@agent-native/dispatch 0.17.3 → 0.17.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/create-workspace-resource.d.ts +13 -13
- package/dist/actions/delete-workspace-resource.d.ts +13 -13
- package/dist/actions/provider-api-register.d.ts +10 -10
- package/dist/client/transactional-emails.d.ts +57 -0
- package/dist/client/transactional-emails.d.ts.map +1 -0
- package/dist/client/transactional-emails.js +116 -0
- package/dist/client/transactional-emails.js.map +1 -0
- package/dist/components/layout/Layout.d.ts.map +1 -1
- package/dist/components/layout/Layout.js +8 -1
- package/dist/components/layout/Layout.js.map +1 -1
- package/dist/components/transactional-email-activity.d.ts +24 -0
- package/dist/components/transactional-email-activity.d.ts.map +1 -0
- package/dist/components/transactional-email-activity.js +31 -0
- package/dist/components/transactional-email-activity.js.map +1 -0
- package/dist/components/transactional-email-metrics.d.ts +40 -0
- package/dist/components/transactional-email-metrics.d.ts.map +1 -0
- package/dist/components/transactional-email-metrics.js +44 -0
- package/dist/components/transactional-email-metrics.js.map +1 -0
- package/dist/components/transactional-email-preview.d.ts +7 -0
- package/dist/components/transactional-email-preview.d.ts.map +1 -0
- package/dist/components/transactional-email-preview.js +41 -0
- package/dist/components/transactional-email-preview.js.map +1 -0
- package/dist/routes/index.d.ts.map +1 -1
- package/dist/routes/index.js +2 -0
- package/dist/routes/index.js.map +1 -1
- package/dist/routes/pages/transactional-email.$appId.$id.d.ts +5 -0
- package/dist/routes/pages/transactional-email.$appId.$id.d.ts.map +1 -0
- package/dist/routes/pages/transactional-email.$appId.$id.js +144 -0
- package/dist/routes/pages/transactional-email.$appId.$id.js.map +1 -0
- package/dist/routes/pages/transactional-email.d.ts +5 -0
- package/dist/routes/pages/transactional-email.d.ts.map +1 -0
- package/dist/routes/pages/transactional-email.js +139 -0
- package/dist/routes/pages/transactional-email.js.map +1 -0
- package/dist/server/lib/thread-debug-store.d.ts.map +1 -1
- package/dist/server/lib/thread-debug-store.js +2 -1
- package/dist/server/lib/thread-debug-store.js.map +1 -1
- package/package.json +2 -2
- package/src/client/transactional-emails.spec.ts +91 -0
- package/src/client/transactional-emails.ts +201 -0
- package/src/components/layout/Layout.tsx +8 -0
- package/src/components/transactional-email-activity.tsx +102 -0
- package/src/components/transactional-email-metrics.tsx +127 -0
- package/src/components/transactional-email-preview.tsx +88 -0
- package/src/routes/index.ts +5 -0
- package/src/routes/pages/transactional-email.$appId.$id.tsx +362 -0
- package/src/routes/pages/transactional-email.tsx +571 -0
- package/src/server/lib/thread-debug-store.spec.ts +7 -3
- package/src/server/lib/thread-debug-store.ts +2 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useActionQuery } from "@agent-native/core/client/hooks";
|
|
3
|
+
import { useT } from "@agent-native/core/client/i18n";
|
|
4
|
+
import { IconAlertTriangle, IconArrowLeft } from "@tabler/icons-react";
|
|
5
|
+
import { useQueries, useQuery } from "@tanstack/react-query";
|
|
6
|
+
import { useMemo } from "react";
|
|
7
|
+
import { Link, useParams } from "react-router";
|
|
8
|
+
import { aggregateSharedEmails, callAppAction, fetchAppEmailCatalog, } from "../../client/transactional-emails.js";
|
|
9
|
+
import { ActionQueryError } from "../../components/action-query-error.js";
|
|
10
|
+
import { DispatchShell } from "../../components/dispatch-shell.js";
|
|
11
|
+
import { ActivityTable, } from "../../components/transactional-email-activity.js";
|
|
12
|
+
import { OpenRateCell, SendsCell, LastSentCell, } from "../../components/transactional-email-metrics.js";
|
|
13
|
+
import { EmailPreviewPane } from "../../components/transactional-email-preview.js";
|
|
14
|
+
import { Alert, AlertDescription, AlertTitle } from "../../components/ui/alert.js";
|
|
15
|
+
import { Button } from "../../components/ui/button.js";
|
|
16
|
+
import { Skeleton } from "../../components/ui/skeleton.js";
|
|
17
|
+
export function meta() {
|
|
18
|
+
return [{ title: "Transactional email detail — Dispatch" }];
|
|
19
|
+
}
|
|
20
|
+
const WINDOW_DAYS = 30;
|
|
21
|
+
const ACTIVITY_LIMIT = 50;
|
|
22
|
+
/**
|
|
23
|
+
* Resolves the one email this page shows, plus the app name/path to display.
|
|
24
|
+
* The "core" appId is Dispatch's own registry, not a cross-app fetch — see
|
|
25
|
+
* the same split in transactional-email.tsx.
|
|
26
|
+
*/
|
|
27
|
+
function useEmailDetail(appId, id) {
|
|
28
|
+
const isCore = appId === "core";
|
|
29
|
+
const t = useT();
|
|
30
|
+
const localQuery = useActionQuery("list-transactional-emails", { windowDays: WINDOW_DAYS }, { enabled: isCore });
|
|
31
|
+
const appsQuery = useActionQuery("list-workspace-apps", {
|
|
32
|
+
includeAgentCards: false,
|
|
33
|
+
});
|
|
34
|
+
const readyApps = useMemo(() => (appsQuery.data ?? []).filter((candidate) => candidate.status !== "pending"), [appsQuery.data]);
|
|
35
|
+
const app = useMemo(() => readyApps.find((candidate) => candidate.id === appId), [readyApps, appId]);
|
|
36
|
+
const coreCatalogQueries = useQueries({
|
|
37
|
+
queries: readyApps.map((candidate) => ({
|
|
38
|
+
queryKey: ["transactional-email-catalog", candidate.id, WINDOW_DAYS],
|
|
39
|
+
queryFn: () => fetchAppEmailCatalog(candidate, WINDOW_DAYS),
|
|
40
|
+
enabled: isCore,
|
|
41
|
+
staleTime: Infinity,
|
|
42
|
+
})),
|
|
43
|
+
});
|
|
44
|
+
const remoteQuery = useQuery({
|
|
45
|
+
queryKey: ["transactional-email-catalog", appId, WINDOW_DAYS],
|
|
46
|
+
queryFn: () => fetchAppEmailCatalog(app, WINDOW_DAYS),
|
|
47
|
+
enabled: !isCore && !!app,
|
|
48
|
+
staleTime: Infinity,
|
|
49
|
+
});
|
|
50
|
+
if (isCore) {
|
|
51
|
+
const appCatalogs = coreCatalogQueries
|
|
52
|
+
.map((query) => query.data)
|
|
53
|
+
.filter((catalog) => Boolean(catalog));
|
|
54
|
+
const aggregate = localQuery.data
|
|
55
|
+
? aggregateSharedEmails(localQuery.data, appCatalogs)
|
|
56
|
+
: undefined;
|
|
57
|
+
const email = aggregate?.emails.find((candidate) => candidate.id === id);
|
|
58
|
+
const catalogError = coreCatalogQueries.find((query) => query.data?.error || query.data?.statsError)?.data;
|
|
59
|
+
const queryError = coreCatalogQueries.find((query) => query.isError)?.error;
|
|
60
|
+
const isLoading = localQuery.isLoading ||
|
|
61
|
+
appsQuery.isLoading ||
|
|
62
|
+
coreCatalogQueries.some((query) => query.isLoading);
|
|
63
|
+
const isError = localQuery.isError || appsQuery.isError || Boolean(queryError);
|
|
64
|
+
return {
|
|
65
|
+
isLoading,
|
|
66
|
+
isError,
|
|
67
|
+
error: localQuery.error ?? appsQuery.error ?? queryError,
|
|
68
|
+
onRetry: () => {
|
|
69
|
+
void localQuery.refetch();
|
|
70
|
+
void appsQuery.refetch();
|
|
71
|
+
for (const query of coreCatalogQueries)
|
|
72
|
+
void query.refetch();
|
|
73
|
+
},
|
|
74
|
+
appName: t("dispatch.transactionalEmail.sharedTitle"),
|
|
75
|
+
appPath: t("dispatch.transactionalEmail.sharedSubtitle"),
|
|
76
|
+
email,
|
|
77
|
+
catalogError: aggregate?.statsError ??
|
|
78
|
+
catalogError?.error ??
|
|
79
|
+
catalogError?.statsError ??
|
|
80
|
+
null,
|
|
81
|
+
notFound: !isLoading && !isError && !email,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const notFound = !appsQuery.isLoading &&
|
|
85
|
+
!appsQuery.isError &&
|
|
86
|
+
(!app ||
|
|
87
|
+
(!remoteQuery.isLoading &&
|
|
88
|
+
!remoteQuery.isError &&
|
|
89
|
+
!remoteQuery.data?.error &&
|
|
90
|
+
!remoteQuery.data?.emails.some((candidate) => candidate.id === id)));
|
|
91
|
+
return {
|
|
92
|
+
isLoading: appsQuery.isLoading || remoteQuery.isLoading,
|
|
93
|
+
isError: appsQuery.isError || remoteQuery.isError,
|
|
94
|
+
error: appsQuery.error ?? remoteQuery.error,
|
|
95
|
+
onRetry: () => {
|
|
96
|
+
void appsQuery.refetch();
|
|
97
|
+
void remoteQuery.refetch();
|
|
98
|
+
},
|
|
99
|
+
appName: app?.name ?? appId,
|
|
100
|
+
appPath: app?.path ?? "",
|
|
101
|
+
email: remoteQuery.data?.emails.find((candidate) => candidate.id === id),
|
|
102
|
+
catalogError: remoteQuery.data?.error ?? null,
|
|
103
|
+
notFound,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export default function TransactionalEmailDetailRoute() {
|
|
107
|
+
const t = useT();
|
|
108
|
+
const params = useParams();
|
|
109
|
+
const appId = params.appId ?? "";
|
|
110
|
+
const id = params.id ?? "";
|
|
111
|
+
const detail = useEmailDetail(appId, id);
|
|
112
|
+
const sharedProviderReason = t("dispatch.transactionalEmail.sharedProviderMetricsUnavailable");
|
|
113
|
+
const engagementQuery = useQuery({
|
|
114
|
+
queryKey: ["list-email-engagement", detail.appPath, id, WINDOW_DAYS],
|
|
115
|
+
queryFn: () => callAppAction(detail.appPath, "list-email-engagement", { templateIds: [id], windowDays: WINDOW_DAYS }, "POST"),
|
|
116
|
+
enabled: appId !== "core" && id.length > 0 && detail.appPath.length > 0,
|
|
117
|
+
});
|
|
118
|
+
const engagementResult = engagementQuery.data;
|
|
119
|
+
const engagementUnavailable = appId === "core"
|
|
120
|
+
? sharedProviderReason
|
|
121
|
+
: engagementResult && !engagementResult.available
|
|
122
|
+
? engagementResult.reason
|
|
123
|
+
: engagementQuery.isError
|
|
124
|
+
? engagementQuery.error instanceof Error
|
|
125
|
+
? engagementQuery.error.message
|
|
126
|
+
: String(engagementQuery.error)
|
|
127
|
+
: null;
|
|
128
|
+
const engagement = engagementResult?.available
|
|
129
|
+
? engagementResult.data.find((entry) => entry.templateId === id)
|
|
130
|
+
: undefined;
|
|
131
|
+
const activityQuery = useQuery({
|
|
132
|
+
queryKey: ["list-email-activity", detail.appPath, id, ACTIVITY_LIMIT],
|
|
133
|
+
queryFn: () => callAppAction(detail.appPath, "list-email-activity", { templateId: id, limit: ACTIVITY_LIMIT }, "GET"),
|
|
134
|
+
enabled: appId !== "core" &&
|
|
135
|
+
id.length > 0 &&
|
|
136
|
+
detail.appPath.length > 0 &&
|
|
137
|
+
!engagementUnavailable,
|
|
138
|
+
});
|
|
139
|
+
return (_jsx(DispatchShell, { title: detail.email?.name ?? t("dispatch.transactionalEmail.title"), description: t("dispatch.transactionalEmail.description"), children: _jsxs("div", { className: "max-w-3xl space-y-4", children: [_jsx(Button, { asChild: true, size: "sm", variant: "ghost", className: "-ml-2", children: _jsxs(Link, { to: "/transactional-email", children: [_jsx(IconArrowLeft, { size: 15, className: "mr-1.5" }), t("dispatch.transactionalEmail.title")] }) }), detail.isError ? (_jsx(ActionQueryError, { error: detail.error, onRetry: detail.onRetry })) : detail.isLoading ? (_jsxs("div", { className: "space-y-3", children: [_jsx(Skeleton, { className: "h-6 w-64" }), _jsx(Skeleton, { className: "h-32 w-full" })] })) : detail.notFound || !detail.email ? (_jsxs(Alert, { variant: "destructive", children: [_jsx(IconAlertTriangle, { className: "size-4" }), _jsx(AlertTitle, { children: t("dispatch.transactionalEmail.emailNotFound") }), _jsx(AlertDescription, { children: detail.catalogError ??
|
|
140
|
+
t("dispatch.transactionalEmail.emailNotFoundDescription") })] })) : (_jsxs(_Fragment, { children: [_jsxs("section", { className: "rounded-2xl bg-card p-5", children: [_jsx("div", { className: "text-lg font-semibold text-foreground", children: detail.email.name }), _jsx("div", { className: "mt-1 font-mono text-xs text-muted-foreground", children: detail.email.id }), _jsxs("div", { className: "mt-1 text-xs text-muted-foreground", children: [detail.appName, detail.appPath ? ` · ${detail.appPath}` : ""] }), _jsxs("dl", { className: "mt-4 space-y-3 text-sm", children: [_jsxs("div", { children: [_jsx("dt", { className: "text-xs font-medium text-muted-foreground", children: t("dispatch.transactionalEmail.trigger") }), _jsx("dd", { className: "mt-1 text-foreground", children: detail.email.trigger })] }), _jsxs("div", { children: [_jsx("dt", { className: "text-xs font-medium text-muted-foreground", children: t("dispatch.transactionalEmail.recipient") }), _jsx("dd", { className: "mt-1 text-foreground", children: detail.email.recipient })] }), _jsxs("div", { children: [_jsx("dt", { className: "text-xs font-medium text-muted-foreground", children: t("dispatch.transactionalEmail.sender") }), _jsx("dd", { className: "mt-1 text-foreground", children: detail.email.sender })] })] }), _jsxs("div", { className: "mt-4 flex flex-wrap gap-6 border-t pt-4 text-sm", children: [_jsxs("div", { children: [_jsx("div", { className: "text-xs font-medium text-muted-foreground", children: t("dispatch.transactionalEmail.sends") }), _jsx("div", { className: "mt-1", children: _jsx(SendsCell, { sent: detail.email.sent, failed: detail.email.failed }) })] }), _jsxs("div", { children: [_jsx("div", { className: "text-xs font-medium text-muted-foreground", children: t("dispatch.transactionalEmail.openRate") }), _jsx("div", { className: "mt-1", children: _jsx(OpenRateCell, { engagement: engagement, unavailableReason: engagementUnavailable, loading: engagementQuery.isLoading }) })] }), _jsxs("div", { children: [_jsx("div", { className: "text-xs font-medium text-muted-foreground", children: t("dispatch.transactionalEmail.lastSent") }), _jsx("div", { className: "mt-1", children: _jsx(LastSentCell, { lastSentAt: detail.email.lastSentAt, sent: detail.email.sent }) })] })] })] }), _jsxs("section", { className: "rounded-2xl bg-card p-5", children: [_jsx("h2", { className: "text-sm font-medium text-foreground", children: t("dispatch.transactionalEmail.preview") }), _jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: t("dispatch.transactionalEmail.previewDescription") }), _jsx("div", { className: "mt-4", children: _jsx(EmailPreviewPane, { appId: appId, appPath: detail.appPath, id: detail.email.id, name: detail.email.name }) })] }), _jsxs("section", { className: "rounded-2xl bg-card p-5", children: [_jsx("h2", { className: "text-sm font-medium text-foreground", children: t("dispatch.transactionalEmail.activityLink") }), _jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: t("dispatch.transactionalEmail.retentionNote") }), _jsx("div", { className: "mt-4", children: _jsx(ActivityTable, { result: engagementUnavailable
|
|
141
|
+
? { available: false, reason: engagementUnavailable }
|
|
142
|
+
: activityQuery.data, isLoading: activityQuery.isLoading, isError: activityQuery.isError, error: activityQuery.error, onRetry: () => void activityQuery.refetch() }) })] })] }))] }) }));
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=transactional-email.$appId.$id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactional-email.$appId.$id.js","sourceRoot":"","sources":["../../../src/routes/pages/transactional-email.$appId.$id.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAc,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,oBAAoB,GAIrB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EACL,aAAa,GAEd,MAAM,+CAA+C,CAAC;AACvD,OAAO,EACL,YAAY,EACZ,SAAS,EACT,YAAY,GAGb,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,EAAE,KAAK,EAAE,uCAAuC,EAAE,CAAC,CAAC;AAC9D,CA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ACnB,KAAC,YAAY,IACX,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU,EACnC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,GACvB,GACE,IACF,IACF,IACE,EAEV,mBAAS,SAAS,EAAC,yBAAyB,aAC1C,aAAI,SAAS,EAAC,qCAAqC,YAChD,CAAC,CAAC,qCAAqC,CAAC,GACtC,EACL,YAAG,SAAS,EAAC,oCAAoC,YAC9C,CAAC,CAAC,gDAAgD,CAAC,GAClD,EACJ,cAAK,SAAS,EAAC,MAAM,YACnB,KAAC,gBAAgB,IACf,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,MAAM,CAAC,OAAO,EACvB,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,EACnB,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,GACvB,GACE,IACE,EAEV,mBAAS,SAAS,EAAC,yBAAyB,aAC1C,aAAI,SAAS,EAAC,qCAAqC,YAChD,CAAC,CAAC,0CAA0C,CAAC,GAC3C,EACL,YAAG,SAAS,EAAC,oCAAoC,YAC9C,CAAC,CAAC,2CAA2C,CAAC,GAC7C,EACJ,cAAK,SAAS,EAAC,MAAM,YACnB,KAAC,aAAa,IACZ,MAAM,EACJ,qBAAqB;4CACnB,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,qBAAqB,EAAE;4CACrD,CAAC,CAAC,aAAa,CAAC,IAAI,EAExB,SAAS,EAAE,aAAa,CAAC,SAAS,EAClC,OAAO,EAAE,aAAa,CAAC,OAAO,EAC9B,KAAK,EAAE,aAAa,CAAC,KAAK,EAC1B,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,aAAa,CAAC,OAAO,EAAE,GAC3C,GACE,IACE,IACT,CACJ,IACG,GACQ,CACjB,CAAC;AACJ,CAAC","sourcesContent":["import { callAction, useActionQuery } from \"@agent-native/core/client/hooks\";\nimport { useT } from \"@agent-native/core/client/i18n\";\nimport { IconAlertTriangle, IconArrowLeft } from \"@tabler/icons-react\";\nimport { useQueries, useQuery } from \"@tanstack/react-query\";\nimport { useMemo } from \"react\";\nimport { Link, useParams } from \"react-router\";\n\nimport {\n aggregateSharedEmails,\n callAppAction,\n fetchAppEmailCatalog,\n type AppEmailCatalog,\n type AppTransactionalEmail,\n type LocalTransactionalEmailCatalog,\n} from \"../../client/transactional-emails\";\nimport { ActionQueryError } from \"../../components/action-query-error\";\nimport { DispatchShell } from \"../../components/dispatch-shell\";\nimport {\n ActivityTable,\n type EmailActivityEntry,\n} from \"../../components/transactional-email-activity\";\nimport {\n OpenRateCell,\n SendsCell,\n LastSentCell,\n type EmailEngagement,\n type ProviderMetricsResult,\n} from \"../../components/transactional-email-metrics\";\nimport { EmailPreviewPane } from \"../../components/transactional-email-preview\";\nimport { Alert, AlertDescription, AlertTitle } from \"../../components/ui/alert\";\nimport { Button } from \"../../components/ui/button\";\nimport { Skeleton } from \"../../components/ui/skeleton\";\n\nexport function meta() {\n return [{ title: \"Transactional email detail — Dispatch\" }];\n}\n\nconst WINDOW_DAYS = 30;\nconst ACTIVITY_LIMIT = 50;\n\ninterface WorkspaceAppRef {\n id: string;\n name: string;\n path: string;\n status?: \"ready\" | \"pending\";\n}\n\n/**\n * Resolves the one email this page shows, plus the app name/path to display.\n * The \"core\" appId is Dispatch's own registry, not a cross-app fetch — see\n * the same split in transactional-email.tsx.\n */\nfunction useEmailDetail(appId: string, id: string) {\n const isCore = appId === \"core\";\n const t = useT();\n\n const localQuery = useActionQuery<LocalTransactionalEmailCatalog>(\n \"list-transactional-emails\",\n { windowDays: WINDOW_DAYS },\n { enabled: isCore },\n );\n\n const appsQuery = useActionQuery<WorkspaceAppRef[]>(\"list-workspace-apps\", {\n includeAgentCards: false,\n });\n const readyApps = useMemo(\n () =>\n (appsQuery.data ?? []).filter(\n (candidate) => candidate.status !== \"pending\",\n ),\n [appsQuery.data],\n );\n const app = useMemo(\n () => readyApps.find((candidate) => candidate.id === appId),\n [readyApps, appId],\n );\n const coreCatalogQueries = useQueries({\n queries: readyApps.map((candidate) => ({\n queryKey: [\"transactional-email-catalog\", candidate.id, WINDOW_DAYS],\n queryFn: () => fetchAppEmailCatalog(candidate, WINDOW_DAYS),\n enabled: isCore,\n staleTime: Infinity,\n })),\n });\n const remoteQuery = useQuery({\n queryKey: [\"transactional-email-catalog\", appId, WINDOW_DAYS],\n queryFn: () => fetchAppEmailCatalog(app!, WINDOW_DAYS),\n enabled: !isCore && !!app,\n staleTime: Infinity,\n });\n\n if (isCore) {\n const appCatalogs = coreCatalogQueries\n .map((query) => query.data)\n .filter((catalog): catalog is AppEmailCatalog => Boolean(catalog));\n const aggregate = localQuery.data\n ? aggregateSharedEmails(localQuery.data, appCatalogs)\n : undefined;\n const email = aggregate?.emails.find((candidate) => candidate.id === id);\n const catalogError = coreCatalogQueries.find(\n (query) => query.data?.error || query.data?.statsError,\n )?.data;\n const queryError = coreCatalogQueries.find((query) => query.isError)?.error;\n const isLoading =\n localQuery.isLoading ||\n appsQuery.isLoading ||\n coreCatalogQueries.some((query) => query.isLoading);\n const isError =\n localQuery.isError || appsQuery.isError || Boolean(queryError);\n return {\n isLoading,\n isError,\n error: localQuery.error ?? appsQuery.error ?? queryError,\n onRetry: () => {\n void localQuery.refetch();\n void appsQuery.refetch();\n for (const query of coreCatalogQueries) void query.refetch();\n },\n appName: t(\"dispatch.transactionalEmail.sharedTitle\"),\n appPath: t(\"dispatch.transactionalEmail.sharedSubtitle\"),\n email,\n catalogError:\n aggregate?.statsError ??\n catalogError?.error ??\n catalogError?.statsError ??\n null,\n notFound: !isLoading && !isError && !email,\n };\n }\n\n const notFound =\n !appsQuery.isLoading &&\n !appsQuery.isError &&\n (!app ||\n (!remoteQuery.isLoading &&\n !remoteQuery.isError &&\n !remoteQuery.data?.error &&\n !remoteQuery.data?.emails.some((candidate) => candidate.id === id)));\n\n return {\n isLoading: appsQuery.isLoading || remoteQuery.isLoading,\n isError: appsQuery.isError || remoteQuery.isError,\n error: appsQuery.error ?? remoteQuery.error,\n onRetry: () => {\n void appsQuery.refetch();\n void remoteQuery.refetch();\n },\n appName: app?.name ?? appId,\n appPath: app?.path ?? \"\",\n email: remoteQuery.data?.emails.find((candidate) => candidate.id === id),\n catalogError: remoteQuery.data?.error ?? null,\n notFound,\n };\n}\n\nexport default function TransactionalEmailDetailRoute() {\n const t = useT();\n const params = useParams<{ appId: string; id: string }>();\n const appId = params.appId ?? \"\";\n const id = params.id ?? \"\";\n\n const detail = useEmailDetail(appId, id);\n\n const sharedProviderReason = t(\n \"dispatch.transactionalEmail.sharedProviderMetricsUnavailable\",\n );\n const engagementQuery = useQuery({\n queryKey: [\"list-email-engagement\", detail.appPath, id, WINDOW_DAYS],\n queryFn: () =>\n callAppAction<ProviderMetricsResult<EmailEngagement[]>>(\n detail.appPath,\n \"list-email-engagement\",\n { templateIds: [id], windowDays: WINDOW_DAYS },\n \"POST\",\n ),\n enabled: appId !== \"core\" && id.length > 0 && detail.appPath.length > 0,\n });\n const engagementResult = engagementQuery.data;\n const engagementUnavailable =\n appId === \"core\"\n ? sharedProviderReason\n : engagementResult && !engagementResult.available\n ? engagementResult.reason\n : engagementQuery.isError\n ? engagementQuery.error instanceof Error\n ? engagementQuery.error.message\n : String(engagementQuery.error)\n : null;\n const engagement = engagementResult?.available\n ? engagementResult.data.find((entry) => entry.templateId === id)\n : undefined;\n\n const activityQuery = useQuery({\n queryKey: [\"list-email-activity\", detail.appPath, id, ACTIVITY_LIMIT],\n queryFn: () =>\n callAppAction<ProviderMetricsResult<EmailActivityEntry[]>>(\n detail.appPath,\n \"list-email-activity\",\n { templateId: id, limit: ACTIVITY_LIMIT },\n \"GET\",\n ),\n enabled:\n appId !== \"core\" &&\n id.length > 0 &&\n detail.appPath.length > 0 &&\n !engagementUnavailable,\n });\n\n return (\n <DispatchShell\n title={detail.email?.name ?? t(\"dispatch.transactionalEmail.title\")}\n description={t(\"dispatch.transactionalEmail.description\")}\n >\n <div className=\"max-w-3xl space-y-4\">\n <Button asChild size=\"sm\" variant=\"ghost\" className=\"-ml-2\">\n <Link to=\"/transactional-email\">\n <IconArrowLeft size={15} className=\"mr-1.5\" />\n {t(\"dispatch.transactionalEmail.title\")}\n </Link>\n </Button>\n\n {detail.isError ? (\n <ActionQueryError error={detail.error} onRetry={detail.onRetry} />\n ) : detail.isLoading ? (\n <div className=\"space-y-3\">\n <Skeleton className=\"h-6 w-64\" />\n <Skeleton className=\"h-32 w-full\" />\n </div>\n ) : detail.notFound || !detail.email ? (\n <Alert variant=\"destructive\">\n <IconAlertTriangle className=\"size-4\" />\n <AlertTitle>\n {t(\"dispatch.transactionalEmail.emailNotFound\")}\n </AlertTitle>\n <AlertDescription>\n {detail.catalogError ??\n t(\"dispatch.transactionalEmail.emailNotFoundDescription\")}\n </AlertDescription>\n </Alert>\n ) : (\n <>\n <section className=\"rounded-2xl bg-card p-5\">\n <div className=\"text-lg font-semibold text-foreground\">\n {detail.email.name}\n </div>\n <div className=\"mt-1 font-mono text-xs text-muted-foreground\">\n {detail.email.id}\n </div>\n <div className=\"mt-1 text-xs text-muted-foreground\">\n {detail.appName}\n {detail.appPath ? ` · ${detail.appPath}` : \"\"}\n </div>\n\n <dl className=\"mt-4 space-y-3 text-sm\">\n <div>\n <dt className=\"text-xs font-medium text-muted-foreground\">\n {t(\"dispatch.transactionalEmail.trigger\")}\n </dt>\n <dd className=\"mt-1 text-foreground\">\n {detail.email.trigger}\n </dd>\n </div>\n <div>\n <dt className=\"text-xs font-medium text-muted-foreground\">\n {t(\"dispatch.transactionalEmail.recipient\")}\n </dt>\n <dd className=\"mt-1 text-foreground\">\n {detail.email.recipient}\n </dd>\n </div>\n <div>\n <dt className=\"text-xs font-medium text-muted-foreground\">\n {t(\"dispatch.transactionalEmail.sender\")}\n </dt>\n <dd className=\"mt-1 text-foreground\">\n {detail.email.sender}\n </dd>\n </div>\n </dl>\n\n <div className=\"mt-4 flex flex-wrap gap-6 border-t pt-4 text-sm\">\n <div>\n <div className=\"text-xs font-medium text-muted-foreground\">\n {t(\"dispatch.transactionalEmail.sends\")}\n </div>\n <div className=\"mt-1\">\n <SendsCell\n sent={detail.email.sent}\n failed={detail.email.failed}\n />\n </div>\n </div>\n <div>\n <div className=\"text-xs font-medium text-muted-foreground\">\n {t(\"dispatch.transactionalEmail.openRate\")}\n </div>\n <div className=\"mt-1\">\n <OpenRateCell\n engagement={engagement}\n unavailableReason={engagementUnavailable}\n loading={engagementQuery.isLoading}\n />\n </div>\n </div>\n <div>\n <div className=\"text-xs font-medium text-muted-foreground\">\n {t(\"dispatch.transactionalEmail.lastSent\")}\n </div>\n <div className=\"mt-1\">\n <LastSentCell\n lastSentAt={detail.email.lastSentAt}\n sent={detail.email.sent}\n />\n </div>\n </div>\n </div>\n </section>\n\n <section className=\"rounded-2xl bg-card p-5\">\n <h2 className=\"text-sm font-medium text-foreground\">\n {t(\"dispatch.transactionalEmail.preview\")}\n </h2>\n <p className=\"mt-1 text-xs text-muted-foreground\">\n {t(\"dispatch.transactionalEmail.previewDescription\")}\n </p>\n <div className=\"mt-4\">\n <EmailPreviewPane\n appId={appId}\n appPath={detail.appPath}\n id={detail.email.id}\n name={detail.email.name}\n />\n </div>\n </section>\n\n <section className=\"rounded-2xl bg-card p-5\">\n <h2 className=\"text-sm font-medium text-foreground\">\n {t(\"dispatch.transactionalEmail.activityLink\")}\n </h2>\n <p className=\"mt-1 text-xs text-muted-foreground\">\n {t(\"dispatch.transactionalEmail.retentionNote\")}\n </p>\n <div className=\"mt-4\">\n <ActivityTable\n result={\n engagementUnavailable\n ? { available: false, reason: engagementUnavailable }\n : activityQuery.data\n }\n isLoading={activityQuery.isLoading}\n isError={activityQuery.isError}\n error={activityQuery.error}\n onRetry={() => void activityQuery.refetch()}\n />\n </div>\n </section>\n </>\n )}\n </div>\n </DispatchShell>\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactional-email.d.ts","sourceRoot":"","sources":["../../../src/routes/pages/transactional-email.tsx"],"names":[],"mappings":"AA4DA,wBAAgB,IAAI;;IAEnB;AAyUD,MAAM,CAAC,OAAO,UAAU,uBAAuB,oDAmL9C"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useActionQuery } from "@agent-native/core/client/hooks";
|
|
3
|
+
import { useT } from "@agent-native/core/client/i18n";
|
|
4
|
+
import { IconAlertTriangle, IconChevronRight, IconEye, IconInfoCircle, IconList, IconMail, } from "@tabler/icons-react";
|
|
5
|
+
import { useQueries, useQuery } from "@tanstack/react-query";
|
|
6
|
+
import { useMemo, useState } from "react";
|
|
7
|
+
import { Link } from "react-router";
|
|
8
|
+
import { aggregateSharedEmails, callAppAction, fetchAppEmailCatalog, } from "../../client/transactional-emails.js";
|
|
9
|
+
import { ActionQueryError } from "../../components/action-query-error.js";
|
|
10
|
+
import { DispatchShell } from "../../components/dispatch-shell.js";
|
|
11
|
+
import { ActivityTable, } from "../../components/transactional-email-activity.js";
|
|
12
|
+
import { OpenRateCell, SendsCell, LastSentCell, } from "../../components/transactional-email-metrics.js";
|
|
13
|
+
import { EmailPreviewPane } from "../../components/transactional-email-preview.js";
|
|
14
|
+
import { Alert, AlertDescription, AlertTitle } from "../../components/ui/alert.js";
|
|
15
|
+
import { Button } from "../../components/ui/button.js";
|
|
16
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "../../components/ui/collapsible.js";
|
|
17
|
+
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "../../components/ui/dialog.js";
|
|
18
|
+
import { Skeleton } from "../../components/ui/skeleton.js";
|
|
19
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "../../components/ui/table.js";
|
|
20
|
+
export function meta() {
|
|
21
|
+
return [{ title: "Transactional email — Dispatch" }];
|
|
22
|
+
}
|
|
23
|
+
const WINDOW_DAYS = 30;
|
|
24
|
+
const ACTIVITY_LIMIT = 50;
|
|
25
|
+
/** Shape of the local `list-transactional-emails` action response. */
|
|
26
|
+
function PreviewDialog({ email, appId, appPath, open, onOpenChange, }) {
|
|
27
|
+
const t = useT();
|
|
28
|
+
return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { className: "max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: email.name }), _jsx(DialogDescription, { children: t("dispatch.transactionalEmail.previewDescription") })] }), _jsx(EmailPreviewPane, { appId: appId, appPath: appPath, id: email.id, name: email.name })] }) }));
|
|
29
|
+
}
|
|
30
|
+
function ActivityDialog({ email, appPath, unavailableReason, open, onOpenChange, }) {
|
|
31
|
+
const t = useT();
|
|
32
|
+
const activityQuery = useQuery({
|
|
33
|
+
queryKey: ["list-email-activity", appPath, email.id, ACTIVITY_LIMIT],
|
|
34
|
+
queryFn: () => callAppAction(appPath, "list-email-activity", { templateId: email.id, limit: ACTIVITY_LIMIT }, "GET"),
|
|
35
|
+
enabled: open && !unavailableReason,
|
|
36
|
+
});
|
|
37
|
+
return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { className: "max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: t("dispatch.transactionalEmail.activityTitle", {
|
|
38
|
+
name: email.name,
|
|
39
|
+
}) }), _jsx(DialogDescription, { children: t("dispatch.transactionalEmail.retentionNote") })] }), _jsx(ActivityTable, { result: unavailableReason
|
|
40
|
+
? { available: false, reason: unavailableReason }
|
|
41
|
+
: activityQuery.data, isLoading: activityQuery.isLoading, isError: activityQuery.isError, error: activityQuery.error, onRetry: () => void activityQuery.refetch() })] }) }));
|
|
42
|
+
}
|
|
43
|
+
function EmailRow({ email, appId, appPath, engagement, engagementUnavailable, engagementLoading, }) {
|
|
44
|
+
const t = useT();
|
|
45
|
+
const [previewOpen, setPreviewOpen] = useState(false);
|
|
46
|
+
const [activityOpen, setActivityOpen] = useState(false);
|
|
47
|
+
return (_jsxs(TableRow, { children: [_jsxs(TableCell, { className: "align-top", children: [_jsx(Link, { to: `/transactional-email/${appId}/${email.id}`, className: "text-sm font-medium text-foreground hover:underline", children: email.name }), _jsx("div", { className: "font-mono text-xs text-muted-foreground", children: email.id })] }), _jsx(TableCell, { className: "max-w-64 align-top text-xs text-muted-foreground", children: email.trigger }), _jsx(TableCell, { className: "max-w-56 align-top text-xs text-muted-foreground", children: email.recipientLabel }), _jsx(TableCell, { className: "max-w-56 align-top text-xs text-muted-foreground", children: email.senderLabel }), _jsx(TableCell, { className: "align-top text-sm", children: _jsx(SendsCell, { sent: email.sent, failed: email.failed }) }), _jsx(TableCell, { className: "align-top text-sm", children: _jsx(OpenRateCell, { engagement: engagement, unavailableReason: engagementUnavailable, loading: engagementLoading }) }), _jsx(TableCell, { className: "align-top text-xs text-muted-foreground", children: _jsx(LastSentCell, { lastSentAt: email.lastSentAt, sent: email.sent }) }), _jsxs(TableCell, { className: "align-top", children: [_jsxs("div", { className: "flex justify-end gap-2", children: [_jsxs(Button, { variant: "outline", size: "sm", onClick: () => setPreviewOpen(true), children: [_jsx(IconEye, { className: "size-4" }), t("dispatch.transactionalEmail.preview")] }), _jsxs(Button, { variant: "ghost", size: "sm", onClick: () => setActivityOpen(true), children: [_jsx(IconList, { className: "size-4" }), t("dispatch.transactionalEmail.activityLink")] })] }), _jsx(PreviewDialog, { email: email, appId: appId, appPath: appPath, open: previewOpen, onOpenChange: setPreviewOpen }), _jsx(ActivityDialog, { email: email, appPath: appPath, unavailableReason: engagementUnavailable, open: activityOpen, onOpenChange: setActivityOpen })] })] }));
|
|
48
|
+
}
|
|
49
|
+
function AppEmailTable({ catalog, engagementByTemplate, engagementUnavailable, engagementLoading, }) {
|
|
50
|
+
const t = useT();
|
|
51
|
+
if (catalog.error) {
|
|
52
|
+
return (_jsxs(Alert, { variant: "destructive", children: [_jsx(IconAlertTriangle, { className: "size-4" }), _jsx(AlertTitle, { children: t("dispatch.transactionalEmail.catalogUnreadable") }), _jsx(AlertDescription, { children: catalog.error })] }));
|
|
53
|
+
}
|
|
54
|
+
return (_jsxs(_Fragment, { children: [catalog.statsError ? (_jsxs(Alert, { className: "mb-4", children: [_jsx(IconInfoCircle, { className: "size-4" }), _jsx(AlertTitle, { children: t("dispatch.transactionalEmail.countsUnreadable") }), _jsx(AlertDescription, { children: catalog.statsError })] })) : null, catalog.emails.length === 0 ? (_jsx("div", { className: "rounded-xl border border-dashed px-4 py-6 text-sm text-muted-foreground", children: t("dispatch.transactionalEmail.appSendsNoEmail") })) : (_jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: t("dispatch.transactionalEmail.email") }), _jsx(TableHead, { children: t("dispatch.transactionalEmail.trigger") }), _jsx(TableHead, { children: t("dispatch.transactionalEmail.recipient") }), _jsx(TableHead, { children: t("dispatch.transactionalEmail.sender") }), _jsx(TableHead, { children: t("dispatch.transactionalEmail.sends") }), _jsx(TableHead, { children: t("dispatch.transactionalEmail.openRate") }), _jsx(TableHead, { children: t("dispatch.transactionalEmail.lastSent") }), _jsx(TableHead, {})] }) }), _jsx(TableBody, { children: catalog.emails.map((email) => (_jsx(EmailRow, { email: email, appId: catalog.appId, appPath: catalog.appPath, engagement: engagementByTemplate.get(email.id), engagementUnavailable: engagementUnavailable, engagementLoading: engagementLoading }, email.id))) })] }))] }));
|
|
55
|
+
}
|
|
56
|
+
function AppEmailCard({ name, path, open, onOpenChange, catalog, isLoading, isError, error, onRetry, engagementByTemplate, engagementUnavailable, engagementLoading, }) {
|
|
57
|
+
return (_jsxs(Collapsible, { open: open, onOpenChange: onOpenChange, className: "rounded-2xl bg-card", children: [_jsxs(CollapsibleTrigger, { className: "group flex w-full cursor-pointer items-center justify-between gap-3 p-5 text-left hover:bg-muted/20", children: [_jsxs("span", { className: "flex items-center gap-2", children: [_jsx(IconChevronRight, { className: "h-4 w-4 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-90" }), _jsx("span", { className: "text-sm font-medium text-foreground", children: name })] }), _jsx("span", { className: "font-mono text-xs text-muted-foreground", children: path })] }), _jsx(CollapsibleContent, { className: "border-t px-5 pb-5 pt-4", children: isError ? (_jsx(ActionQueryError, { error: error, onRetry: onRetry })) : isLoading || !catalog ? (_jsx(Skeleton, { className: "h-24 w-full" })) : (_jsx(AppEmailTable, { catalog: catalog, engagementByTemplate: engagementByTemplate, engagementUnavailable: engagementUnavailable, engagementLoading: engagementLoading })) })] }));
|
|
58
|
+
}
|
|
59
|
+
export default function TransactionalEmailRoute() {
|
|
60
|
+
const t = useT();
|
|
61
|
+
const appsQuery = useActionQuery("list-workspace-apps", {
|
|
62
|
+
includeAgentCards: false,
|
|
63
|
+
});
|
|
64
|
+
const apps = useMemo(() => (appsQuery.data ?? [])
|
|
65
|
+
.filter((app) => app.status !== "pending")
|
|
66
|
+
.map((app) => ({ id: app.id, name: app.name, path: app.path })), [appsQuery.data]);
|
|
67
|
+
const [expanded, setExpanded] = useState({});
|
|
68
|
+
const [sharedOpen, setSharedOpen] = useState(true);
|
|
69
|
+
const sharedQuery = useActionQuery("list-transactional-emails", { windowDays: WINDOW_DAYS });
|
|
70
|
+
const catalogQueries = useQueries({
|
|
71
|
+
queries: apps.map((app) => ({
|
|
72
|
+
queryKey: ["transactional-email-catalog", app.id, WINDOW_DAYS],
|
|
73
|
+
queryFn: () => fetchAppEmailCatalog(app, WINDOW_DAYS),
|
|
74
|
+
enabled: sharedOpen || expanded[app.id] === true,
|
|
75
|
+
staleTime: Infinity,
|
|
76
|
+
})),
|
|
77
|
+
});
|
|
78
|
+
const sharedCatalog = useMemo(() => {
|
|
79
|
+
if (!sharedQuery.data)
|
|
80
|
+
return undefined;
|
|
81
|
+
const aggregate = aggregateSharedEmails(sharedQuery.data, catalogQueries
|
|
82
|
+
.map((query) => query.data)
|
|
83
|
+
.filter((catalog) => Boolean(catalog)));
|
|
84
|
+
return {
|
|
85
|
+
appId: "core",
|
|
86
|
+
appName: t("dispatch.transactionalEmail.sharedTitle"),
|
|
87
|
+
appPath: t("dispatch.transactionalEmail.sharedSubtitle"),
|
|
88
|
+
emails: aggregate.emails,
|
|
89
|
+
error: null,
|
|
90
|
+
statsError: aggregate.statsError,
|
|
91
|
+
};
|
|
92
|
+
}, [sharedQuery.data, catalogQueries, t]);
|
|
93
|
+
const engagementQueries = useQueries({
|
|
94
|
+
queries: apps.map((app, index) => {
|
|
95
|
+
const catalog = catalogQueries[index]?.data;
|
|
96
|
+
const templateIds = catalog && !catalog.error
|
|
97
|
+
? catalog.emails.map((email) => email.id)
|
|
98
|
+
: [];
|
|
99
|
+
return {
|
|
100
|
+
queryKey: [
|
|
101
|
+
"list-email-engagement",
|
|
102
|
+
app.id,
|
|
103
|
+
templateIds.join(","),
|
|
104
|
+
WINDOW_DAYS,
|
|
105
|
+
],
|
|
106
|
+
queryFn: () => callAppAction(app.path, "list-email-engagement", { templateIds, windowDays: WINDOW_DAYS }, "POST"),
|
|
107
|
+
enabled: expanded[app.id] === true && templateIds.length > 0,
|
|
108
|
+
};
|
|
109
|
+
}),
|
|
110
|
+
});
|
|
111
|
+
const sharedLoading = sharedQuery.isLoading ||
|
|
112
|
+
(sharedOpen && catalogQueries.some((query) => query.isLoading));
|
|
113
|
+
const sharedError = catalogQueries.find((query) => query.isError)?.error;
|
|
114
|
+
const sharedProviderReason = t("dispatch.transactionalEmail.sharedProviderMetricsUnavailable");
|
|
115
|
+
return (_jsx(DispatchShell, { title: t("dispatch.transactionalEmail.title"), description: t("dispatch.transactionalEmail.description"), children: _jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs(Alert, { children: [_jsx(IconInfoCircle, { className: "size-4" }), _jsx(AlertTitle, { children: t("dispatch.transactionalEmail.retentionTitle") }), _jsx(AlertDescription, { children: t("dispatch.transactionalEmail.retentionNote") })] }), appsQuery.isError ? (_jsx(ActionQueryError, { error: appsQuery.error, onRetry: () => void appsQuery.refetch() })) : null, appsQuery.isLoading ? (_jsxs("div", { className: "space-y-3", children: [_jsx(Skeleton, { className: "h-16 w-full rounded-2xl" }), _jsx(Skeleton, { className: "h-16 w-full rounded-2xl" })] })) : null, !appsQuery.isLoading && apps.length === 0 ? (_jsxs("div", { className: "rounded-2xl border border-dashed px-6 py-12 text-center text-sm text-muted-foreground", children: [_jsx(IconMail, { className: "mx-auto mb-2 size-5" }), t("dispatch.transactionalEmail.noApps")] })) : null, _jsx(AppEmailCard, { name: t("dispatch.transactionalEmail.sharedTitle"), path: t("dispatch.transactionalEmail.sharedSubtitle"), open: sharedOpen, onOpenChange: setSharedOpen, catalog: sharedCatalog, isLoading: sharedLoading, isError: sharedQuery.isError || Boolean(sharedError), error: sharedQuery.error ?? sharedError, onRetry: () => {
|
|
116
|
+
void sharedQuery.refetch();
|
|
117
|
+
for (const query of catalogQueries)
|
|
118
|
+
void query.refetch();
|
|
119
|
+
}, engagementByTemplate: new Map(), engagementUnavailable: sharedProviderReason, engagementLoading: false }), apps.map((app, index) => {
|
|
120
|
+
const query = catalogQueries[index];
|
|
121
|
+
const engagementQuery = engagementQueries[index];
|
|
122
|
+
const engagementResult = engagementQuery?.data;
|
|
123
|
+
const engagementUnavailable = engagementResult && !engagementResult.available
|
|
124
|
+
? engagementResult.reason
|
|
125
|
+
: engagementQuery?.isError
|
|
126
|
+
? engagementQuery.error instanceof Error
|
|
127
|
+
? engagementQuery.error.message
|
|
128
|
+
: String(engagementQuery.error)
|
|
129
|
+
: null;
|
|
130
|
+
const engagementByTemplate = new Map();
|
|
131
|
+
if (engagementResult?.available) {
|
|
132
|
+
for (const entry of engagementResult.data) {
|
|
133
|
+
engagementByTemplate.set(entry.templateId, entry);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return (_jsx(AppEmailCard, { name: app.name, path: app.path, open: expanded[app.id] === true, onOpenChange: (next) => setExpanded((current) => ({ ...current, [app.id]: next })), catalog: query?.data, isLoading: query?.isLoading ?? false, isError: query?.isError ?? false, error: query?.error, onRetry: () => void query?.refetch(), engagementByTemplate: engagementByTemplate, engagementUnavailable: engagementUnavailable, engagementLoading: engagementQuery?.isLoading ?? false }, app.id));
|
|
137
|
+
})] }) }));
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=transactional-email.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactional-email.js","sourceRoot":"","sources":["../../../src/routes/pages/transactional-email.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAc,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AACtD,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,OAAO,EACP,cAAc,EACd,QAAQ,EACR,QAAQ,GACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,oBAAoB,GAIrB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EACL,aAAa,GAEd,MAAM,+CAA+C,CAAC;AACvD,OAAO,EACL,YAAY,EACZ,SAAS,EACT,YAAY,GAGb,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,iCAAiC,CAAC;AACzC,O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I,EAAE,CAAC;4BAC1C,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;wBACpD,CAAC;oBACH,CAAC;oBACD,OAAO,CACL,KAAC,YAAY,IAEX,IAAI,EAAE,GAAG,CAAC,IAAI,EACd,IAAI,EAAE,GAAG,CAAC,IAAI,EACd,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,IAAI,EAC/B,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CACrB,WAAW,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAE5D,OAAO,EAAE,KAAK,EAAE,IAAI,EACpB,SAAS,EAAE,KAAK,EAAE,SAAS,IAAI,KAAK,EACpC,OAAO,EAAE,KAAK,EAAE,OAAO,IAAI,KAAK,EAChC,KAAK,EAAE,KAAK,EAAE,KAAK,EACnB,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,KAAK,EAAE,OAAO,EAAE,EACpC,oBAAoB,EAAE,oBAAoB,EAC1C,qBAAqB,EAAE,qBAAqB,EAC5C,iBAAiB,EAAE,eAAe,EAAE,SAAS,IAAI,KAAK,IAdjD,GAAG,CAAC,EAAE,CAeX,CACH,CAAC;gBACJ,CAAC,CAAC,IACE,GACQ,CACjB,CAAC;AACJ,CAAC","sourcesContent":["import { callAction, useActionQuery } from \"@agent-native/core/client/hooks\";\nimport { useT } from \"@agent-native/core/client/i18n\";\nimport {\n IconAlertTriangle,\n IconChevronRight,\n IconEye,\n IconInfoCircle,\n IconList,\n IconMail,\n} from \"@tabler/icons-react\";\nimport { useQueries, useQuery } from \"@tanstack/react-query\";\nimport { useMemo, useState } from \"react\";\nimport { Link } from \"react-router\";\n\nimport {\n aggregateSharedEmails,\n callAppAction,\n fetchAppEmailCatalog,\n type AppEmailCatalog,\n type AppTransactionalEmail,\n type LocalTransactionalEmailCatalog,\n} from \"../../client/transactional-emails\";\nimport { ActionQueryError } from \"../../components/action-query-error\";\nimport { DispatchShell } from \"../../components/dispatch-shell\";\nimport {\n ActivityTable,\n type EmailActivityEntry,\n} from \"../../components/transactional-email-activity\";\nimport {\n OpenRateCell,\n SendsCell,\n LastSentCell,\n type EmailEngagement,\n type ProviderMetricsResult,\n} from \"../../components/transactional-email-metrics\";\nimport { EmailPreviewPane } from \"../../components/transactional-email-preview\";\nimport { Alert, AlertDescription, AlertTitle } from \"../../components/ui/alert\";\nimport { Button } from \"../../components/ui/button\";\nimport {\n Collapsible,\n CollapsibleContent,\n CollapsibleTrigger,\n} from \"../../components/ui/collapsible\";\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n} from \"../../components/ui/dialog\";\nimport { Skeleton } from \"../../components/ui/skeleton\";\nimport {\n Table,\n TableBody,\n TableCell,\n TableHead,\n TableHeader,\n TableRow,\n} from \"../../components/ui/table\";\n\nexport function meta() {\n return [{ title: \"Transactional email — Dispatch\" }];\n}\n\nconst WINDOW_DAYS = 30;\nconst ACTIVITY_LIMIT = 50;\n\ninterface WorkspaceAppRef {\n id: string;\n name: string;\n path: string;\n status?: \"ready\" | \"pending\";\n}\n\n/** Shape of the local `list-transactional-emails` action response. */\nfunction PreviewDialog({\n email,\n appId,\n appPath,\n open,\n onOpenChange,\n}: {\n email: AppTransactionalEmail;\n appId: string;\n appPath: string;\n open: boolean;\n onOpenChange: (next: boolean) => void;\n}) {\n const t = useT();\n return (\n <Dialog open={open} onOpenChange={onOpenChange}>\n <DialogContent className=\"max-w-3xl\">\n <DialogHeader>\n <DialogTitle>{email.name}</DialogTitle>\n <DialogDescription>\n {t(\"dispatch.transactionalEmail.previewDescription\")}\n </DialogDescription>\n </DialogHeader>\n {/* Dialog content only mounts while open, so this fetches on open and\n drops the request when closed rather than needing an enabled flag. */}\n <EmailPreviewPane\n appId={appId}\n appPath={appPath}\n id={email.id}\n name={email.name}\n />\n </DialogContent>\n </Dialog>\n );\n}\n\nfunction ActivityDialog({\n email,\n appPath,\n unavailableReason,\n open,\n onOpenChange,\n}: {\n email: AppTransactionalEmail;\n appPath: string;\n unavailableReason: string | null;\n open: boolean;\n onOpenChange: (next: boolean) => void;\n}) {\n const t = useT();\n const activityQuery = useQuery({\n queryKey: [\"list-email-activity\", appPath, email.id, ACTIVITY_LIMIT],\n queryFn: () =>\n callAppAction<ProviderMetricsResult<EmailActivityEntry[]>>(\n appPath,\n \"list-email-activity\",\n { templateId: email.id, limit: ACTIVITY_LIMIT },\n \"GET\",\n ),\n enabled: open && !unavailableReason,\n });\n\n return (\n <Dialog open={open} onOpenChange={onOpenChange}>\n <DialogContent className=\"max-w-4xl\">\n <DialogHeader>\n <DialogTitle>\n {t(\"dispatch.transactionalEmail.activityTitle\", {\n name: email.name,\n })}\n </DialogTitle>\n <DialogDescription>\n {t(\"dispatch.transactionalEmail.retentionNote\")}\n </DialogDescription>\n </DialogHeader>\n <ActivityTable\n result={\n unavailableReason\n ? { available: false, reason: unavailableReason }\n : activityQuery.data\n }\n isLoading={activityQuery.isLoading}\n isError={activityQuery.isError}\n error={activityQuery.error}\n onRetry={() => void activityQuery.refetch()}\n />\n </DialogContent>\n </Dialog>\n );\n}\n\nfunction EmailRow({\n email,\n appId,\n appPath,\n engagement,\n engagementUnavailable,\n engagementLoading,\n}: {\n email: AppTransactionalEmail;\n appId: string;\n appPath: string;\n engagement: EmailEngagement | undefined;\n engagementUnavailable: string | null;\n engagementLoading: boolean;\n}) {\n const t = useT();\n const [previewOpen, setPreviewOpen] = useState(false);\n const [activityOpen, setActivityOpen] = useState(false);\n\n return (\n <TableRow>\n <TableCell className=\"align-top\">\n <Link\n to={`/transactional-email/${appId}/${email.id}`}\n className=\"text-sm font-medium text-foreground hover:underline\"\n >\n {email.name}\n </Link>\n <div className=\"font-mono text-xs text-muted-foreground\">\n {email.id}\n </div>\n </TableCell>\n <TableCell className=\"max-w-64 align-top text-xs text-muted-foreground\">\n {email.trigger}\n </TableCell>\n <TableCell className=\"max-w-56 align-top text-xs text-muted-foreground\">\n {email.recipientLabel}\n </TableCell>\n <TableCell className=\"max-w-56 align-top text-xs text-muted-foreground\">\n {email.senderLabel}\n </TableCell>\n <TableCell className=\"align-top text-sm\">\n <SendsCell sent={email.sent} failed={email.failed} />\n </TableCell>\n <TableCell className=\"align-top text-sm\">\n <OpenRateCell\n engagement={engagement}\n unavailableReason={engagementUnavailable}\n loading={engagementLoading}\n />\n </TableCell>\n <TableCell className=\"align-top text-xs text-muted-foreground\">\n <LastSentCell lastSentAt={email.lastSentAt} sent={email.sent} />\n </TableCell>\n <TableCell className=\"align-top\">\n <div className=\"flex justify-end gap-2\">\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={() => setPreviewOpen(true)}\n >\n <IconEye className=\"size-4\" />\n {t(\"dispatch.transactionalEmail.preview\")}\n </Button>\n <Button\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => setActivityOpen(true)}\n >\n <IconList className=\"size-4\" />\n {t(\"dispatch.transactionalEmail.activityLink\")}\n </Button>\n </div>\n <PreviewDialog\n email={email}\n appId={appId}\n appPath={appPath}\n open={previewOpen}\n onOpenChange={setPreviewOpen}\n />\n <ActivityDialog\n email={email}\n appPath={appPath}\n unavailableReason={engagementUnavailable}\n open={activityOpen}\n onOpenChange={setActivityOpen}\n />\n </TableCell>\n </TableRow>\n );\n}\n\nfunction AppEmailTable({\n catalog,\n engagementByTemplate,\n engagementUnavailable,\n engagementLoading,\n}: {\n catalog: AppEmailCatalog;\n engagementByTemplate: Map<string, EmailEngagement>;\n engagementUnavailable: string | null;\n engagementLoading: boolean;\n}) {\n const t = useT();\n\n if (catalog.error) {\n return (\n <Alert variant=\"destructive\">\n <IconAlertTriangle className=\"size-4\" />\n <AlertTitle>\n {t(\"dispatch.transactionalEmail.catalogUnreadable\")}\n </AlertTitle>\n <AlertDescription>{catalog.error}</AlertDescription>\n </Alert>\n );\n }\n\n return (\n <>\n {catalog.statsError ? (\n <Alert className=\"mb-4\">\n <IconInfoCircle className=\"size-4\" />\n <AlertTitle>\n {t(\"dispatch.transactionalEmail.countsUnreadable\")}\n </AlertTitle>\n <AlertDescription>{catalog.statsError}</AlertDescription>\n </Alert>\n ) : null}\n {catalog.emails.length === 0 ? (\n <div className=\"rounded-xl border border-dashed px-4 py-6 text-sm text-muted-foreground\">\n {t(\"dispatch.transactionalEmail.appSendsNoEmail\")}\n </div>\n ) : (\n <Table>\n <TableHeader>\n <TableRow>\n <TableHead>{t(\"dispatch.transactionalEmail.email\")}</TableHead>\n <TableHead>{t(\"dispatch.transactionalEmail.trigger\")}</TableHead>\n <TableHead>\n {t(\"dispatch.transactionalEmail.recipient\")}\n </TableHead>\n <TableHead>{t(\"dispatch.transactionalEmail.sender\")}</TableHead>\n <TableHead>{t(\"dispatch.transactionalEmail.sends\")}</TableHead>\n <TableHead>{t(\"dispatch.transactionalEmail.openRate\")}</TableHead>\n <TableHead>{t(\"dispatch.transactionalEmail.lastSent\")}</TableHead>\n <TableHead />\n </TableRow>\n </TableHeader>\n <TableBody>\n {catalog.emails.map((email) => (\n <EmailRow\n key={email.id}\n email={email}\n appId={catalog.appId}\n appPath={catalog.appPath}\n engagement={engagementByTemplate.get(email.id)}\n engagementUnavailable={engagementUnavailable}\n engagementLoading={engagementLoading}\n />\n ))}\n </TableBody>\n </Table>\n )}\n </>\n );\n}\n\nfunction AppEmailCard({\n name,\n path,\n open,\n onOpenChange,\n catalog,\n isLoading,\n isError,\n error,\n onRetry,\n engagementByTemplate,\n engagementUnavailable,\n engagementLoading,\n}: {\n name: string;\n path: string;\n open: boolean;\n onOpenChange: (next: boolean) => void;\n catalog: AppEmailCatalog | undefined;\n isLoading: boolean;\n isError: boolean;\n error: unknown;\n onRetry: () => void;\n engagementByTemplate: Map<string, EmailEngagement>;\n engagementUnavailable: string | null;\n engagementLoading: boolean;\n}) {\n return (\n <Collapsible\n open={open}\n onOpenChange={onOpenChange}\n className=\"rounded-2xl bg-card\"\n >\n <CollapsibleTrigger className=\"group flex w-full cursor-pointer items-center justify-between gap-3 p-5 text-left hover:bg-muted/20\">\n <span className=\"flex items-center gap-2\">\n <IconChevronRight className=\"h-4 w-4 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-90\" />\n <span className=\"text-sm font-medium text-foreground\">{name}</span>\n </span>\n <span className=\"font-mono text-xs text-muted-foreground\">{path}</span>\n </CollapsibleTrigger>\n <CollapsibleContent className=\"border-t px-5 pb-5 pt-4\">\n {isError ? (\n <ActionQueryError error={error} onRetry={onRetry} />\n ) : isLoading || !catalog ? (\n <Skeleton className=\"h-24 w-full\" />\n ) : (\n <AppEmailTable\n catalog={catalog}\n engagementByTemplate={engagementByTemplate}\n engagementUnavailable={engagementUnavailable}\n engagementLoading={engagementLoading}\n />\n )}\n </CollapsibleContent>\n </Collapsible>\n );\n}\n\nexport default function TransactionalEmailRoute() {\n const t = useT();\n const appsQuery = useActionQuery<WorkspaceAppRef[]>(\"list-workspace-apps\", {\n includeAgentCards: false,\n });\n\n const apps = useMemo(\n () =>\n (appsQuery.data ?? [])\n .filter((app) => app.status !== \"pending\")\n .map((app) => ({ id: app.id, name: app.name, path: app.path })),\n [appsQuery.data],\n );\n\n const [expanded, setExpanded] = useState<Record<string, boolean>>({});\n const [sharedOpen, setSharedOpen] = useState(true);\n\n const sharedQuery = useActionQuery<LocalTransactionalEmailCatalog>(\n \"list-transactional-emails\",\n { windowDays: WINDOW_DAYS },\n );\n\n const catalogQueries = useQueries({\n queries: apps.map((app) => ({\n queryKey: [\"transactional-email-catalog\", app.id, WINDOW_DAYS],\n queryFn: () => fetchAppEmailCatalog(app, WINDOW_DAYS),\n enabled: sharedOpen || expanded[app.id] === true,\n staleTime: Infinity,\n })),\n });\n\n const sharedCatalog = useMemo<AppEmailCatalog | undefined>(() => {\n if (!sharedQuery.data) return undefined;\n const aggregate = aggregateSharedEmails(\n sharedQuery.data,\n catalogQueries\n .map((query) => query.data)\n .filter((catalog): catalog is AppEmailCatalog => Boolean(catalog)),\n );\n return {\n appId: \"core\",\n appName: t(\"dispatch.transactionalEmail.sharedTitle\"),\n appPath: t(\"dispatch.transactionalEmail.sharedSubtitle\"),\n emails: aggregate.emails,\n error: null,\n statsError: aggregate.statsError,\n };\n }, [sharedQuery.data, catalogQueries, t]);\n\n const engagementQueries = useQueries({\n queries: apps.map((app, index) => {\n const catalog = catalogQueries[index]?.data;\n const templateIds =\n catalog && !catalog.error\n ? catalog.emails.map((email) => email.id)\n : [];\n return {\n queryKey: [\n \"list-email-engagement\",\n app.id,\n templateIds.join(\",\"),\n WINDOW_DAYS,\n ],\n queryFn: () =>\n callAppAction<ProviderMetricsResult<EmailEngagement[]>>(\n app.path,\n \"list-email-engagement\",\n { templateIds, windowDays: WINDOW_DAYS },\n \"POST\",\n ),\n enabled: expanded[app.id] === true && templateIds.length > 0,\n };\n }),\n });\n\n const sharedLoading =\n sharedQuery.isLoading ||\n (sharedOpen && catalogQueries.some((query) => query.isLoading));\n const sharedError = catalogQueries.find((query) => query.isError)?.error;\n const sharedProviderReason = t(\n \"dispatch.transactionalEmail.sharedProviderMetricsUnavailable\",\n );\n\n return (\n <DispatchShell\n title={t(\"dispatch.transactionalEmail.title\")}\n description={t(\"dispatch.transactionalEmail.description\")}\n >\n <div className=\"flex flex-col gap-4\">\n <Alert>\n <IconInfoCircle className=\"size-4\" />\n <AlertTitle>\n {t(\"dispatch.transactionalEmail.retentionTitle\")}\n </AlertTitle>\n <AlertDescription>\n {t(\"dispatch.transactionalEmail.retentionNote\")}\n </AlertDescription>\n </Alert>\n\n {appsQuery.isError ? (\n <ActionQueryError\n error={appsQuery.error}\n onRetry={() => void appsQuery.refetch()}\n />\n ) : null}\n\n {appsQuery.isLoading ? (\n <div className=\"space-y-3\">\n <Skeleton className=\"h-16 w-full rounded-2xl\" />\n <Skeleton className=\"h-16 w-full rounded-2xl\" />\n </div>\n ) : null}\n\n {!appsQuery.isLoading && apps.length === 0 ? (\n <div className=\"rounded-2xl border border-dashed px-6 py-12 text-center text-sm text-muted-foreground\">\n <IconMail className=\"mx-auto mb-2 size-5\" />\n {t(\"dispatch.transactionalEmail.noApps\")}\n </div>\n ) : null}\n\n <AppEmailCard\n name={t(\"dispatch.transactionalEmail.sharedTitle\")}\n path={t(\"dispatch.transactionalEmail.sharedSubtitle\")}\n open={sharedOpen}\n onOpenChange={setSharedOpen}\n catalog={sharedCatalog}\n isLoading={sharedLoading}\n isError={sharedQuery.isError || Boolean(sharedError)}\n error={sharedQuery.error ?? sharedError}\n onRetry={() => {\n void sharedQuery.refetch();\n for (const query of catalogQueries) void query.refetch();\n }}\n engagementByTemplate={new Map()}\n engagementUnavailable={sharedProviderReason}\n engagementLoading={false}\n />\n\n {apps.map((app, index) => {\n const query = catalogQueries[index];\n const engagementQuery = engagementQueries[index];\n const engagementResult = engagementQuery?.data;\n const engagementUnavailable =\n engagementResult && !engagementResult.available\n ? engagementResult.reason\n : engagementQuery?.isError\n ? engagementQuery.error instanceof Error\n ? engagementQuery.error.message\n : String(engagementQuery.error)\n : null;\n const engagementByTemplate = new Map<string, EmailEngagement>();\n if (engagementResult?.available) {\n for (const entry of engagementResult.data) {\n engagementByTemplate.set(entry.templateId, entry);\n }\n }\n return (\n <AppEmailCard\n key={app.id}\n name={app.name}\n path={app.path}\n open={expanded[app.id] === true}\n onOpenChange={(next) =>\n setExpanded((current) => ({ ...current, [app.id]: next }))\n }\n catalog={query?.data}\n isLoading={query?.isLoading ?? false}\n isError={query?.isError ?? false}\n error={query?.error}\n onRetry={() => void query?.refetch()}\n engagementByTemplate={engagementByTemplate}\n engagementUnavailable={engagementUnavailable}\n engagementLoading={engagementQuery?.isLoading ?? false}\n />\n );\n })}\n </div>\n </DispatchShell>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-debug-store.d.ts","sourceRoot":"","sources":["../../../src/server/lib/thread-debug-store.ts"],"names":[],"mappings":"A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;;;;;;;;;;QAiBT,SAAS;QACT,KAAK;;;;;;GAOV"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { classifyAgentFailure, } from "@agent-native/core/agent/engine";
|
|
2
2
|
import { createDbExec, getDbExec } from "@agent-native/core/db";
|
|
3
|
+
import { ForbiddenError } from "@agent-native/core/sharing";
|
|
3
4
|
import { currentOrgId, currentOwnerEmail } from "./dispatch-store.js";
|
|
4
5
|
const CONFIG_ENV_KEY = "AGENT_NATIVE_THREAD_DEBUG_DATABASES";
|
|
5
6
|
const MAX_RAW_PREVIEW_CHARS = 1_500;
|
|
@@ -361,7 +362,7 @@ function assertSourceAccess(source, access) {
|
|
|
361
362
|
if (source.kind === "current")
|
|
362
363
|
return;
|
|
363
364
|
if (!access.canInspectAll) {
|
|
364
|
-
throw new
|
|
365
|
+
throw new ForbiddenError("Only Dispatch admins can inspect thread databases from other apps.");
|
|
365
366
|
}
|
|
366
367
|
}
|
|
367
368
|
function ownerScope(access, ownerEmail, column = "owner_email") {
|