Change webhook table names
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* @generated SignedSource<<cc57c5db0d6374e4941bb0d4f1fb73c2>>
|
* @generated SignedSource<<18c0948adc229a75b1d980e64730b423>>
|
||||||
* @lightSyntaxTransform
|
* @lightSyntaxTransform
|
||||||
* @nogrep
|
* @nogrep
|
||||||
*/
|
*/
|
||||||
@@ -20,10 +20,10 @@ export type WebhooksSettingsPageQuery$data = {
|
|||||||
readonly webhookConfigurations: {
|
readonly webhookConfigurations: {
|
||||||
readonly edges: ReadonlyArray<{
|
readonly edges: ReadonlyArray<{
|
||||||
readonly node: {
|
readonly node: {
|
||||||
readonly calls: {
|
readonly endpointUrl: string;
|
||||||
|
readonly events: {
|
||||||
readonly totalCount: number;
|
readonly totalCount: number;
|
||||||
};
|
};
|
||||||
readonly endpointUrl: string;
|
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
readonly selectedEvents: ReadonlyArray<WebhookEventType>;
|
readonly selectedEvents: ReadonlyArray<WebhookEventType>;
|
||||||
};
|
};
|
||||||
@@ -110,9 +110,9 @@ v4 = [
|
|||||||
"value": 0
|
"value": 0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"concreteType": "WebhookCallConnection",
|
"concreteType": "WebhookEventConnection",
|
||||||
"kind": "LinkedField",
|
"kind": "LinkedField",
|
||||||
"name": "calls",
|
"name": "events",
|
||||||
"plural": false,
|
"plural": false,
|
||||||
"selections": [
|
"selections": [
|
||||||
{
|
{
|
||||||
@@ -123,7 +123,7 @@ v4 = [
|
|||||||
"storageKey": null
|
"storageKey": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"storageKey": "calls(first:0)"
|
"storageKey": "events(first:0)"
|
||||||
},
|
},
|
||||||
(v2/*: any*/)
|
(v2/*: any*/)
|
||||||
],
|
],
|
||||||
@@ -265,7 +265,7 @@ return {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"params": {
|
"params": {
|
||||||
"cacheID": "97b7c454586fe958e456fa7929b46686",
|
"cacheID": "b5ca3cf4d05d2cb81c744e760433cb94",
|
||||||
"id": null,
|
"id": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"connection": [
|
"connection": [
|
||||||
@@ -282,11 +282,11 @@ return {
|
|||||||
},
|
},
|
||||||
"name": "WebhooksSettingsPageQuery",
|
"name": "WebhooksSettingsPageQuery",
|
||||||
"operationKind": "query",
|
"operationKind": "query",
|
||||||
"text": "query WebhooksSettingsPageQuery(\n $organizationId: ID!\n) {\n organization: node(id: $organizationId) {\n __typename\n ... on Organization {\n id\n webhookConfigurations(first: 50) {\n edges {\n node {\n id\n endpointUrl\n selectedEvents\n calls(first: 0) {\n totalCount\n }\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n }\n id\n }\n}\n"
|
"text": "query WebhooksSettingsPageQuery(\n $organizationId: ID!\n) {\n organization: node(id: $organizationId) {\n __typename\n ... on Organization {\n id\n webhookConfigurations(first: 50) {\n edges {\n node {\n id\n endpointUrl\n selectedEvents\n events(first: 0) {\n totalCount\n }\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n }\n id\n }\n}\n"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(node as any).hash = "58012f55644dae31fe5e18c2c1e193a7";
|
(node as any).hash = "bac1812903d6f495d15bb0e70ce5ed48";
|
||||||
|
|
||||||
export default node;
|
export default node;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* @generated SignedSource<<c53381e72c0d17cff70568af0bbbb6e5>>
|
* @generated SignedSource<<70389123cd52ffd010e2b8f0109aedcd>>
|
||||||
* @lightSyntaxTransform
|
* @lightSyntaxTransform
|
||||||
* @nogrep
|
* @nogrep
|
||||||
*/
|
*/
|
||||||
@@ -9,22 +9,22 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import { ConcreteRequest } from 'relay-runtime';
|
import { ConcreteRequest } from 'relay-runtime';
|
||||||
export type WebhookCallStatus = "FAILED" | "SUCCEEDED";
|
export type WebhookEventStatus = "FAILED" | "SUCCEEDED";
|
||||||
export type WebhooksSettingsPage_callsQuery$variables = {
|
export type WebhooksSettingsPage_eventsQuery$variables = {
|
||||||
after?: string | null | undefined;
|
after?: string | null | undefined;
|
||||||
first?: number | null | undefined;
|
first?: number | null | undefined;
|
||||||
webhookConfigurationId: string;
|
webhookConfigurationId: string;
|
||||||
};
|
};
|
||||||
export type WebhooksSettingsPage_callsQuery$data = {
|
export type WebhooksSettingsPage_eventsQuery$data = {
|
||||||
readonly node: {
|
readonly node: {
|
||||||
readonly calls?: {
|
readonly events?: {
|
||||||
readonly edges: ReadonlyArray<{
|
readonly edges: ReadonlyArray<{
|
||||||
readonly node: {
|
readonly node: {
|
||||||
readonly createdAt: string;
|
readonly createdAt: string;
|
||||||
readonly endpointUrl: string;
|
readonly endpointUrl: string;
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
readonly response: string | null | undefined;
|
readonly response: string | null | undefined;
|
||||||
readonly status: WebhookCallStatus;
|
readonly status: WebhookEventStatus;
|
||||||
};
|
};
|
||||||
}>;
|
}>;
|
||||||
readonly pageInfo: {
|
readonly pageInfo: {
|
||||||
@@ -35,9 +35,9 @@ export type WebhooksSettingsPage_callsQuery$data = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
export type WebhooksSettingsPage_callsQuery = {
|
export type WebhooksSettingsPage_eventsQuery = {
|
||||||
response: WebhooksSettingsPage_callsQuery$data;
|
response: WebhooksSettingsPage_eventsQuery$data;
|
||||||
variables: WebhooksSettingsPage_callsQuery$variables;
|
variables: WebhooksSettingsPage_eventsQuery$variables;
|
||||||
};
|
};
|
||||||
|
|
||||||
const node: ConcreteRequest = (function(){
|
const node: ConcreteRequest = (function(){
|
||||||
@@ -87,9 +87,9 @@ v5 = {
|
|||||||
"variableName": "first"
|
"variableName": "first"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"concreteType": "WebhookCallConnection",
|
"concreteType": "WebhookEventConnection",
|
||||||
"kind": "LinkedField",
|
"kind": "LinkedField",
|
||||||
"name": "calls",
|
"name": "events",
|
||||||
"plural": false,
|
"plural": false,
|
||||||
"selections": [
|
"selections": [
|
||||||
{
|
{
|
||||||
@@ -127,7 +127,7 @@ v5 = {
|
|||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": null,
|
"args": null,
|
||||||
"concreteType": "WebhookCallEdge",
|
"concreteType": "WebhookEventEdge",
|
||||||
"kind": "LinkedField",
|
"kind": "LinkedField",
|
||||||
"name": "edges",
|
"name": "edges",
|
||||||
"plural": true,
|
"plural": true,
|
||||||
@@ -135,7 +135,7 @@ v5 = {
|
|||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
"args": null,
|
"args": null,
|
||||||
"concreteType": "WebhookCall",
|
"concreteType": "WebhookEvent",
|
||||||
"kind": "LinkedField",
|
"kind": "LinkedField",
|
||||||
"name": "node",
|
"name": "node",
|
||||||
"plural": false,
|
"plural": false,
|
||||||
@@ -191,7 +191,7 @@ return {
|
|||||||
],
|
],
|
||||||
"kind": "Fragment",
|
"kind": "Fragment",
|
||||||
"metadata": null,
|
"metadata": null,
|
||||||
"name": "WebhooksSettingsPage_callsQuery",
|
"name": "WebhooksSettingsPage_eventsQuery",
|
||||||
"selections": [
|
"selections": [
|
||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
@@ -217,7 +217,7 @@ return {
|
|||||||
(v0/*: any*/)
|
(v0/*: any*/)
|
||||||
],
|
],
|
||||||
"kind": "Operation",
|
"kind": "Operation",
|
||||||
"name": "WebhooksSettingsPage_callsQuery",
|
"name": "WebhooksSettingsPage_eventsQuery",
|
||||||
"selections": [
|
"selections": [
|
||||||
{
|
{
|
||||||
"alias": null,
|
"alias": null,
|
||||||
@@ -242,16 +242,16 @@ return {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"params": {
|
"params": {
|
||||||
"cacheID": "9371a8918daebbb2a660b02649ba0241",
|
"cacheID": "507b568e987ce78e58b171810a60bce8",
|
||||||
"id": null,
|
"id": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"name": "WebhooksSettingsPage_callsQuery",
|
"name": "WebhooksSettingsPage_eventsQuery",
|
||||||
"operationKind": "query",
|
"operationKind": "query",
|
||||||
"text": "query WebhooksSettingsPage_callsQuery(\n $webhookConfigurationId: ID!\n $first: Int\n $after: CursorKey\n) {\n node(id: $webhookConfigurationId) {\n __typename\n ... on WebhookConfiguration {\n calls(first: $first, after: $after) {\n totalCount\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n id\n status\n endpointUrl\n createdAt\n response\n }\n }\n }\n }\n id\n }\n}\n"
|
"text": "query WebhooksSettingsPage_eventsQuery(\n $webhookConfigurationId: ID!\n $first: Int\n $after: CursorKey\n) {\n node(id: $webhookConfigurationId) {\n __typename\n ... on WebhookConfiguration {\n events(first: $first, after: $after) {\n totalCount\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n id\n status\n endpointUrl\n createdAt\n response\n }\n }\n }\n }\n id\n }\n}\n"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(node as any).hash = "de18874117b6272fdf2e22871adc4a5d";
|
(node as any).hash = "2e528e16c34c33138858f92215af2ab4";
|
||||||
|
|
||||||
export default node;
|
export default node;
|
||||||
@@ -23,9 +23,9 @@ import { type PreloadedQuery, usePreloadedQuery, useRelayEnvironment } from "rea
|
|||||||
import { ConnectionHandler, fetchQuery, graphql } from "relay-runtime";
|
import { ConnectionHandler, fetchQuery, graphql } from "relay-runtime";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import type { WebhooksSettingsPage_callsQuery } from "#/__generated__/core/WebhooksSettingsPage_callsQuery.graphql";
|
|
||||||
import type { WebhooksSettingsPage_createMutation } from "#/__generated__/core/WebhooksSettingsPage_createMutation.graphql";
|
import type { WebhooksSettingsPage_createMutation } from "#/__generated__/core/WebhooksSettingsPage_createMutation.graphql";
|
||||||
import type { WebhooksSettingsPage_deleteMutation } from "#/__generated__/core/WebhooksSettingsPage_deleteMutation.graphql";
|
import type { WebhooksSettingsPage_deleteMutation } from "#/__generated__/core/WebhooksSettingsPage_deleteMutation.graphql";
|
||||||
|
import type { WebhooksSettingsPage_eventsQuery } from "#/__generated__/core/WebhooksSettingsPage_eventsQuery.graphql";
|
||||||
import type { WebhooksSettingsPage_signingSecretQuery } from "#/__generated__/core/WebhooksSettingsPage_signingSecretQuery.graphql";
|
import type { WebhooksSettingsPage_signingSecretQuery } from "#/__generated__/core/WebhooksSettingsPage_signingSecretQuery.graphql";
|
||||||
import type { WebhooksSettingsPage_updateMutation } from "#/__generated__/core/WebhooksSettingsPage_updateMutation.graphql";
|
import type { WebhooksSettingsPage_updateMutation } from "#/__generated__/core/WebhooksSettingsPage_updateMutation.graphql";
|
||||||
import type { WebhooksSettingsPageQuery } from "#/__generated__/core/WebhooksSettingsPageQuery.graphql";
|
import type { WebhooksSettingsPageQuery } from "#/__generated__/core/WebhooksSettingsPageQuery.graphql";
|
||||||
@@ -45,7 +45,7 @@ export const webhooksSettingsPageQuery = graphql`
|
|||||||
id
|
id
|
||||||
endpointUrl
|
endpointUrl
|
||||||
selectedEvents
|
selectedEvents
|
||||||
calls(first: 0) {
|
events(first: 0) {
|
||||||
totalCount
|
totalCount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,15 +98,15 @@ const signingSecretQuery = graphql`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const webhookCallsQuery = graphql`
|
const webhookEventsQuery = graphql`
|
||||||
query WebhooksSettingsPage_callsQuery(
|
query WebhooksSettingsPage_eventsQuery(
|
||||||
$webhookConfigurationId: ID!
|
$webhookConfigurationId: ID!
|
||||||
$first: Int
|
$first: Int
|
||||||
$after: CursorKey
|
$after: CursorKey
|
||||||
) {
|
) {
|
||||||
node(id: $webhookConfigurationId) {
|
node(id: $webhookConfigurationId) {
|
||||||
... on WebhookConfiguration {
|
... on WebhookConfiguration {
|
||||||
calls(first: $first, after: $after) {
|
events(first: $first, after: $after) {
|
||||||
totalCount
|
totalCount
|
||||||
pageInfo {
|
pageInfo {
|
||||||
hasNextPage
|
hasNextPage
|
||||||
@@ -285,7 +285,7 @@ function WebhookFormDialog({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CallStatusBadge({ status }: { status: string }) {
|
function EventStatusBadge({ status }: { status: string }) {
|
||||||
const { __ } = useTranslate();
|
const { __ } = useTranslate();
|
||||||
if (status === "SUCCEEDED") {
|
if (status === "SUCCEEDED") {
|
||||||
return <Badge variant="success" size="sm">{__("Succeeded")}</Badge>;
|
return <Badge variant="success" size="sm">{__("Succeeded")}</Badge>;
|
||||||
@@ -297,7 +297,7 @@ function formatDate(iso: string) {
|
|||||||
return new Date(iso).toLocaleString();
|
return new Date(iso).toLocaleString();
|
||||||
}
|
}
|
||||||
|
|
||||||
function WebhookCallsDialog({
|
function WebhookEventsDialog({
|
||||||
webhookConfigurationId,
|
webhookConfigurationId,
|
||||||
endpointUrl,
|
endpointUrl,
|
||||||
onClose,
|
onClose,
|
||||||
@@ -307,10 +307,11 @@ function WebhookCallsDialog({
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}) {
|
}) {
|
||||||
const { __ } = useTranslate();
|
const { __ } = useTranslate();
|
||||||
|
const { toast } = useToast();
|
||||||
const environment = useRelayEnvironment();
|
const environment = useRelayEnvironment();
|
||||||
const dialogRef = useDialogRef();
|
const dialogRef = useDialogRef();
|
||||||
type CallNode = NonNullable<WebhooksSettingsPage_callsQuery["response"]["node"]["calls"]>["edges"][number]["node"];
|
type EventNode = NonNullable<WebhooksSettingsPage_eventsQuery["response"]["node"]["events"]>["edges"][number]["node"];
|
||||||
const [calls, setCalls] = useState<CallNode[]>([]);
|
const [events, setEvents] = useState<EventNode[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [hasNextPage, setHasNextPage] = useState(false);
|
const [hasNextPage, setHasNextPage] = useState(false);
|
||||||
const [endCursor, setEndCursor] = useState<string | null>(null);
|
const [endCursor, setEndCursor] = useState<string | null>(null);
|
||||||
@@ -318,13 +319,13 @@ function WebhookCallsDialog({
|
|||||||
|
|
||||||
const PAGE_SIZE = 20;
|
const PAGE_SIZE = 20;
|
||||||
|
|
||||||
const loadCalls = useCallback(
|
const loadEvents = useCallback(
|
||||||
async (after?: string | null) => {
|
async (after?: string | null) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const data = await fetchQuery<WebhooksSettingsPage_callsQuery>(
|
const data = await fetchQuery<WebhooksSettingsPage_eventsQuery>(
|
||||||
environment,
|
environment,
|
||||||
webhookCallsQuery,
|
webhookEventsQuery,
|
||||||
{
|
{
|
||||||
webhookConfigurationId,
|
webhookConfigurationId,
|
||||||
first: PAGE_SIZE,
|
first: PAGE_SIZE,
|
||||||
@@ -332,30 +333,36 @@ function WebhookCallsDialog({
|
|||||||
},
|
},
|
||||||
).toPromise();
|
).toPromise();
|
||||||
|
|
||||||
const connection = data?.node?.calls;
|
const connection = data?.node?.events;
|
||||||
if (connection) {
|
if (connection) {
|
||||||
const newCalls = connection.edges.map(e => e.node);
|
const newEvents = connection.edges.map(e => e.node);
|
||||||
setCalls(prev => after ? [...prev, ...newCalls] : newCalls);
|
setEvents(prev => after ? [...prev, ...newEvents] : newEvents);
|
||||||
setHasNextPage(connection.pageInfo.hasNextPage);
|
setHasNextPage(connection.pageInfo.hasNextPage);
|
||||||
setEndCursor(connection.pageInfo.endCursor ?? null);
|
setEndCursor(connection.pageInfo.endCursor ?? null);
|
||||||
setTotalCount(connection.totalCount);
|
setTotalCount(connection.totalCount);
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
toast({
|
||||||
|
title: __("Error"),
|
||||||
|
description: __("Failed to load webhook events."),
|
||||||
|
variant: "error",
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[environment, webhookConfigurationId],
|
[environment, webhookConfigurationId, toast, __],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void loadCalls();
|
void loadEvents();
|
||||||
dialogRef.current?.open();
|
dialogRef.current?.open();
|
||||||
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
}, [loadEvents]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
ref={dialogRef}
|
ref={dialogRef}
|
||||||
title={__("Webhook Calls")}
|
title={__("Webhook Events")}
|
||||||
className="max-w-2xl"
|
className="max-w-2xl"
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
>
|
>
|
||||||
@@ -368,29 +375,29 @@ function WebhookCallsDialog({
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
{calls.length === 0 && !loading
|
{events.length === 0 && !loading
|
||||||
? (
|
? (
|
||||||
<p className="text-sm text-txt-tertiary text-center py-8">
|
<p className="text-sm text-txt-tertiary text-center py-8">
|
||||||
{__("No webhook calls recorded yet.")}
|
{__("No webhook events recorded yet.")}
|
||||||
</p>
|
</p>
|
||||||
)
|
)
|
||||||
: (
|
: (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{calls.map(call => (
|
{events.map(event => (
|
||||||
<div
|
<div
|
||||||
key={call.id}
|
key={event.id}
|
||||||
className="border border-border-solid rounded-md p-3 space-y-1"
|
className="border border-border-solid rounded-md p-3 space-y-1"
|
||||||
>
|
>
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<CallStatusBadge status={call.status} />
|
<EventStatusBadge status={event.status} />
|
||||||
<span className="text-xs text-txt-tertiary">
|
<span className="text-xs text-txt-tertiary">
|
||||||
{formatDate(call.createdAt)}
|
{formatDate(event.createdAt)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs font-mono text-txt-secondary truncate">
|
<p className="text-xs font-mono text-txt-secondary truncate">
|
||||||
{call.endpointUrl}
|
{event.endpointUrl}
|
||||||
</p>
|
</p>
|
||||||
{call.response && (
|
{event.response && (
|
||||||
<details className="text-xs">
|
<details className="text-xs">
|
||||||
<summary className="cursor-pointer text-txt-link hover:underline">
|
<summary className="cursor-pointer text-txt-link hover:underline">
|
||||||
{__("Response")}
|
{__("Response")}
|
||||||
@@ -398,9 +405,9 @@ function WebhookCallsDialog({
|
|||||||
<pre className="mt-1 bg-subtle p-2 rounded text-xs overflow-auto max-h-48 whitespace-pre-wrap break-all">
|
<pre className="mt-1 bg-subtle p-2 rounded text-xs overflow-auto max-h-48 whitespace-pre-wrap break-all">
|
||||||
{(() => {
|
{(() => {
|
||||||
try {
|
try {
|
||||||
return JSON.stringify(JSON.parse(call.response), null, 2);
|
return JSON.stringify(JSON.parse(event.response), null, 2);
|
||||||
} catch {
|
} catch {
|
||||||
return call.response;
|
return event.response;
|
||||||
}
|
}
|
||||||
})()}
|
})()}
|
||||||
</pre>
|
</pre>
|
||||||
@@ -420,7 +427,7 @@ function WebhookCallsDialog({
|
|||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
onClick={() => void loadCalls(endCursor)}
|
onClick={() => void loadEvents(endCursor)}
|
||||||
>
|
>
|
||||||
{__("Load more")}
|
{__("Load more")}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -441,7 +448,7 @@ export function WebhooksSettingsPage(props: {
|
|||||||
const [deletingId, setDeletingId] = useState<string | null>(null);
|
const [deletingId, setDeletingId] = useState<string | null>(null);
|
||||||
const [revealedSecrets, setRevealedSecrets] = useState<Record<string, string>>({});
|
const [revealedSecrets, setRevealedSecrets] = useState<Record<string, string>>({});
|
||||||
const [loadingSecrets, setLoadingSecrets] = useState<Set<string>>(new Set());
|
const [loadingSecrets, setLoadingSecrets] = useState<Set<string>>(new Set());
|
||||||
const [viewingCallsId, setViewingCallsId] = useState<string | null>(null);
|
const [viewingEventsId, setViewingEventsId] = useState<string | null>(null);
|
||||||
|
|
||||||
const fetchSigningSecret = useCallback(
|
const fetchSigningSecret = useCallback(
|
||||||
async (webhookConfigurationId: string): Promise<string | null> => {
|
async (webhookConfigurationId: string): Promise<string | null> => {
|
||||||
@@ -543,6 +550,9 @@ export function WebhooksSettingsPage(props: {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const webhooks = organization.webhookConfigurations?.edges ?? [];
|
const webhooks = organization.webhookConfigurations?.edges ?? [];
|
||||||
|
const viewingEventsWebhook = viewingEventsId
|
||||||
|
? webhooks.find(e => e.node.id === viewingEventsId)?.node ?? null
|
||||||
|
: null;
|
||||||
|
|
||||||
const connectionId = ConnectionHandler.getConnectionID(
|
const connectionId = ConnectionHandler.getConnectionID(
|
||||||
organization.id,
|
organization.id,
|
||||||
@@ -683,9 +693,9 @@ export function WebhooksSettingsPage(props: {
|
|||||||
<div className="flex items-center gap-1 shrink-0">
|
<div className="flex items-center gap-1 shrink-0">
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
onClick={() => setViewingCallsId(webhook.id)}
|
onClick={() => setViewingEventsId(webhook.id)}
|
||||||
>
|
>
|
||||||
{`${__("Calls")} (${webhook.calls.totalCount})`}
|
{`${__("Events")} (${webhook.events.totalCount})`}
|
||||||
</Button>
|
</Button>
|
||||||
<WebhookFormDialog
|
<WebhookFormDialog
|
||||||
mode="edit"
|
mode="edit"
|
||||||
@@ -740,26 +750,22 @@ export function WebhooksSettingsPage(props: {
|
|||||||
variant="danger"
|
variant="danger"
|
||||||
onClick={() => deletingId && handleDelete(deletingId)}
|
onClick={() => deletingId && handleDelete(deletingId)}
|
||||||
disabled={isDeleting}
|
disabled={isDeleting}
|
||||||
icon={isDeleting ? Spinner : IconTrashCan}
|
icon={isDeleting ? undefined : IconTrashCan}
|
||||||
>
|
>
|
||||||
{isDeleting
|
{isDeleting
|
||||||
? __("Deleting...")
|
? <><Spinner size={16} /> {__("Deleting...")}</>
|
||||||
: __("Delete")}
|
: __("Delete")}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
{viewingCallsId && (() => {
|
{viewingEventsWebhook && viewingEventsId && (
|
||||||
const webhook = webhooks.find(e => e.node.id === viewingCallsId);
|
<WebhookEventsDialog
|
||||||
if (!webhook) return null;
|
webhookConfigurationId={viewingEventsId}
|
||||||
return (
|
endpointUrl={viewingEventsWebhook.endpointUrl}
|
||||||
<WebhookCallsDialog
|
onClose={() => setViewingEventsId(null)}
|
||||||
webhookConfigurationId={viewingCallsId}
|
/>
|
||||||
endpointUrl={webhook.node.endpointUrl}
|
)}
|
||||||
onClose={() => setViewingCallsId(null)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})()}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ const (
|
|||||||
TokenEntityType uint16 = 54
|
TokenEntityType uint16 = 54
|
||||||
SCIMBridgeEntityType uint16 = 55
|
SCIMBridgeEntityType uint16 = 55
|
||||||
WebhookConfigurationEntityType uint16 = 56
|
WebhookConfigurationEntityType uint16 = 56
|
||||||
WebhookEventEntityType uint16 = 57
|
WebhookDataEntityType uint16 = 57
|
||||||
WebhookCallEntityType uint16 = 58
|
WebhookEventEntityType uint16 = 58
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewEntityFromID(id gid.GID) (any, bool) {
|
func NewEntityFromID(id gid.GID) (any, bool) {
|
||||||
@@ -196,10 +196,10 @@ func NewEntityFromID(id gid.GID) (any, bool) {
|
|||||||
return &SCIMBridge{ID: id}, true
|
return &SCIMBridge{ID: id}, true
|
||||||
case WebhookConfigurationEntityType:
|
case WebhookConfigurationEntityType:
|
||||||
return &WebhookConfiguration{ID: id}, true
|
return &WebhookConfiguration{ID: id}, true
|
||||||
|
case WebhookDataEntityType:
|
||||||
|
return &WebhookData{ID: id}, true
|
||||||
case WebhookEventEntityType:
|
case WebhookEventEntityType:
|
||||||
return &WebhookEvent{ID: id}, true
|
return &WebhookEvent{ID: id}, true
|
||||||
case WebhookCallEntityType:
|
|
||||||
return &WebhookCall{ID: id}, true
|
|
||||||
default:
|
default:
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,35 +18,35 @@ CREATE TABLE webhook_configurations (
|
|||||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TYPE webhook_event_status AS ENUM (
|
CREATE TYPE webhook_data_status AS ENUM (
|
||||||
'PENDING',
|
'PENDING',
|
||||||
'PROCESSING',
|
'PROCESSING',
|
||||||
'DELIVERED'
|
'DELIVERED'
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE webhook_events (
|
CREATE TABLE webhook_data (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
tenant_id TEXT NOT NULL,
|
tenant_id TEXT NOT NULL,
|
||||||
organization_id TEXT NOT NULL REFERENCES organizations(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
organization_id TEXT NOT NULL REFERENCES organizations(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
event_type webhook_event_type NOT NULL,
|
event_type webhook_event_type NOT NULL,
|
||||||
status webhook_event_status NOT NULL,
|
status webhook_data_status NOT NULL,
|
||||||
data JSONB NOT NULL,
|
data JSONB NOT NULL,
|
||||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||||
processed_at TIMESTAMP WITH TIME ZONE
|
processed_at TIMESTAMP WITH TIME ZONE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TYPE webhook_call_status AS ENUM (
|
CREATE TYPE webhook_event_status AS ENUM (
|
||||||
'SUCCEEDED',
|
'SUCCEEDED',
|
||||||
'FAILED'
|
'FAILED'
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE webhook_calls (
|
CREATE TABLE webhook_events (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
tenant_id TEXT NOT NULL,
|
tenant_id TEXT NOT NULL,
|
||||||
webhook_event_id TEXT NOT NULL REFERENCES webhook_events(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
webhook_data_id TEXT NOT NULL REFERENCES webhook_data(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
webhook_configuration_id TEXT NOT NULL REFERENCES webhook_configurations(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
webhook_configuration_id TEXT NOT NULL REFERENCES webhook_configurations(id) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
endpoint_url TEXT NOT NULL,
|
endpoint_url TEXT NOT NULL,
|
||||||
status webhook_call_status NOT NULL,
|
status webhook_event_status NOT NULL,
|
||||||
response JSONB,
|
response JSONB,
|
||||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,166 +0,0 @@
|
|||||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
|
||||||
//
|
|
||||||
// Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
// purpose with or without fee is hereby granted, provided that the above
|
|
||||||
// copyright notice and this permission notice appear in all copies.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
||||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
||||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
||||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
||||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
||||||
// PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
|
|
||||||
package coredata
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"maps"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5"
|
|
||||||
"go.gearno.de/kit/pg"
|
|
||||||
"go.probo.inc/probo/pkg/gid"
|
|
||||||
"go.probo.inc/probo/pkg/page"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
WebhookCall struct {
|
|
||||||
ID gid.GID `db:"id"`
|
|
||||||
WebhookEventID gid.GID `db:"webhook_event_id"`
|
|
||||||
WebhookConfigurationID gid.GID `db:"webhook_configuration_id"`
|
|
||||||
EndpointURL string `db:"endpoint_url"`
|
|
||||||
Status WebhookCallStatus `db:"status"`
|
|
||||||
Response json.RawMessage `db:"response"`
|
|
||||||
CreatedAt time.Time `db:"created_at"`
|
|
||||||
}
|
|
||||||
|
|
||||||
WebhookCalls []*WebhookCall
|
|
||||||
)
|
|
||||||
|
|
||||||
func (w WebhookCall) CursorKey(orderBy WebhookCallOrderField) page.CursorKey {
|
|
||||||
switch orderBy {
|
|
||||||
case WebhookCallOrderFieldCreatedAt:
|
|
||||||
return page.NewCursorKey(w.ID, w.CreatedAt)
|
|
||||||
}
|
|
||||||
|
|
||||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WebhookCalls) LoadByConfigurationID(
|
|
||||||
ctx context.Context,
|
|
||||||
conn pg.Conn,
|
|
||||||
scope Scoper,
|
|
||||||
webhookConfigurationID gid.GID,
|
|
||||||
cursor *page.Cursor[WebhookCallOrderField],
|
|
||||||
) error {
|
|
||||||
q := `
|
|
||||||
SELECT
|
|
||||||
id,
|
|
||||||
webhook_event_id,
|
|
||||||
webhook_configuration_id,
|
|
||||||
endpoint_url,
|
|
||||||
status,
|
|
||||||
response,
|
|
||||||
created_at
|
|
||||||
FROM
|
|
||||||
webhook_calls
|
|
||||||
WHERE
|
|
||||||
%s
|
|
||||||
AND webhook_configuration_id = @webhook_configuration_id
|
|
||||||
AND %s
|
|
||||||
`
|
|
||||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
|
||||||
|
|
||||||
args := pgx.NamedArgs{"webhook_configuration_id": webhookConfigurationID}
|
|
||||||
maps.Copy(args, scope.SQLArguments())
|
|
||||||
maps.Copy(args, cursor.SQLArguments())
|
|
||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot query webhook calls: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
calls, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[WebhookCall])
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot collect webhook calls: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
*w = calls
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WebhookCalls) CountByConfigurationID(
|
|
||||||
ctx context.Context,
|
|
||||||
conn pg.Conn,
|
|
||||||
scope Scoper,
|
|
||||||
webhookConfigurationID gid.GID,
|
|
||||||
) (int, error) {
|
|
||||||
q := `
|
|
||||||
SELECT COUNT(*)
|
|
||||||
FROM webhook_calls
|
|
||||||
WHERE %s
|
|
||||||
AND webhook_configuration_id = @webhook_configuration_id
|
|
||||||
`
|
|
||||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{"webhook_configuration_id": webhookConfigurationID}
|
|
||||||
maps.Copy(args, scope.SQLArguments())
|
|
||||||
|
|
||||||
var count int
|
|
||||||
if err := conn.QueryRow(ctx, q, args).Scan(&count); err != nil {
|
|
||||||
return 0, fmt.Errorf("cannot count webhook calls: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return count, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WebhookCall) Insert(
|
|
||||||
ctx context.Context,
|
|
||||||
conn pg.Conn,
|
|
||||||
scope Scoper,
|
|
||||||
) error {
|
|
||||||
q := `
|
|
||||||
INSERT INTO webhook_calls (
|
|
||||||
id,
|
|
||||||
tenant_id,
|
|
||||||
webhook_event_id,
|
|
||||||
webhook_configuration_id,
|
|
||||||
endpoint_url,
|
|
||||||
status,
|
|
||||||
response,
|
|
||||||
created_at
|
|
||||||
)
|
|
||||||
VALUES (
|
|
||||||
@id,
|
|
||||||
@tenant_id,
|
|
||||||
@webhook_event_id,
|
|
||||||
@webhook_configuration_id,
|
|
||||||
@endpoint_url,
|
|
||||||
@status,
|
|
||||||
@response,
|
|
||||||
@created_at
|
|
||||||
)
|
|
||||||
`
|
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{
|
|
||||||
"id": w.ID,
|
|
||||||
"tenant_id": scope.GetTenantID(),
|
|
||||||
"webhook_event_id": w.WebhookEventID,
|
|
||||||
"webhook_configuration_id": w.WebhookConfigurationID,
|
|
||||||
"endpoint_url": w.EndpointURL,
|
|
||||||
"status": w.Status,
|
|
||||||
"response": w.Response,
|
|
||||||
"created_at": w.CreatedAt,
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := conn.Exec(ctx, q, args)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot insert webhook call: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
159
pkg/coredata/webhook_data.go
Normal file
159
pkg/coredata/webhook_data.go
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
|
// copyright notice and this permission notice appear in all copies.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||||
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||||
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||||
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||||
|
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
// PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
package coredata
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"maps"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
|
"go.gearno.de/kit/pg"
|
||||||
|
"go.probo.inc/probo/pkg/gid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
WebhookData struct {
|
||||||
|
ID gid.GID `db:"id"`
|
||||||
|
OrganizationID gid.GID `db:"organization_id"`
|
||||||
|
EventType WebhookEventType `db:"event_type"`
|
||||||
|
Status WebhookDataStatus `db:"status"`
|
||||||
|
Data json.RawMessage `db:"data"`
|
||||||
|
CreatedAt time.Time `db:"created_at"`
|
||||||
|
ProcessedAt *time.Time `db:"processed_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
WebhookDataList []*WebhookData
|
||||||
|
)
|
||||||
|
|
||||||
|
func (w *WebhookData) Insert(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
INSERT INTO webhook_data (
|
||||||
|
id,
|
||||||
|
tenant_id,
|
||||||
|
organization_id,
|
||||||
|
event_type,
|
||||||
|
status,
|
||||||
|
data,
|
||||||
|
created_at
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
@id,
|
||||||
|
@tenant_id,
|
||||||
|
@organization_id,
|
||||||
|
@event_type,
|
||||||
|
@status,
|
||||||
|
@data,
|
||||||
|
@created_at
|
||||||
|
)
|
||||||
|
`
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{
|
||||||
|
"id": w.ID,
|
||||||
|
"tenant_id": scope.GetTenantID(),
|
||||||
|
"organization_id": w.OrganizationID,
|
||||||
|
"event_type": w.EventType,
|
||||||
|
"status": w.Status,
|
||||||
|
"data": w.Data,
|
||||||
|
"created_at": w.CreatedAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := conn.Exec(ctx, q, args)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot insert webhook data: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WebhookData) LoadNextPendingForUpdate(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
organization_id,
|
||||||
|
event_type,
|
||||||
|
status,
|
||||||
|
data,
|
||||||
|
created_at,
|
||||||
|
processed_at
|
||||||
|
FROM webhook_data
|
||||||
|
WHERE status = 'PENDING'
|
||||||
|
ORDER BY created_at ASC
|
||||||
|
LIMIT 1
|
||||||
|
FOR UPDATE SKIP LOCKED
|
||||||
|
`
|
||||||
|
|
||||||
|
rows, err := conn.Query(ctx, q)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot query pending webhook data: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[WebhookData])
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
|
return ErrResourceNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("cannot collect webhook data: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
*w = data
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WebhookData) UpdateStatus(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
UPDATE webhook_data
|
||||||
|
SET
|
||||||
|
status = @status,
|
||||||
|
processed_at = @processed_at
|
||||||
|
WHERE %s
|
||||||
|
AND id = @id
|
||||||
|
`
|
||||||
|
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{
|
||||||
|
"id": w.ID,
|
||||||
|
"status": w.Status.String(),
|
||||||
|
"processed_at": w.ProcessedAt,
|
||||||
|
}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
|
result, err := conn.Exec(ctx, q, args)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot update webhook data: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.RowsAffected() == 0 {
|
||||||
|
return ErrResourceNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -19,46 +19,47 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WebhookCallStatus string
|
type WebhookDataStatus string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
WebhookCallStatusSucceeded WebhookCallStatus = "SUCCEEDED"
|
WebhookDataStatusPending WebhookDataStatus = "PENDING"
|
||||||
WebhookCallStatusFailed WebhookCallStatus = "FAILED"
|
WebhookDataStatusProcessing WebhookDataStatus = "PROCESSING"
|
||||||
|
WebhookDataStatusDelivered WebhookDataStatus = "DELIVERED"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s WebhookCallStatus) String() string {
|
func (s WebhookDataStatus) String() string {
|
||||||
return string(s)
|
return string(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s WebhookCallStatus) IsValid() bool {
|
func (s WebhookDataStatus) IsValid() bool {
|
||||||
switch s {
|
switch s {
|
||||||
case WebhookCallStatusSucceeded, WebhookCallStatusFailed:
|
case WebhookDataStatusPending, WebhookDataStatusProcessing, WebhookDataStatusDelivered:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s WebhookCallStatus) MarshalText() ([]byte, error) {
|
func (s WebhookDataStatus) MarshalText() ([]byte, error) {
|
||||||
return []byte(s.String()), nil
|
return []byte(s.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WebhookCallStatus) UnmarshalText(text []byte) error {
|
func (s *WebhookDataStatus) UnmarshalText(text []byte) error {
|
||||||
*s = WebhookCallStatus(text)
|
*s = WebhookDataStatus(text)
|
||||||
if !s.IsValid() {
|
if !s.IsValid() {
|
||||||
return fmt.Errorf("%s is not a valid WebhookCallStatus", string(text))
|
return fmt.Errorf("%s is not a valid WebhookDataStatus", string(text))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WebhookCallStatus) Scan(value any) error {
|
func (s *WebhookDataStatus) Scan(value any) error {
|
||||||
str, ok := value.(string)
|
str, ok := value.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("unsupported type for WebhookCallStatus: %T", value)
|
return fmt.Errorf("unsupported type for WebhookDataStatus: %T", value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.UnmarshalText([]byte(str))
|
return s.UnmarshalText([]byte(str))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s WebhookCallStatus) Value() (driver.Value, error) {
|
func (s WebhookDataStatus) Value() (driver.Value, error) {
|
||||||
return s.String(), nil
|
return s.String(), nil
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,6 @@ package coredata
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"maps"
|
"maps"
|
||||||
"time"
|
"time"
|
||||||
@@ -25,23 +24,100 @@ import (
|
|||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"go.gearno.de/kit/pg"
|
"go.gearno.de/kit/pg"
|
||||||
"go.probo.inc/probo/pkg/gid"
|
"go.probo.inc/probo/pkg/gid"
|
||||||
|
"go.probo.inc/probo/pkg/page"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
WebhookEvent struct {
|
WebhookEvent struct {
|
||||||
ID gid.GID `db:"id"`
|
ID gid.GID `db:"id"`
|
||||||
OrganizationID gid.GID `db:"organization_id"`
|
WebhookDataID gid.GID `db:"webhook_data_id"`
|
||||||
EventType WebhookEventType `db:"event_type"`
|
WebhookConfigurationID gid.GID `db:"webhook_configuration_id"`
|
||||||
Status WebhookEventStatus `db:"status"`
|
EndpointURL string `db:"endpoint_url"`
|
||||||
Data json.RawMessage `db:"data"`
|
Status WebhookEventStatus `db:"status"`
|
||||||
CreatedAt time.Time `db:"created_at"`
|
Response json.RawMessage `db:"response"`
|
||||||
ProcessedAt *time.Time `db:"processed_at"`
|
CreatedAt time.Time `db:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
WebhookEvents []*WebhookEvent
|
WebhookEvents []*WebhookEvent
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (w WebhookEvent) CursorKey(orderBy WebhookEventOrderField) page.CursorKey {
|
||||||
|
switch orderBy {
|
||||||
|
case WebhookEventOrderFieldCreatedAt:
|
||||||
|
return page.NewCursorKey(w.ID, w.CreatedAt)
|
||||||
|
}
|
||||||
|
|
||||||
|
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WebhookEvents) LoadByConfigurationID(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
webhookConfigurationID gid.GID,
|
||||||
|
cursor *page.Cursor[WebhookEventOrderField],
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
webhook_data_id,
|
||||||
|
webhook_configuration_id,
|
||||||
|
endpoint_url,
|
||||||
|
status,
|
||||||
|
response,
|
||||||
|
created_at
|
||||||
|
FROM
|
||||||
|
webhook_events
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
AND webhook_configuration_id = @webhook_configuration_id
|
||||||
|
AND %s
|
||||||
|
`
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.NamedArgs{"webhook_configuration_id": webhookConfigurationID}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
maps.Copy(args, cursor.SQLArguments())
|
||||||
|
|
||||||
|
rows, err := conn.Query(ctx, q, args)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot query webhook events: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
events, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[WebhookEvent])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot collect webhook events: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
*w = events
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WebhookEvents) CountByConfigurationID(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
webhookConfigurationID gid.GID,
|
||||||
|
) (int, error) {
|
||||||
|
q := `
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM webhook_events
|
||||||
|
WHERE %s
|
||||||
|
AND webhook_configuration_id = @webhook_configuration_id
|
||||||
|
`
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{"webhook_configuration_id": webhookConfigurationID}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
|
var count int
|
||||||
|
if err := conn.QueryRow(ctx, q, args).Scan(&count); err != nil {
|
||||||
|
return 0, fmt.Errorf("cannot count webhook events: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (w *WebhookEvent) Insert(
|
func (w *WebhookEvent) Insert(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
conn pg.Conn,
|
conn pg.Conn,
|
||||||
@@ -51,31 +127,34 @@ func (w *WebhookEvent) Insert(
|
|||||||
INSERT INTO webhook_events (
|
INSERT INTO webhook_events (
|
||||||
id,
|
id,
|
||||||
tenant_id,
|
tenant_id,
|
||||||
organization_id,
|
webhook_data_id,
|
||||||
event_type,
|
webhook_configuration_id,
|
||||||
|
endpoint_url,
|
||||||
status,
|
status,
|
||||||
data,
|
response,
|
||||||
created_at
|
created_at
|
||||||
)
|
)
|
||||||
VALUES (
|
VALUES (
|
||||||
@id,
|
@id,
|
||||||
@tenant_id,
|
@tenant_id,
|
||||||
@organization_id,
|
@webhook_data_id,
|
||||||
@event_type,
|
@webhook_configuration_id,
|
||||||
|
@endpoint_url,
|
||||||
@status,
|
@status,
|
||||||
@data,
|
@response,
|
||||||
@created_at
|
@created_at
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{
|
args := pgx.StrictNamedArgs{
|
||||||
"id": w.ID,
|
"id": w.ID,
|
||||||
"tenant_id": scope.GetTenantID(),
|
"tenant_id": scope.GetTenantID(),
|
||||||
"organization_id": w.OrganizationID,
|
"webhook_data_id": w.WebhookDataID,
|
||||||
"event_type": w.EventType,
|
"webhook_configuration_id": w.WebhookConfigurationID,
|
||||||
"status": w.Status,
|
"endpoint_url": w.EndpointURL,
|
||||||
"data": w.Data,
|
"status": w.Status,
|
||||||
"created_at": w.CreatedAt,
|
"response": w.Response,
|
||||||
|
"created_at": w.CreatedAt,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := conn.Exec(ctx, q, args)
|
_, err := conn.Exec(ctx, q, args)
|
||||||
@@ -85,76 +164,3 @@ VALUES (
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WebhookEvent) LoadNextPendingForUpdate(
|
|
||||||
ctx context.Context,
|
|
||||||
conn pg.Conn,
|
|
||||||
) error {
|
|
||||||
q := `
|
|
||||||
SELECT
|
|
||||||
id,
|
|
||||||
organization_id,
|
|
||||||
event_type,
|
|
||||||
status,
|
|
||||||
data,
|
|
||||||
created_at,
|
|
||||||
processed_at
|
|
||||||
FROM webhook_events
|
|
||||||
WHERE status = 'PENDING'
|
|
||||||
ORDER BY created_at ASC
|
|
||||||
LIMIT 1
|
|
||||||
FOR UPDATE SKIP LOCKED
|
|
||||||
`
|
|
||||||
|
|
||||||
rows, err := conn.Query(ctx, q)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot query pending webhook events: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
event, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[WebhookEvent])
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, pgx.ErrNoRows) {
|
|
||||||
return ErrResourceNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("cannot collect webhook event: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
*w = event
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WebhookEvent) UpdateStatus(
|
|
||||||
ctx context.Context,
|
|
||||||
conn pg.Conn,
|
|
||||||
scope Scoper,
|
|
||||||
) error {
|
|
||||||
q := `
|
|
||||||
UPDATE webhook_events
|
|
||||||
SET
|
|
||||||
status = @status,
|
|
||||||
processed_at = @processed_at
|
|
||||||
WHERE %s
|
|
||||||
AND id = @id
|
|
||||||
`
|
|
||||||
|
|
||||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{
|
|
||||||
"id": w.ID,
|
|
||||||
"status": w.Status.String(),
|
|
||||||
"processed_at": w.ProcessedAt,
|
|
||||||
}
|
|
||||||
maps.Copy(args, scope.SQLArguments())
|
|
||||||
|
|
||||||
result, err := conn.Exec(ctx, q, args)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot update webhook event: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if result.RowsAffected() == 0 {
|
|
||||||
return ErrResourceNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -19,37 +19,37 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
WebhookCallOrderField string
|
WebhookEventOrderField string
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
WebhookCallOrderFieldCreatedAt WebhookCallOrderField = "CREATED_AT"
|
WebhookEventOrderFieldCreatedAt WebhookEventOrderField = "CREATED_AT"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p WebhookCallOrderField) Column() string {
|
func (p WebhookEventOrderField) Column() string {
|
||||||
return string(p)
|
return string(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p WebhookCallOrderField) String() string {
|
func (p WebhookEventOrderField) String() string {
|
||||||
return string(p)
|
return string(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p WebhookCallOrderField) IsValid() bool {
|
func (p WebhookEventOrderField) IsValid() bool {
|
||||||
switch p {
|
switch p {
|
||||||
case WebhookCallOrderFieldCreatedAt:
|
case WebhookEventOrderFieldCreatedAt:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p WebhookCallOrderField) MarshalText() ([]byte, error) {
|
func (p WebhookEventOrderField) MarshalText() ([]byte, error) {
|
||||||
return []byte(p.String()), nil
|
return []byte(p.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WebhookCallOrderField) UnmarshalText(text []byte) error {
|
func (p *WebhookEventOrderField) UnmarshalText(text []byte) error {
|
||||||
*p = WebhookCallOrderField(text)
|
*p = WebhookEventOrderField(text)
|
||||||
if !p.IsValid() {
|
if !p.IsValid() {
|
||||||
return fmt.Errorf("%s is not a valid WebhookCallOrderField", string(text))
|
return fmt.Errorf("%s is not a valid WebhookEventOrderField", string(text))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -22,9 +22,8 @@ import (
|
|||||||
type WebhookEventStatus string
|
type WebhookEventStatus string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
WebhookEventStatusPending WebhookEventStatus = "PENDING"
|
WebhookEventStatusSucceeded WebhookEventStatus = "SUCCEEDED"
|
||||||
WebhookEventStatusProcessing WebhookEventStatus = "PROCESSING"
|
WebhookEventStatusFailed WebhookEventStatus = "FAILED"
|
||||||
WebhookEventStatusDelivered WebhookEventStatus = "DELIVERED"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s WebhookEventStatus) String() string {
|
func (s WebhookEventStatus) String() string {
|
||||||
@@ -33,7 +32,7 @@ func (s WebhookEventStatus) String() string {
|
|||||||
|
|
||||||
func (s WebhookEventStatus) IsValid() bool {
|
func (s WebhookEventStatus) IsValid() bool {
|
||||||
switch s {
|
switch s {
|
||||||
case WebhookEventStatusPending, WebhookEventStatusProcessing, WebhookEventStatusDelivered:
|
case WebhookEventStatusSucceeded, WebhookEventStatusFailed:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -261,18 +261,18 @@ func (s WebhookConfigurationService) GetSigningSecret(
|
|||||||
return wc.DecryptSigningSecret(s.svc.encryptionKey)
|
return wc.DecryptSigningSecret(s.svc.encryptionKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s WebhookConfigurationService) ListCallsForConfigurationID(
|
func (s WebhookConfigurationService) ListEventsForConfigurationID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
webhookConfigurationID gid.GID,
|
webhookConfigurationID gid.GID,
|
||||||
cursor *page.Cursor[coredata.WebhookCallOrderField],
|
cursor *page.Cursor[coredata.WebhookEventOrderField],
|
||||||
) (*page.Page[*coredata.WebhookCall, coredata.WebhookCallOrderField], error) {
|
) (*page.Page[*coredata.WebhookEvent, coredata.WebhookEventOrderField], error) {
|
||||||
var calls coredata.WebhookCalls
|
var events coredata.WebhookEvents
|
||||||
|
|
||||||
err := s.svc.pg.WithConn(
|
err := s.svc.pg.WithConn(
|
||||||
ctx,
|
ctx,
|
||||||
func(conn pg.Conn) error {
|
func(conn pg.Conn) error {
|
||||||
if err := calls.LoadByConfigurationID(ctx, conn, s.svc.scope, webhookConfigurationID, cursor); err != nil {
|
if err := events.LoadByConfigurationID(ctx, conn, s.svc.scope, webhookConfigurationID, cursor); err != nil {
|
||||||
return fmt.Errorf("cannot load webhook calls: %w", err)
|
return fmt.Errorf("cannot load webhook events: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -283,10 +283,10 @@ func (s WebhookConfigurationService) ListCallsForConfigurationID(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return page.NewPage(calls, cursor), nil
|
return page.NewPage(events, cursor), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s WebhookConfigurationService) CountCallsForConfigurationID(
|
func (s WebhookConfigurationService) CountEventsForConfigurationID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
webhookConfigurationID gid.GID,
|
webhookConfigurationID gid.GID,
|
||||||
) (int, error) {
|
) (int, error) {
|
||||||
@@ -295,11 +295,11 @@ func (s WebhookConfigurationService) CountCallsForConfigurationID(
|
|||||||
err := s.svc.pg.WithConn(
|
err := s.svc.pg.WithConn(
|
||||||
ctx,
|
ctx,
|
||||||
func(conn pg.Conn) (err error) {
|
func(conn pg.Conn) (err error) {
|
||||||
calls := &coredata.WebhookCalls{}
|
events := &coredata.WebhookEvents{}
|
||||||
count, err = calls.CountByConfigurationID(ctx, conn, s.svc.scope, webhookConfigurationID)
|
count, err = events.CountByConfigurationID(ctx, conn, s.svc.scope, webhookConfigurationID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot count webhook calls: %w", err)
|
return fmt.Errorf("cannot count webhook events: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -2293,13 +2293,13 @@ type WebhookConfiguration implements Node {
|
|||||||
createdAt: Datetime!
|
createdAt: Datetime!
|
||||||
updatedAt: Datetime!
|
updatedAt: Datetime!
|
||||||
|
|
||||||
calls(
|
events(
|
||||||
first: Int
|
first: Int
|
||||||
after: CursorKey
|
after: CursorKey
|
||||||
last: Int
|
last: Int
|
||||||
before: CursorKey
|
before: CursorKey
|
||||||
orderBy: WebhookCallOrder
|
orderBy: WebhookEventOrder
|
||||||
): WebhookCallConnection! @goField(forceResolver: true)
|
): WebhookEventConnection! @goField(forceResolver: true)
|
||||||
|
|
||||||
permission(action: String!): Boolean! @goField(forceResolver: true)
|
permission(action: String!): Boolean! @goField(forceResolver: true)
|
||||||
}
|
}
|
||||||
@@ -2318,54 +2318,54 @@ type WebhookConfigurationEdge {
|
|||||||
node: WebhookConfiguration!
|
node: WebhookConfiguration!
|
||||||
}
|
}
|
||||||
|
|
||||||
enum WebhookCallStatus
|
enum WebhookEventStatus
|
||||||
@goModel(model: "go.probo.inc/probo/pkg/coredata.WebhookCallStatus") {
|
@goModel(model: "go.probo.inc/probo/pkg/coredata.WebhookEventStatus") {
|
||||||
SUCCEEDED
|
SUCCEEDED
|
||||||
@goEnum(value: "go.probo.inc/probo/pkg/coredata.WebhookCallStatusSucceeded")
|
@goEnum(value: "go.probo.inc/probo/pkg/coredata.WebhookEventStatusSucceeded")
|
||||||
FAILED
|
FAILED
|
||||||
@goEnum(value: "go.probo.inc/probo/pkg/coredata.WebhookCallStatusFailed")
|
@goEnum(value: "go.probo.inc/probo/pkg/coredata.WebhookEventStatusFailed")
|
||||||
}
|
}
|
||||||
|
|
||||||
enum WebhookCallOrderField
|
enum WebhookEventOrderField
|
||||||
@goModel(
|
@goModel(
|
||||||
model: "go.probo.inc/probo/pkg/coredata.WebhookCallOrderField"
|
model: "go.probo.inc/probo/pkg/coredata.WebhookEventOrderField"
|
||||||
) {
|
) {
|
||||||
CREATED_AT
|
CREATED_AT
|
||||||
@goEnum(
|
@goEnum(
|
||||||
value: "go.probo.inc/probo/pkg/coredata.WebhookCallOrderFieldCreatedAt"
|
value: "go.probo.inc/probo/pkg/coredata.WebhookEventOrderFieldCreatedAt"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
input WebhookCallOrder
|
input WebhookEventOrder
|
||||||
@goModel(
|
@goModel(
|
||||||
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.WebhookCallOrderBy"
|
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.WebhookEventOrderBy"
|
||||||
) {
|
) {
|
||||||
field: WebhookCallOrderField!
|
field: WebhookEventOrderField!
|
||||||
direction: OrderDirection!
|
direction: OrderDirection!
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebhookCall implements Node {
|
type WebhookEvent implements Node {
|
||||||
id: ID!
|
id: ID!
|
||||||
webhookEventId: ID!
|
webhookDataId: ID!
|
||||||
webhookConfigurationId: ID!
|
webhookConfigurationId: ID!
|
||||||
endpointUrl: String!
|
endpointUrl: String!
|
||||||
status: WebhookCallStatus!
|
status: WebhookEventStatus!
|
||||||
response: String
|
response: String
|
||||||
createdAt: Datetime!
|
createdAt: Datetime!
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebhookCallConnection
|
type WebhookEventConnection
|
||||||
@goModel(
|
@goModel(
|
||||||
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.WebhookCallConnection"
|
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.WebhookEventConnection"
|
||||||
) {
|
) {
|
||||||
edges: [WebhookCallEdge!]!
|
edges: [WebhookEventEdge!]!
|
||||||
pageInfo: PageInfo!
|
pageInfo: PageInfo!
|
||||||
totalCount: Int! @goField(forceResolver: true)
|
totalCount: Int! @goField(forceResolver: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebhookCallEdge {
|
type WebhookEventEdge {
|
||||||
cursor: CursorKey!
|
cursor: CursorKey!
|
||||||
node: WebhookCall!
|
node: WebhookEvent!
|
||||||
}
|
}
|
||||||
|
|
||||||
type StateOfApplicability implements Node {
|
type StateOfApplicability implements Node {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2623,24 +2623,6 @@ type Viewer struct {
|
|||||||
SignableDocument *SignableDocument `json:"signableDocument,omitempty"`
|
SignableDocument *SignableDocument `json:"signableDocument,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebhookCall struct {
|
|
||||||
ID gid.GID `json:"id"`
|
|
||||||
WebhookEventID gid.GID `json:"webhookEventId"`
|
|
||||||
WebhookConfigurationID gid.GID `json:"webhookConfigurationId"`
|
|
||||||
EndpointURL string `json:"endpointUrl"`
|
|
||||||
Status coredata.WebhookCallStatus `json:"status"`
|
|
||||||
Response *string `json:"response,omitempty"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (WebhookCall) IsNode() {}
|
|
||||||
func (this WebhookCall) GetID() gid.GID { return this.ID }
|
|
||||||
|
|
||||||
type WebhookCallEdge struct {
|
|
||||||
Cursor page.CursorKey `json:"cursor"`
|
|
||||||
Node *WebhookCall `json:"node"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type WebhookConfiguration struct {
|
type WebhookConfiguration struct {
|
||||||
ID gid.GID `json:"id"`
|
ID gid.GID `json:"id"`
|
||||||
Organization *Organization `json:"organization,omitempty"`
|
Organization *Organization `json:"organization,omitempty"`
|
||||||
@@ -2649,7 +2631,7 @@ type WebhookConfiguration struct {
|
|||||||
SelectedEvents []coredata.WebhookEventType `json:"selectedEvents"`
|
SelectedEvents []coredata.WebhookEventType `json:"selectedEvents"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
Calls *WebhookCallConnection `json:"calls"`
|
Events *WebhookEventConnection `json:"events"`
|
||||||
Permission bool `json:"permission"`
|
Permission bool `json:"permission"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2660,3 +2642,21 @@ type WebhookConfigurationEdge struct {
|
|||||||
Cursor page.CursorKey `json:"cursor"`
|
Cursor page.CursorKey `json:"cursor"`
|
||||||
Node *WebhookConfiguration `json:"node"`
|
Node *WebhookConfiguration `json:"node"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type WebhookEvent struct {
|
||||||
|
ID gid.GID `json:"id"`
|
||||||
|
WebhookDataID gid.GID `json:"webhookDataId"`
|
||||||
|
WebhookConfigurationID gid.GID `json:"webhookConfigurationId"`
|
||||||
|
EndpointURL string `json:"endpointUrl"`
|
||||||
|
Status coredata.WebhookEventStatus `json:"status"`
|
||||||
|
Response *string `json:"response,omitempty"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (WebhookEvent) IsNode() {}
|
||||||
|
func (this WebhookEvent) GetID() gid.GID { return this.ID }
|
||||||
|
|
||||||
|
type WebhookEventEdge struct {
|
||||||
|
Cursor page.CursorKey `json:"cursor"`
|
||||||
|
Node *WebhookEvent `json:"node"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
WebhookCallOrderBy OrderBy[coredata.WebhookCallOrderField]
|
WebhookEventOrderBy OrderBy[coredata.WebhookEventOrderField]
|
||||||
|
|
||||||
WebhookCallConnection struct {
|
WebhookEventConnection struct {
|
||||||
TotalCount int
|
TotalCount int
|
||||||
Edges []*WebhookCallEdge
|
Edges []*WebhookEventEdge
|
||||||
PageInfo PageInfo
|
PageInfo PageInfo
|
||||||
|
|
||||||
Resolver any
|
Resolver any
|
||||||
@@ -33,18 +33,18 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewWebhookCallConnection(
|
func NewWebhookEventConnection(
|
||||||
p *page.Page[*coredata.WebhookCall, coredata.WebhookCallOrderField],
|
p *page.Page[*coredata.WebhookEvent, coredata.WebhookEventOrderField],
|
||||||
parentType any,
|
parentType any,
|
||||||
parentID gid.GID,
|
parentID gid.GID,
|
||||||
) *WebhookCallConnection {
|
) *WebhookEventConnection {
|
||||||
var edges = make([]*WebhookCallEdge, len(p.Data))
|
var edges = make([]*WebhookEventEdge, len(p.Data))
|
||||||
|
|
||||||
for i := range edges {
|
for i := range edges {
|
||||||
edges[i] = NewWebhookCallEdge(p.Data[i], p.Cursor.OrderBy.Field)
|
edges[i] = NewWebhookEventEdge(p.Data[i], p.Cursor.OrderBy.Field)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &WebhookCallConnection{
|
return &WebhookEventConnection{
|
||||||
Edges: edges,
|
Edges: edges,
|
||||||
PageInfo: *NewPageInfo(p),
|
PageInfo: *NewPageInfo(p),
|
||||||
|
|
||||||
@@ -53,27 +53,27 @@ func NewWebhookCallConnection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWebhookCallEdge(wc *coredata.WebhookCall, orderBy coredata.WebhookCallOrderField) *WebhookCallEdge {
|
func NewWebhookEventEdge(we *coredata.WebhookEvent, orderBy coredata.WebhookEventOrderField) *WebhookEventEdge {
|
||||||
return &WebhookCallEdge{
|
return &WebhookEventEdge{
|
||||||
Cursor: wc.CursorKey(orderBy),
|
Cursor: we.CursorKey(orderBy),
|
||||||
Node: NewWebhookCall(wc),
|
Node: NewWebhookEvent(we),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWebhookCall(wc *coredata.WebhookCall) *WebhookCall {
|
func NewWebhookEvent(we *coredata.WebhookEvent) *WebhookEvent {
|
||||||
var response *string
|
var response *string
|
||||||
if len(wc.Response) > 0 {
|
if len(we.Response) > 0 {
|
||||||
s := string(wc.Response)
|
s := string(we.Response)
|
||||||
response = &s
|
response = &s
|
||||||
}
|
}
|
||||||
|
|
||||||
return &WebhookCall{
|
return &WebhookEvent{
|
||||||
ID: wc.ID,
|
ID: we.ID,
|
||||||
WebhookEventID: wc.WebhookEventID,
|
WebhookDataID: we.WebhookDataID,
|
||||||
WebhookConfigurationID: wc.WebhookConfigurationID,
|
WebhookConfigurationID: we.WebhookConfigurationID,
|
||||||
EndpointURL: wc.EndpointURL,
|
EndpointURL: we.EndpointURL,
|
||||||
Status: wc.Status,
|
Status: we.Status,
|
||||||
Response: response,
|
Response: response,
|
||||||
CreatedAt: wc.CreatedAt,
|
CreatedAt: we.CreatedAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8559,23 +8559,6 @@ func (r *viewerResolver) SignableDocument(ctx context.Context, obj *types.Viewer
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TotalCount is the resolver for the totalCount field.
|
|
||||||
func (r *webhookCallConnectionResolver) TotalCount(ctx context.Context, obj *types.WebhookCallConnection) (int, error) {
|
|
||||||
if err := r.authorize(ctx, obj.ParentID, probo.ActionWebhookConfigurationGet); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
|
||||||
|
|
||||||
count, err := prb.WebhookConfigurations.CountCallsForConfigurationID(ctx, obj.ParentID)
|
|
||||||
if err != nil {
|
|
||||||
r.logger.ErrorCtx(ctx, "cannot count webhook calls", log.Error(err))
|
|
||||||
return 0, gqlutils.Internal(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
return count, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Organization is the resolver for the organization field.
|
// Organization is the resolver for the organization field.
|
||||||
func (r *webhookConfigurationResolver) Organization(ctx context.Context, obj *types.WebhookConfiguration) (*types.Organization, error) {
|
func (r *webhookConfigurationResolver) Organization(ctx context.Context, obj *types.WebhookConfiguration) (*types.Organization, error) {
|
||||||
if err := r.authorize(ctx, obj.ID, probo.ActionOrganizationGet); err != nil {
|
if err := r.authorize(ctx, obj.ID, probo.ActionOrganizationGet); err != nil {
|
||||||
@@ -8599,6 +8582,10 @@ func (r *webhookConfigurationResolver) Organization(ctx context.Context, obj *ty
|
|||||||
|
|
||||||
// SigningSecret is the resolver for the signingSecret field.
|
// SigningSecret is the resolver for the signingSecret field.
|
||||||
func (r *webhookConfigurationResolver) SigningSecret(ctx context.Context, obj *types.WebhookConfiguration) (string, error) {
|
func (r *webhookConfigurationResolver) SigningSecret(ctx context.Context, obj *types.WebhookConfiguration) (string, error) {
|
||||||
|
if err := r.authorize(ctx, obj.ID, probo.ActionWebhookConfigurationUpdate); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||||
|
|
||||||
signingSecret, err := prb.WebhookConfigurations.GetSigningSecret(ctx, obj.ID)
|
signingSecret, err := prb.WebhookConfigurations.GetSigningSecret(ctx, obj.ID)
|
||||||
@@ -8610,20 +8597,20 @@ func (r *webhookConfigurationResolver) SigningSecret(ctx context.Context, obj *t
|
|||||||
return signingSecret, nil
|
return signingSecret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calls is the resolver for the calls field.
|
// Events is the resolver for the events field.
|
||||||
func (r *webhookConfigurationResolver) Calls(ctx context.Context, obj *types.WebhookConfiguration, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.WebhookCallOrderBy) (*types.WebhookCallConnection, error) {
|
func (r *webhookConfigurationResolver) Events(ctx context.Context, obj *types.WebhookConfiguration, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.WebhookEventOrderBy) (*types.WebhookEventConnection, error) {
|
||||||
if err := r.authorize(ctx, obj.ID, probo.ActionWebhookConfigurationGet); err != nil {
|
if err := r.authorize(ctx, obj.ID, probo.ActionWebhookConfigurationGet); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
prb := r.ProboService(ctx, obj.ID.TenantID())
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
||||||
|
|
||||||
pageOrderBy := page.OrderBy[coredata.WebhookCallOrderField]{
|
pageOrderBy := page.OrderBy[coredata.WebhookEventOrderField]{
|
||||||
Field: coredata.WebhookCallOrderFieldCreatedAt,
|
Field: coredata.WebhookEventOrderFieldCreatedAt,
|
||||||
Direction: page.OrderDirectionDesc,
|
Direction: page.OrderDirectionDesc,
|
||||||
}
|
}
|
||||||
if orderBy != nil {
|
if orderBy != nil {
|
||||||
pageOrderBy = page.OrderBy[coredata.WebhookCallOrderField]{
|
pageOrderBy = page.OrderBy[coredata.WebhookEventOrderField]{
|
||||||
Field: orderBy.Field,
|
Field: orderBy.Field,
|
||||||
Direction: orderBy.Direction,
|
Direction: orderBy.Direction,
|
||||||
}
|
}
|
||||||
@@ -8631,13 +8618,13 @@ func (r *webhookConfigurationResolver) Calls(ctx context.Context, obj *types.Web
|
|||||||
|
|
||||||
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
||||||
|
|
||||||
page, err := prb.WebhookConfigurations.ListCallsForConfigurationID(ctx, obj.ID, cursor)
|
page, err := prb.WebhookConfigurations.ListEventsForConfigurationID(ctx, obj.ID, cursor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.logger.ErrorCtx(ctx, "cannot list webhook calls", log.Error(err))
|
r.logger.ErrorCtx(ctx, "cannot list webhook events", log.Error(err))
|
||||||
return nil, gqlutils.Internal(ctx)
|
return nil, gqlutils.Internal(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
return types.NewWebhookCallConnection(page, r, obj.ID), nil
|
return types.NewWebhookEventConnection(page, r, obj.ID), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Permission is the resolver for the permission field.
|
// Permission is the resolver for the permission field.
|
||||||
@@ -8667,6 +8654,23 @@ func (r *webhookConfigurationConnectionResolver) TotalCount(ctx context.Context,
|
|||||||
return 0, gqlutils.Internal(ctx)
|
return 0, gqlutils.Internal(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TotalCount is the resolver for the totalCount field.
|
||||||
|
func (r *webhookEventConnectionResolver) TotalCount(ctx context.Context, obj *types.WebhookEventConnection) (int, error) {
|
||||||
|
if err := r.authorize(ctx, obj.ParentID, probo.ActionWebhookConfigurationGet); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
||||||
|
|
||||||
|
count, err := prb.WebhookConfigurations.CountEventsForConfigurationID(ctx, obj.ParentID)
|
||||||
|
if err != nil {
|
||||||
|
r.logger.ErrorCtx(ctx, "cannot count webhook events", log.Error(err))
|
||||||
|
return 0, gqlutils.Internal(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ApplicabilityStatement returns schema.ApplicabilityStatementResolver implementation.
|
// ApplicabilityStatement returns schema.ApplicabilityStatementResolver implementation.
|
||||||
func (r *Resolver) ApplicabilityStatement() schema.ApplicabilityStatementResolver {
|
func (r *Resolver) ApplicabilityStatement() schema.ApplicabilityStatementResolver {
|
||||||
return &applicabilityStatementResolver{r}
|
return &applicabilityStatementResolver{r}
|
||||||
@@ -8969,11 +8973,6 @@ func (r *Resolver) VendorService() schema.VendorServiceResolver { return &vendor
|
|||||||
// Viewer returns schema.ViewerResolver implementation.
|
// Viewer returns schema.ViewerResolver implementation.
|
||||||
func (r *Resolver) Viewer() schema.ViewerResolver { return &viewerResolver{r} }
|
func (r *Resolver) Viewer() schema.ViewerResolver { return &viewerResolver{r} }
|
||||||
|
|
||||||
// WebhookCallConnection returns schema.WebhookCallConnectionResolver implementation.
|
|
||||||
func (r *Resolver) WebhookCallConnection() schema.WebhookCallConnectionResolver {
|
|
||||||
return &webhookCallConnectionResolver{r}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WebhookConfiguration returns schema.WebhookConfigurationResolver implementation.
|
// WebhookConfiguration returns schema.WebhookConfigurationResolver implementation.
|
||||||
func (r *Resolver) WebhookConfiguration() schema.WebhookConfigurationResolver {
|
func (r *Resolver) WebhookConfiguration() schema.WebhookConfigurationResolver {
|
||||||
return &webhookConfigurationResolver{r}
|
return &webhookConfigurationResolver{r}
|
||||||
@@ -8984,6 +8983,11 @@ func (r *Resolver) WebhookConfigurationConnection() schema.WebhookConfigurationC
|
|||||||
return &webhookConfigurationConnectionResolver{r}
|
return &webhookConfigurationConnectionResolver{r}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WebhookEventConnection returns schema.WebhookEventConnectionResolver implementation.
|
||||||
|
func (r *Resolver) WebhookEventConnection() schema.WebhookEventConnectionResolver {
|
||||||
|
return &webhookEventConnectionResolver{r}
|
||||||
|
}
|
||||||
|
|
||||||
type applicabilityStatementResolver struct{ *Resolver }
|
type applicabilityStatementResolver struct{ *Resolver }
|
||||||
type applicabilityStatementConnectionResolver struct{ *Resolver }
|
type applicabilityStatementConnectionResolver struct{ *Resolver }
|
||||||
type assetResolver struct{ *Resolver }
|
type assetResolver struct{ *Resolver }
|
||||||
@@ -9056,6 +9060,6 @@ type vendorDataPrivacyAgreementResolver struct{ *Resolver }
|
|||||||
type vendorRiskAssessmentResolver struct{ *Resolver }
|
type vendorRiskAssessmentResolver struct{ *Resolver }
|
||||||
type vendorServiceResolver struct{ *Resolver }
|
type vendorServiceResolver struct{ *Resolver }
|
||||||
type viewerResolver struct{ *Resolver }
|
type viewerResolver struct{ *Resolver }
|
||||||
type webhookCallConnectionResolver struct{ *Resolver }
|
|
||||||
type webhookConfigurationResolver struct{ *Resolver }
|
type webhookConfigurationResolver struct{ *Resolver }
|
||||||
type webhookConfigurationConnectionResolver struct{ *Resolver }
|
type webhookConfigurationConnectionResolver struct{ *Resolver }
|
||||||
|
type webhookEventConnectionResolver struct{ *Resolver }
|
||||||
|
|||||||
@@ -48,17 +48,17 @@ func InsertEvent(
|
|||||||
return fmt.Errorf("cannot marshal webhook event data: %w", err)
|
return fmt.Errorf("cannot marshal webhook event data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
event := &coredata.WebhookEvent{
|
webhookData := &coredata.WebhookData{
|
||||||
ID: gid.New(scope.GetTenantID(), coredata.WebhookEventEntityType),
|
ID: gid.New(scope.GetTenantID(), coredata.WebhookDataEntityType),
|
||||||
OrganizationID: organizationID,
|
OrganizationID: organizationID,
|
||||||
EventType: eventType,
|
EventType: eventType,
|
||||||
Status: coredata.WebhookEventStatusPending,
|
Status: coredata.WebhookDataStatusPending,
|
||||||
Data: raw,
|
Data: raw,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = event.Insert(ctx, conn, scope); err != nil {
|
if err = webhookData.Insert(ctx, conn, scope); err != nil {
|
||||||
return fmt.Errorf("cannot insert webhook event: %w", err)
|
return fmt.Errorf("cannot insert webhook data: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func (s *Sender) Run(ctx context.Context) error {
|
|||||||
|
|
||||||
func (s *Sender) processEvents(ctx context.Context) error {
|
func (s *Sender) processEvents(ctx context.Context) error {
|
||||||
for {
|
for {
|
||||||
event, err := s.claimNextEvent(ctx)
|
webhookData, err := s.claimNextWebhookData(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||||
return nil
|
return nil
|
||||||
@@ -99,24 +99,24 @@ func (s *Sender) processEvents(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.processEvent(ctx, event)
|
s.processWebhookData(ctx, webhookData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sender) claimNextEvent(ctx context.Context) (*coredata.WebhookEvent, error) {
|
func (s *Sender) claimNextWebhookData(ctx context.Context) (*coredata.WebhookData, error) {
|
||||||
var event coredata.WebhookEvent
|
var webhookData coredata.WebhookData
|
||||||
|
|
||||||
err := s.pg.WithTx(ctx, func(tx pg.Conn) error {
|
err := s.pg.WithTx(ctx, func(tx pg.Conn) error {
|
||||||
if err := event.LoadNextPendingForUpdate(ctx, tx); err != nil {
|
if err := webhookData.LoadNextPendingForUpdate(ctx, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
scope := coredata.NewScopeFromObjectID(event.ID)
|
scope := coredata.NewScopeFromObjectID(webhookData.ID)
|
||||||
|
|
||||||
event.Status = coredata.WebhookEventStatusProcessing
|
webhookData.Status = coredata.WebhookDataStatusProcessing
|
||||||
|
|
||||||
if err := event.UpdateStatus(ctx, tx, scope); err != nil {
|
if err := webhookData.UpdateStatus(ctx, tx, scope); err != nil {
|
||||||
return fmt.Errorf("cannot update webhook event to processing: %w", err)
|
return fmt.Errorf("cannot update webhook data to processing: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -126,77 +126,77 @@ func (s *Sender) claimNextEvent(ctx context.Context) (*coredata.WebhookEvent, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &event, nil
|
return &webhookData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sender) processEvent(ctx context.Context, event *coredata.WebhookEvent) {
|
func (s *Sender) processWebhookData(ctx context.Context, webhookData *coredata.WebhookData) {
|
||||||
scope := coredata.NewScopeFromObjectID(event.ID)
|
scope := coredata.NewScopeFromObjectID(webhookData.ID)
|
||||||
|
|
||||||
var configs coredata.WebhookConfigurations
|
var configs coredata.WebhookConfigurations
|
||||||
err := s.pg.WithConn(ctx, func(conn pg.Conn) error {
|
err := s.pg.WithConn(ctx, func(conn pg.Conn) error {
|
||||||
return configs.LoadMatchingByOrganizationIDAndEventType(
|
return configs.LoadMatchingByOrganizationIDAndEventType(
|
||||||
ctx, conn, scope, event.OrganizationID, event.EventType,
|
ctx, conn, scope, webhookData.OrganizationID, webhookData.EventType,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.ErrorCtx(ctx, "cannot load matching webhook configurations",
|
s.logger.ErrorCtx(ctx, "cannot load matching webhook configurations",
|
||||||
log.Error(err),
|
log.Error(err),
|
||||||
log.String("event_id", event.ID.String()),
|
log.String("webhook_data_id", webhookData.ID.String()),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, config := range configs {
|
for _, config := range configs {
|
||||||
s.deliverToConfiguration(ctx, event, config, scope)
|
s.deliverToConfiguration(ctx, webhookData, config, scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
event.Status = coredata.WebhookEventStatusDelivered
|
webhookData.Status = coredata.WebhookDataStatusDelivered
|
||||||
event.ProcessedAt = &now
|
webhookData.ProcessedAt = &now
|
||||||
|
|
||||||
err = s.pg.WithConn(ctx, func(conn pg.Conn) error {
|
err = s.pg.WithConn(ctx, func(conn pg.Conn) error {
|
||||||
return event.UpdateStatus(ctx, conn, scope)
|
return webhookData.UpdateStatus(ctx, conn, scope)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.ErrorCtx(ctx, "cannot update webhook event to delivered",
|
s.logger.ErrorCtx(ctx, "cannot update webhook data to delivered",
|
||||||
log.Error(err),
|
log.Error(err),
|
||||||
log.String("event_id", event.ID.String()),
|
log.String("webhook_data_id", webhookData.ID.String()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sender) deliverToConfiguration(
|
func (s *Sender) deliverToConfiguration(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
event *coredata.WebhookEvent,
|
webhookData *coredata.WebhookData,
|
||||||
config *coredata.WebhookConfiguration,
|
config *coredata.WebhookConfiguration,
|
||||||
scope coredata.Scoper,
|
scope coredata.Scoper,
|
||||||
) {
|
) {
|
||||||
callID := gid.New(event.ID.TenantID(), coredata.WebhookCallEntityType)
|
eventID := gid.New(webhookData.ID.TenantID(), coredata.WebhookEventEntityType)
|
||||||
|
|
||||||
signingSecret, err := s.getSigningSecret(config.ID.String(), config.EncryptedSigningSecret)
|
signingSecret, err := s.getSigningSecret(config.ID.String(), config.EncryptedSigningSecret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.ErrorCtx(ctx, "cannot get signing secret",
|
s.logger.ErrorCtx(ctx, "cannot get signing secret",
|
||||||
log.Error(err),
|
log.Error(err),
|
||||||
log.String("event_id", event.ID.String()),
|
log.String("webhook_data_id", webhookData.ID.String()),
|
||||||
log.String("configuration_id", config.ID.String()),
|
log.String("configuration_id", config.ID.String()),
|
||||||
)
|
)
|
||||||
s.recordCall(ctx, callID, event, config, scope, coredata.WebhookCallStatusFailed, nil)
|
s.recordEvent(ctx, eventID, webhookData, config, scope, coredata.WebhookEventStatusFailed, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response, sendErr := s.doHTTPCall(ctx, callID, config.EndpointURL, event, config.ID, signingSecret)
|
response, sendErr := s.doHTTPCall(ctx, eventID, config.EndpointURL, webhookData, config.ID, signingSecret)
|
||||||
|
|
||||||
callStatus := coredata.WebhookCallStatusSucceeded
|
eventStatus := coredata.WebhookEventStatusSucceeded
|
||||||
if sendErr != nil {
|
if sendErr != nil {
|
||||||
callStatus = coredata.WebhookCallStatusFailed
|
eventStatus = coredata.WebhookEventStatusFailed
|
||||||
s.logger.ErrorCtx(ctx, "error delivering webhook event",
|
s.logger.ErrorCtx(ctx, "error delivering webhook",
|
||||||
log.Error(sendErr),
|
log.Error(sendErr),
|
||||||
log.String("event_id", event.ID.String()),
|
log.String("webhook_data_id", webhookData.ID.String()),
|
||||||
log.String("endpoint_url", config.EndpointURL),
|
log.String("endpoint_url", config.EndpointURL),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.recordCall(ctx, callID, event, config, scope, callStatus, response)
|
s.recordEvent(ctx, eventID, webhookData, config, scope, eventStatus, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sender) getSigningSecret(webhookConfigurationID string, encryptedSigningSecret []byte) (string, error) {
|
func (s *Sender) getSigningSecret(webhookConfigurationID string, encryptedSigningSecret []byte) (string, error) {
|
||||||
@@ -217,20 +217,19 @@ func (s *Sender) getSigningSecret(webhookConfigurationID string, encryptedSignin
|
|||||||
|
|
||||||
func (s *Sender) doHTTPCall(
|
func (s *Sender) doHTTPCall(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
callID gid.GID,
|
eventID gid.GID,
|
||||||
endpointURL string,
|
endpointURL string,
|
||||||
event *coredata.WebhookEvent,
|
webhookData *coredata.WebhookData,
|
||||||
configurationID gid.GID,
|
configurationID gid.GID,
|
||||||
signingSecret string,
|
signingSecret string,
|
||||||
) (json.RawMessage, error) {
|
) (json.RawMessage, error) {
|
||||||
payload := map[string]any{
|
payload := map[string]any{
|
||||||
"eventId": event.ID.String(),
|
"eventId": eventID.String(),
|
||||||
"callId": callID.String(),
|
|
||||||
"configurationId": configurationID.String(),
|
"configurationId": configurationID.String(),
|
||||||
"organizationId": event.OrganizationID.String(),
|
"organizationId": webhookData.OrganizationID.String(),
|
||||||
"eventType": event.EventType.String(),
|
"eventType": webhookData.EventType.String(),
|
||||||
"createdAt": event.CreatedAt,
|
"createdAt": webhookData.CreatedAt,
|
||||||
"data": event.Data,
|
"data": webhookData.Data,
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := json.Marshal(payload)
|
body, err := json.Marshal(payload)
|
||||||
@@ -250,7 +249,7 @@ func (s *Sender) doHTTPCall(
|
|||||||
signature := computeSignature(signingSecret, timestamp, body)
|
signature := computeSignature(signingSecret, timestamp, body)
|
||||||
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Probo-Webhook-Event", event.EventType.String())
|
req.Header.Set("X-Probo-Webhook-Event", webhookData.EventType.String())
|
||||||
req.Header.Set("X-Probo-Webhook-Timestamp", timestamp)
|
req.Header.Set("X-Probo-Webhook-Timestamp", timestamp)
|
||||||
req.Header.Set("X-Probo-Webhook-Signature", signature)
|
req.Header.Set("X-Probo-Webhook-Signature", signature)
|
||||||
|
|
||||||
@@ -275,18 +274,18 @@ func (s *Sender) doHTTPCall(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sender) recordCall(
|
func (s *Sender) recordEvent(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
callID gid.GID,
|
eventID gid.GID,
|
||||||
event *coredata.WebhookEvent,
|
webhookData *coredata.WebhookData,
|
||||||
config *coredata.WebhookConfiguration,
|
config *coredata.WebhookConfiguration,
|
||||||
scope coredata.Scoper,
|
scope coredata.Scoper,
|
||||||
status coredata.WebhookCallStatus,
|
status coredata.WebhookEventStatus,
|
||||||
response json.RawMessage,
|
response json.RawMessage,
|
||||||
) {
|
) {
|
||||||
call := coredata.WebhookCall{
|
event := coredata.WebhookEvent{
|
||||||
ID: callID,
|
ID: eventID,
|
||||||
WebhookEventID: event.ID,
|
WebhookDataID: webhookData.ID,
|
||||||
WebhookConfigurationID: config.ID,
|
WebhookConfigurationID: config.ID,
|
||||||
EndpointURL: config.EndpointURL,
|
EndpointURL: config.EndpointURL,
|
||||||
Status: status,
|
Status: status,
|
||||||
@@ -295,12 +294,12 @@ func (s *Sender) recordCall(
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := s.pg.WithConn(ctx, func(conn pg.Conn) error {
|
err := s.pg.WithConn(ctx, func(conn pg.Conn) error {
|
||||||
return call.Insert(ctx, conn, scope)
|
return event.Insert(ctx, conn, scope)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.ErrorCtx(ctx, "cannot insert webhook call",
|
s.logger.ErrorCtx(ctx, "cannot insert webhook event",
|
||||||
log.Error(err),
|
log.Error(err),
|
||||||
log.String("event_id", event.ID.String()),
|
log.String("webhook_data_id", webhookData.ID.String()),
|
||||||
log.String("configuration_id", config.ID.String()),
|
log.String("configuration_id", config.ID.String()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user