Stringify event payload and context before serialization

This fixes an issue where an event payload was being serialized through remix-typedjson and was causing issues with incorrect meta keys and so deserialization was failing. See https://github.com/kiliman/remix-typedjson/pull/33 for more
This commit is contained in:
Eric Allam
2023-10-06 11:21:14 +01:00
parent 9a187f9eda
commit c17faabe9f
6 changed files with 47 additions and 15 deletions
@@ -12,7 +12,7 @@ import {
import { JobRunStatus, RuntimeEnvironmentType } from "@trigger.dev/database";
import { useMemo } from "react";
import { usePathName } from "~/hooks/usePathName";
import { Run } from "~/presenters/RunPresenter.server";
import { ViewRun } from "~/presenters/RunPresenter.server";
import { cancelSchema } from "~/routes/resources.runs.$runId.cancel";
import { schema } from "~/routes/resources.runs.$runId.rerun";
import { formatDuration } from "~/utils";
@@ -59,7 +59,7 @@ import { TaskCard } from "./TaskCard";
import { TaskCardSkeleton } from "./TaskCardSkeleton";
type RunOverviewProps = {
run: Run;
run: ViewRun;
trigger: {
icon: string;
title: string;
+2 -2
View File
@@ -3,7 +3,7 @@ import { AnimatePresence, motion } from "framer-motion";
import { Fragment, useState } from "react";
import simplur from "simplur";
import { Paragraph } from "~/components/primitives/Paragraph";
import { Task } from "~/presenters/RunPresenter.server";
import { ViewTask } from "~/presenters/RunPresenter.server";
import { formatDuration } from "~/utils";
import { cn } from "~/utils/cn";
import {
@@ -22,7 +22,7 @@ import {
} from "./RunCard";
import { TaskStatusIcon } from "./TaskStatus";
type TaskCardProps = Task & {
type TaskCardProps = ViewTask & {
selectedId?: string;
selectedTask: (id: string) => void;
isLast: boolean;
@@ -25,7 +25,7 @@ export function TriggerDetail({
};
properties: DisplayProperty[];
}) {
const { id, name, payload, timestamp, deliveredAt } = trigger;
const { id, name, payload, context, timestamp, deliveredAt } = trigger;
return (
<RunPanel selected={false}>
@@ -45,6 +45,7 @@ export function TriggerDetail({
/>
)}
<RunPanelIconProperty icon="id" label="Event name" value={name} />
<RunPanelIconProperty icon="account" label="Event ID" value={id} />
{trigger.externalAccount && (
<RunPanelIconProperty
icon="account"
@@ -62,7 +63,9 @@ export function TriggerDetail({
</div>
)}
<Header3>Payload</Header3>
<CodeBlock code={JSON.stringify(payload, null, 2)} />
<CodeBlock code={payload} />
<Header3>Context</Header3>
<CodeBlock code={context} />
</div>
</RunPanelBody>
</RunPanel>
@@ -13,10 +13,11 @@ type RunOptions = {
userId: string;
};
export type Run = NonNullable<Awaited<ReturnType<RunPresenter["call"]>>>;
export type Task = NonNullable<Awaited<ReturnType<RunPresenter["call"]>>>["tasks"][number];
export type Event = NonNullable<Awaited<ReturnType<RunPresenter["call"]>>>["event"];
export type ViewRun = NonNullable<Awaited<ReturnType<RunPresenter["call"]>>>;
export type ViewTask = NonNullable<Awaited<ReturnType<RunPresenter["call"]>>>["tasks"][number];
export type ViewEvent = NonNullable<Awaited<ReturnType<RunPresenter["call"]>>>["event"];
type QueryEvent = NonNullable<Awaited<ReturnType<RunPresenter["query"]>>>["event"];
type QueryTask = NonNullable<Awaited<ReturnType<RunPresenter["query"]>>>["tasks"][number];
export class RunPresenter {
@@ -76,7 +77,7 @@ export class RunPresenter {
type: run.environment.type,
slug: run.environment.slug,
},
event: run.event,
event: this.#prepareEventData(run.event),
tasks,
runConnections: run.runConnections,
missingConnections: run.missingConnections,
@@ -84,6 +85,22 @@ export class RunPresenter {
};
}
#prepareEventData(event: QueryEvent) {
return {
id: event.eventId,
name: event.name,
payload: JSON.stringify(event.payload),
context: JSON.stringify(event.context),
timestamp: event.timestamp,
deliveredAt: event.deliveredAt,
externalAccount: event.externalAccount
? {
identifier: event.externalAccount.identifier,
}
: undefined,
};
}
query({ id, userId }: RunOptions) {
return this.#prismaClient.jobRun.findFirst({
select: {
@@ -110,9 +127,10 @@ export class RunPresenter {
},
event: {
select: {
id: true,
eventId: true,
name: true,
payload: true,
context: true,
timestamp: true,
deliveredAt: true,
externalAccount: {
@@ -17,9 +17,10 @@ export class TriggerDetailsPresenter {
select: {
event: {
select: {
id: true,
eventId: true,
name: true,
payload: true,
context: true,
timestamp: true,
deliveredAt: true,
externalAccount: {
@@ -32,6 +33,18 @@ export class TriggerDetailsPresenter {
},
});
return event;
return {
id: event.eventId,
name: event.name,
payload: JSON.stringify(event.payload),
context: JSON.stringify(event.context),
timestamp: event.timestamp,
deliveredAt: event.deliveredAt,
externalAccount: event.externalAccount
? {
identifier: event.externalAccount.identifier,
}
: undefined,
};
}
}
@@ -1,5 +1,3 @@
import { env } from "process";
import { Run } from "~/presenters/RunPresenter.server";
import {
FetchOperationSchema,
FetchRequestInit,