@remit/web-client 0.0.336 → 0.0.338

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.
Files changed (43) hide show
  1. package/dist/src/auth/AccountMenu.js +5 -3
  2. package/dist/src/auth/provider.d.ts +0 -1
  3. package/dist/src/components/settings/ReportLink.d.ts +3 -0
  4. package/dist/src/components/settings/ReportLink.js +4 -0
  5. package/dist/src/components/settings/classification/ClassificationPanel.d.ts +1 -0
  6. package/dist/src/components/settings/classification/ClassificationPanel.js +49 -0
  7. package/dist/src/components/settings/classification/FailureBanner.d.ts +8 -0
  8. package/dist/src/components/settings/classification/FailureBanner.js +8 -0
  9. package/dist/src/components/settings/classification/ProviderCard.d.ts +7 -0
  10. package/dist/src/components/settings/classification/ProviderCard.js +174 -0
  11. package/dist/src/components/settings/people/PeoplePanel.js +1 -3
  12. package/dist/src/hooks/useClassificationSettings.d.ts +173 -0
  13. package/dist/src/hooks/useClassificationSettings.js +47 -0
  14. package/dist/src/lib/classification.d.ts +40 -0
  15. package/dist/src/lib/classification.js +106 -0
  16. package/dist/src/routeTree.gen.d.ts +29 -16
  17. package/dist/src/routeTree.gen.js +14 -7
  18. package/dist/src/routes/settings/{security.d.ts → $slotId.d.ts} +1 -1
  19. package/dist/src/routes/settings/$slotId.js +20 -0
  20. package/dist/src/routes/settings/-shared/help-copy.d.ts +0 -1
  21. package/dist/src/routes/settings/-shared/help-copy.js +0 -1
  22. package/dist/src/routes/settings/accounts.js +4 -7
  23. package/dist/src/routes/settings/advanced.js +4 -7
  24. package/dist/src/routes/settings/appearance.js +4 -7
  25. package/dist/src/routes/settings/calendars.js +4 -6
  26. package/dist/src/routes/settings/classification.d.ts +1 -0
  27. package/dist/src/routes/settings/classification.js +18 -0
  28. package/dist/src/routes/settings/filters.js +4 -7
  29. package/dist/src/routes/settings/folders.js +4 -7
  30. package/dist/src/routes/settings/labels.js +4 -7
  31. package/dist/src/routes/settings/people.js +4 -6
  32. package/dist/src/routes/settings/senders.js +4 -7
  33. package/dist/src/routes/settings/warnings.js +4 -7
  34. package/dist/src/routes/settings.d.ts +0 -1
  35. package/dist/src/routes/settings.js +10 -30
  36. package/dist/src/routing/sections.d.ts +6 -1
  37. package/dist/src/routing/sections.js +10 -1
  38. package/dist/src/settings-slots.d.ts +14 -0
  39. package/dist/src/settings-slots.js +4 -0
  40. package/dist/src/shell/index.d.ts +5 -1
  41. package/dist/src/shell/index.js +8 -2
  42. package/package.json +2 -2
  43. package/dist/src/routes/settings/security.js +0 -21
@@ -1,8 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { AccountMenu as AccountMenuView } from "@remit/ui";
3
- import { useGoToSection } from "../routing/sections";
3
+ import { useOpenSettingsSection } from "../routing/sections";
4
+ import { useSettingsSlots } from "../settings-slots";
4
5
  import { AccountSession } from "./AccountSession";
5
6
  export const AccountMenu = () => {
6
- const goToSection = useGoToSection();
7
- return (_jsx(AccountSession, { children: ({ email, signOut, securityUrl }) => (_jsx(AccountMenuView, { email: email, onOpenSecurity: securityUrl ? () => goToSection("security") : undefined, onSignOut: signOut })) }));
7
+ const openSettingsSection = useOpenSettingsSection();
8
+ const slots = useSettingsSlots();
9
+ return (_jsx(AccountSession, { children: ({ email, signOut }) => (_jsx(AccountMenuView, { email: email, sections: slots.map(({ id, label, icon }) => ({ id, label, icon })), onOpenSection: openSettingsSection, onSignOut: signOut })) }));
8
10
  };
@@ -8,7 +8,6 @@ import { type FC, type ReactNode } from "react";
8
8
  */
9
9
  export interface AuthAccount {
10
10
  email: string | null;
11
- securityUrl?: string;
12
11
  signOut: () => void | Promise<void>;
13
12
  }
14
13
  export interface AuthAccountProps {
@@ -0,0 +1,3 @@
1
+ export declare function ReportLink({ href }: {
2
+ href: string;
3
+ }): import("react").JSX.Element;
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function ReportLink({ href }) {
3
+ return (_jsx("a", { href: href, target: "_blank", rel: "noreferrer", className: "inline-flex min-h-11 items-center font-medium text-accent hover:underline", children: "Report an issue" }));
4
+ }
@@ -0,0 +1 @@
1
+ export declare function ClassificationPanel(): import("react").JSX.Element | null;
@@ -0,0 +1,49 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Switch } from "@remit/ui";
3
+ import { useId, useState } from "react";
4
+ import { useClassificationSettings, useSaveClassification, } from "../../../hooks/useClassificationSettings";
5
+ import { FailureBanner } from "./FailureBanner";
6
+ import { ProviderCard } from "./ProviderCard";
7
+ const LOAD_FAILED = "Mail classification settings did not load";
8
+ const switchNote = (settings) => {
9
+ if (settings.state === "NotConfigured") {
10
+ return "Save a provider below first. Until then, built-in rules label your mail.";
11
+ }
12
+ if (settings.enabled) {
13
+ return "New mail goes to the model. A failed call falls back to built-in rules.";
14
+ }
15
+ return "Provider saved. Built-in rules label your mail until you switch this on.";
16
+ };
17
+ function StatusCard({ settings, }) {
18
+ const toggle = useSaveClassification();
19
+ const [refusal, setRefusal] = useState(null);
20
+ const ids = useId();
21
+ const configured = settings.state === "Configured";
22
+ const on = configured && settings.enabled;
23
+ const flip = () => {
24
+ setRefusal(null);
25
+ toggle.mutate({ body: { classificationEnabled: !on } }, { onError: setRefusal });
26
+ };
27
+ return (_jsxs("section", { "aria-labelledby": `${ids}-title`, className: "space-y-3", children: [_jsx("h2", { id: `${ids}-title`, className: "text-xs font-semibold uppercase tracking-wider text-fg-subtle", children: "Status" }), _jsxs("div", { className: "flex min-h-11 items-center gap-3", children: [_jsxs("span", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx("span", { id: `${ids}-label`, className: "text-sm text-fg", children: "Use the model" }), _jsx("span", { id: `${ids}-note`, className: "text-xs text-fg-subtle", children: switchNote(settings) })] }), _jsx(Switch, { checked: on, "aria-labelledby": `${ids}-label`, "aria-describedby": `${ids}-note`, "aria-disabled": !configured || toggle.isPending, "aria-busy": toggle.isPending, onToggle: flip })] }), refusal !== null && (_jsx(FailureBanner, { failure: {
28
+ title: on
29
+ ? "Classification was not switched off"
30
+ : "Classification was not switched on",
31
+ error: refusal,
32
+ } }))] }));
33
+ }
34
+ export function ClassificationPanel() {
35
+ const query = useClassificationSettings();
36
+ const [announcement, setAnnouncement] = useState("");
37
+ if (query.isPending) {
38
+ return (
39
+ // biome-ignore lint/a11y/useAriaPropsSupportedByRole: aria-label on a loading skeleton is what assistive tech has to go on
40
+ _jsx("div", { className: "h-48 animate-pulse rounded-sm border border-line bg-surface", "aria-busy": "true", "aria-label": "Loading mail classification settings" }));
41
+ }
42
+ if (query.signedOut)
43
+ return null;
44
+ if (query.isError) {
45
+ return (_jsx(FailureBanner, { failure: { title: LOAD_FAILED, error: query.error }, onRetry: () => void query.refetch() }));
46
+ }
47
+ const { classification, classificationPresets } = query.data;
48
+ return (_jsxs("div", { className: "max-w-xl space-y-8", children: [_jsx(StatusCard, { settings: classification }), _jsx(ProviderCard, { presets: classificationPresets, settings: classification, onAnnounce: setAnnouncement }, classification.state), _jsx("p", { "aria-live": "polite", className: "text-sm text-fg-muted", children: announcement })] }));
49
+ }
@@ -0,0 +1,8 @@
1
+ export interface ClassificationFailure {
2
+ title: string;
3
+ error: unknown;
4
+ }
5
+ export declare function FailureBanner({ failure, onRetry, }: {
6
+ failure: ClassificationFailure;
7
+ onRetry?: () => void;
8
+ }): import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Banner, Button, formatErrorMessage } from "@remit/ui";
3
+ import { classificationReportHref } from "../../../lib/classification";
4
+ import { ReportLink } from "../ReportLink";
5
+ export function FailureBanner({ failure, onRetry, }) {
6
+ const message = formatErrorMessage(failure.error);
7
+ return (_jsxs(Banner, { tone: "danger", variant: "soft", children: [_jsx("p", { className: "font-medium", children: failure.title }), _jsx("p", { className: "mt-0.5 break-words text-fg-muted", children: message }), _jsxs("p", { className: "flex flex-wrap items-center gap-x-4", children: [onRetry && (_jsx(Button, { variant: "secondary", className: "min-h-11", onClick: onRetry, children: "Retry" })), _jsx(ReportLink, { href: classificationReportHref(failure.title, message) })] })] }));
8
+ }
@@ -0,0 +1,7 @@
1
+ import type { RemitImapClassificationPreset, RemitImapClassificationSettings } from "@remit/api-http-client/types.gen.ts";
2
+ export interface ProviderCardProps {
3
+ presets: RemitImapClassificationPreset[];
4
+ settings: RemitImapClassificationSettings;
5
+ onAnnounce: (text: string) => void;
6
+ }
7
+ export declare function ProviderCard({ presets, settings, onAnnounce, }: ProviderCardProps): import("react").JSX.Element;
@@ -0,0 +1,174 @@
1
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Banner, Button, ConfirmDialog, FieldLabel, Input, PasswordInput, Select, } from "@remit/ui";
3
+ import { useEffect, useId, useRef, useState } from "react";
4
+ import { useClearClassification, useSaveClassification, useTestClassification, } from "../../../hooks/useClassificationSettings";
5
+ import { classificationReportHref, draftForPreset, draftFromSettings, groupPresets, hasSavedKey, needsBaseUrl, presetNote, providerSave, switchingFrom, testFailureHeadline, } from "../../../lib/classification";
6
+ import { formatDatePreset } from "../../../lib/format";
7
+ import { ReportLink } from "../ReportLink";
8
+ import { FailureBanner } from "./FailureBanner";
9
+ const FIELD_FIX_LABEL = {
10
+ ApiKey: "Replace key",
11
+ Model: "Fix the model",
12
+ BaseUrl: "Fix the base URL",
13
+ };
14
+ function TestOutcome({ result, presetLabel, onFix, shown, }) {
15
+ if (result.state === "Passed") {
16
+ return (_jsxs(Banner, { tone: "success", variant: "soft", children: [_jsxs("p", { className: "font-medium", children: ["Test passed in ", result.latencyMs, " ms"] }), _jsxs("p", { className: "mt-0.5 text-fg-muted", children: ["Sample message labelled ", result.label, ",", " ", Math.round(result.confidence * 100), "% confident."] })] }));
17
+ }
18
+ const headline = testFailureHeadline(result);
19
+ const field = result.field;
20
+ return (_jsxs(Banner, { tone: "danger", variant: "soft", children: [_jsx("p", { className: "font-medium", children: headline }), _jsxs("p", { className: "mt-0.5 break-words text-fg-muted", children: [result.fix, " Nothing changed: classification stays as it was."] }), _jsxs("p", { className: "flex flex-wrap items-center gap-x-4", children: [field !== undefined && shown[field] && (_jsx("button", { type: "button", onClick: () => onFix(field), className: "inline-flex min-h-11 items-center font-medium text-accent hover:underline", children: FIELD_FIX_LABEL[field] })), _jsx(ReportLink, { href: classificationReportHref(`Test of ${presetLabel} failed`, `${headline}. ${result.kind}. ${result.fix}`) })] })] }));
21
+ }
22
+ function Field({ id, label, hint, error, children, }) {
23
+ return (_jsxs("div", { children: [_jsx(FieldLabel, { htmlFor: id, children: label }), children, error && (_jsx("p", { id: `${id}-error`, className: "mt-1 text-xs text-danger", children: error })), hint && (_jsx("p", { id: `${id}-hint`, className: "mt-1 text-xs text-fg-subtle", children: hint }))] }));
24
+ }
25
+ const describedBy = (id, hint, error) => [error ? `${id}-error` : "", hint ? `${id}-hint` : ""]
26
+ .filter(Boolean)
27
+ .join(" ") || undefined;
28
+ function PresetForm({ preset, settings, onAnnounce }) {
29
+ const save = useSaveClassification();
30
+ const clear = useClearClassification();
31
+ const test = useTestClassification();
32
+ const [draft, setDraft] = useState(() => draftForPreset(preset.presetId, settings));
33
+ const [fieldError, setFieldError] = useState(null);
34
+ const [testResult, setTestResult] = useState(null);
35
+ const [replacing, setReplacing] = useState(false);
36
+ const [confirmClear, setConfirmClear] = useState(false);
37
+ const [failure, setFailure] = useState(null);
38
+ const [focusTarget, setFocusTarget] = useState(null);
39
+ const modelRef = useRef(null);
40
+ const baseUrlRef = useRef(null);
41
+ const keyRef = useRef(null);
42
+ const replaceRef = useRef(null);
43
+ const ids = useId();
44
+ const modelId = `${ids}-model`;
45
+ const baseUrlId = `${ids}-base-url`;
46
+ const keyId = `${ids}-key`;
47
+ useEffect(() => {
48
+ if (!focusTarget)
49
+ return;
50
+ const refs = {
51
+ Model: modelRef,
52
+ BaseUrl: baseUrlRef,
53
+ ApiKey: keyRef,
54
+ Replace: replaceRef,
55
+ };
56
+ refs[focusTarget.target].current?.focus();
57
+ }, [focusTarget]);
58
+ const savedKey = preset.needsKey && hasSavedKey(settings, preset.presetId)
59
+ ? settings
60
+ : undefined;
61
+ const showKeyInput = preset.needsKey && (savedKey === undefined || replacing);
62
+ const showBaseUrl = needsBaseUrl(preset);
63
+ const shown = {
64
+ ApiKey: preset.needsKey,
65
+ Model: true,
66
+ BaseUrl: showBaseUrl,
67
+ };
68
+ const errorFor = (field) => fieldError?.field === field ? fieldError.message : undefined;
69
+ const invalid = (field) => errorFor(field) !== undefined ||
70
+ (testResult?.state === "Failed" && testResult.field === field);
71
+ const focus = (target) => setFocusTarget({ target });
72
+ const edit = (field, value) => {
73
+ setDraft((current) => ({ ...current, ...value }));
74
+ setTestResult((current) => (current?.state === "Passed" ? null : current));
75
+ setFieldError((current) => (current?.field === field ? null : current));
76
+ onAnnounce("");
77
+ };
78
+ const startReplace = () => {
79
+ setReplacing(true);
80
+ focus("ApiKey");
81
+ };
82
+ const cancelReplace = () => {
83
+ setReplacing(false);
84
+ setDraft((current) => ({ ...current, apiKey: "" }));
85
+ setFieldError((current) => (current?.field === "ApiKey" ? null : current));
86
+ focus("Replace");
87
+ };
88
+ const fixField = (field) => {
89
+ if (field === "ApiKey" && savedKey) {
90
+ startReplace();
91
+ return;
92
+ }
93
+ focus(field);
94
+ };
95
+ const onSave = () => {
96
+ const result = providerSave(draft, preset, settings);
97
+ if (!result.ok) {
98
+ setFieldError({ field: result.field, message: result.message });
99
+ focus(result.field);
100
+ return;
101
+ }
102
+ setFailure(null);
103
+ const wasReplacing = replacing;
104
+ save.mutate({ body: result.body }, {
105
+ onSuccess: () => {
106
+ setDraft((current) => ({ ...current, apiKey: "" }));
107
+ setReplacing(false);
108
+ setFieldError(null);
109
+ onAnnounce("Saved");
110
+ if (wasReplacing)
111
+ focus("Replace");
112
+ },
113
+ onError: (error) => setFailure({ title: `${preset.label} was not saved`, error }),
114
+ });
115
+ };
116
+ const onTest = () => {
117
+ if (test.isPending)
118
+ return;
119
+ setTestResult(null);
120
+ setFailure(null);
121
+ onAnnounce("");
122
+ test.mutate({
123
+ body: {
124
+ presetId: preset.presetId,
125
+ model: draft.model.trim(),
126
+ baseUrl: draft.baseUrl.trim(),
127
+ apiKey: draft.apiKey.trim(),
128
+ },
129
+ }, {
130
+ onSuccess: setTestResult,
131
+ onError: (error) => setFailure({
132
+ title: `The test of ${preset.label} did not run`,
133
+ error,
134
+ }),
135
+ });
136
+ };
137
+ const onClear = () => {
138
+ clear.mutate({}, {
139
+ onError: (error) => {
140
+ setConfirmClear(false);
141
+ setFailure({
142
+ title: `The ${preset.label} key was not cleared`,
143
+ error,
144
+ });
145
+ },
146
+ });
147
+ };
148
+ const enabled = settings.state === "Configured" && settings.enabled;
149
+ const keyError = errorFor("ApiKey");
150
+ return (_jsxs(_Fragment, { children: [_jsx(Field, { id: modelId, label: "Model", hint: `Empty uses ${preset.defaultModel}.`, error: errorFor("Model"), children: _jsx(Input, { id: modelId, ref: modelRef, className: "h-11", value: draft.model, placeholder: preset.defaultModel, autoComplete: "off", spellCheck: false, "aria-invalid": invalid("Model"), "aria-describedby": describedBy(modelId, true, errorFor("Model") !== undefined), onChange: (event) => edit("Model", { model: event.target.value }) }) }), showBaseUrl && (_jsx(Field, { id: baseUrlId, label: "Base URL", hint: "Remit's server calls this URL.", error: errorFor("BaseUrl"), children: _jsx(Input, { id: baseUrlId, ref: baseUrlRef, className: "h-11", type: "url", inputMode: "url", value: draft.baseUrl, placeholder: "http://localhost:11434/v1", autoComplete: "off", spellCheck: false, required: true, "aria-invalid": invalid("BaseUrl"), "aria-describedby": describedBy(baseUrlId, true, errorFor("BaseUrl") !== undefined), onChange: (event) => edit("BaseUrl", { baseUrl: event.target.value }) }) })), savedKey && !replacing && (_jsxs("div", { children: [_jsx("p", { className: "mb-1 text-xs font-medium text-fg-muted", children: "API key" }), _jsxs("div", { className: "flex flex-wrap items-center gap-x-3 gap-y-2", children: [_jsx("span", { className: invalid("ApiKey") ? "text-sm text-danger" : "text-sm text-fg", children: "set" }), _jsxs("span", { className: "text-sm text-fg-muted", children: ["saved ", formatDatePreset(savedKey.savedAt, "short")] }), _jsx("span", { className: "flex-1" }), _jsx(Button, { ref: replaceRef, variant: "secondary", className: "min-h-11", "aria-invalid": invalid("ApiKey"), onClick: startReplace, children: "Replace" }), _jsx(Button, { variant: "secondary", className: "min-h-11", onClick: () => setConfirmClear(true), children: "Clear" })] })] })), showKeyInput && (_jsx(Field, { id: keyId, label: replacing ? "New API key" : "API key", hint: replacing
151
+ ? "The saved key stays in use until you press Save."
152
+ : undefined, error: keyError, children: _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(PasswordInput, { id: keyId, ref: keyRef, className: "h-11 flex-1", value: draft.apiKey, placeholder: replacing ? "Paste the new key" : "Paste the key", autoComplete: "off", spellCheck: false, "aria-invalid": invalid("ApiKey"), "aria-describedby": describedBy(keyId, replacing, keyError !== undefined), onChange: (event) => edit("ApiKey", { apiKey: event.target.value }), onKeyDown: (event) => {
153
+ if (event.key === "Escape" && replacing) {
154
+ event.preventDefault();
155
+ event.stopPropagation();
156
+ cancelReplace();
157
+ }
158
+ } }), replacing && (_jsx(Button, { variant: "ghost", className: "min-h-11", onClick: cancelReplace, children: "Cancel" }))] }) })), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { variant: "primary", className: "min-h-11", "aria-disabled": save.isPending, onClick: () => {
159
+ if (!save.isPending)
160
+ onSave();
161
+ }, children: save.isPending ? "Saving…" : "Save" }), _jsx(Button, { variant: "secondary", className: "min-h-11", "aria-disabled": test.isPending, "aria-busy": test.isPending, onClick: onTest, children: test.isPending ? "Testing…" : "Test connection" })] }), _jsx("p", { "aria-live": "polite", className: "text-sm text-fg-muted empty:hidden", children: test.isPending ? `Sending one sample message to ${preset.label}` : "" }), testResult && (_jsx(TestOutcome, { result: testResult, presetLabel: preset.label, onFix: fixField, shown: shown })), failure && _jsx(FailureBanner, { failure: failure }), _jsx(ConfirmDialog, { isOpen: confirmClear, title: `Clear the ${preset.label} key?`, description: enabled
162
+ ? `Classification is on. Clearing the key switches it off, and new mail goes back to built-in rules. To use ${preset.label} again you paste the key again.`
163
+ : `To use ${preset.label} again you paste the key again.`, confirmLabel: "Clear key", destructive: true, isBusy: clear.isPending, onConfirm: onClear, onCancel: () => setConfirmClear(false) })] }));
164
+ }
165
+ export function ProviderCard({ presets, settings, onAnnounce, }) {
166
+ const [presetId, setPresetId] = useState(() => draftFromSettings(settings).presetId);
167
+ const presetFieldId = useId();
168
+ const preset = presets.find((entry) => entry.presetId === presetId);
169
+ const from = switchingFrom(settings, presetId, presets);
170
+ return (_jsxs("section", { className: "space-y-4", children: [_jsx("h2", { className: "text-xs font-semibold uppercase tracking-wider text-fg-subtle", children: "Provider" }), _jsx(Field, { id: presetFieldId, label: "Provider", hint: preset ? presetNote(preset) : undefined, children: _jsxs(Select, { id: presetFieldId, className: "h-11", value: presetId ?? "", onChange: (event) => setPresetId(presets.find((entry) => entry.presetId === event.target.value)
171
+ ?.presetId), "aria-describedby": describedBy(presetFieldId, preset !== undefined, false), children: [_jsx("option", { value: "", disabled: true, children: "Choose a provider" }), groupPresets(presets).map((group) => (_jsx("optgroup", { label: group.label, children: group.presets.map((entry) => (_jsx("option", { value: entry.presetId, children: entry.label }, entry.presetId))) }, group.group)))] }) }), from && (_jsxs("p", { className: "text-sm text-warning", children: ["Saving switches from ", from.label, settings.state === "Configured" && settings.apiKeySaved
172
+ ? " and deletes its saved key."
173
+ : "."] })), preset && (_jsx(PresetForm, { preset: preset, settings: settings, onAnnounce: onAnnounce }, preset.presetId))] }));
174
+ }
@@ -4,12 +4,10 @@ import { MoreHorizontal } from "lucide-react";
4
4
  import { useEffect, useRef, useState } from "react";
5
5
  import { usePeople } from "../../../hooks/usePeople";
6
6
  import { classifyPeopleFailure, formatPersonDate, peopleListFailureReason, peopleReportHref, personActionCopy, } from "../../../lib/people";
7
+ import { ReportLink } from "../ReportLink";
7
8
  import { PersonActionDialog } from "./PersonActionDialog";
8
9
  import { ResetLinkDialog } from "./ResetLinkDialog";
9
10
  const LIST_FAILED = "The list of people did not load";
10
- function ReportLink({ href }) {
11
- return (_jsx("a", { href: href, target: "_blank", rel: "noreferrer", className: "font-medium text-accent hover:underline", children: "Report an issue" }));
12
- }
13
11
  function ActionFailedBanner({ failure }) {
14
12
  const ref = useRef(null);
15
13
  useEffect(() => {
@@ -0,0 +1,173 @@
1
+ import type { RemitImapUserSettingsResponse } from "@remit/api-http-client/types.gen.ts";
2
+ export declare const useClassificationSettings: () => {
3
+ signedOut: boolean;
4
+ data: NoInfer<RemitImapUserSettingsResponse>;
5
+ error: import("@remit/api-http-client").ApiError;
6
+ isError: true;
7
+ isPending: false;
8
+ isLoading: false;
9
+ isLoadingError: false;
10
+ isRefetchError: true;
11
+ isSuccess: false;
12
+ isPlaceholderData: false;
13
+ status: "error";
14
+ dataUpdatedAt: number;
15
+ errorUpdatedAt: number;
16
+ failureCount: number;
17
+ failureReason: import("@remit/api-http-client").ApiError | null;
18
+ errorUpdateCount: number;
19
+ isFetched: boolean;
20
+ isFetchedAfterMount: boolean;
21
+ isFetching: boolean;
22
+ isInitialLoading: boolean;
23
+ isPaused: boolean;
24
+ isRefetching: boolean;
25
+ isStale: boolean;
26
+ isEnabled: boolean;
27
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<RemitImapUserSettingsResponse>, import("@remit/api-http-client").ApiError>>;
28
+ fetchStatus: import("@tanstack/query-core").FetchStatus;
29
+ promise: Promise<NoInfer<RemitImapUserSettingsResponse>>;
30
+ } | {
31
+ signedOut: boolean;
32
+ data: NoInfer<RemitImapUserSettingsResponse>;
33
+ error: null;
34
+ isError: false;
35
+ isPending: false;
36
+ isLoading: false;
37
+ isLoadingError: false;
38
+ isRefetchError: false;
39
+ isSuccess: true;
40
+ isPlaceholderData: false;
41
+ status: "success";
42
+ dataUpdatedAt: number;
43
+ errorUpdatedAt: number;
44
+ failureCount: number;
45
+ failureReason: import("@remit/api-http-client").ApiError | null;
46
+ errorUpdateCount: number;
47
+ isFetched: boolean;
48
+ isFetchedAfterMount: boolean;
49
+ isFetching: boolean;
50
+ isInitialLoading: boolean;
51
+ isPaused: boolean;
52
+ isRefetching: boolean;
53
+ isStale: boolean;
54
+ isEnabled: boolean;
55
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<RemitImapUserSettingsResponse>, import("@remit/api-http-client").ApiError>>;
56
+ fetchStatus: import("@tanstack/query-core").FetchStatus;
57
+ promise: Promise<NoInfer<RemitImapUserSettingsResponse>>;
58
+ } | {
59
+ signedOut: boolean;
60
+ data: undefined;
61
+ error: import("@remit/api-http-client").ApiError;
62
+ isError: true;
63
+ isPending: false;
64
+ isLoading: false;
65
+ isLoadingError: true;
66
+ isRefetchError: false;
67
+ isSuccess: false;
68
+ isPlaceholderData: false;
69
+ status: "error";
70
+ dataUpdatedAt: number;
71
+ errorUpdatedAt: number;
72
+ failureCount: number;
73
+ failureReason: import("@remit/api-http-client").ApiError | null;
74
+ errorUpdateCount: number;
75
+ isFetched: boolean;
76
+ isFetchedAfterMount: boolean;
77
+ isFetching: boolean;
78
+ isInitialLoading: boolean;
79
+ isPaused: boolean;
80
+ isRefetching: boolean;
81
+ isStale: boolean;
82
+ isEnabled: boolean;
83
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<RemitImapUserSettingsResponse>, import("@remit/api-http-client").ApiError>>;
84
+ fetchStatus: import("@tanstack/query-core").FetchStatus;
85
+ promise: Promise<NoInfer<RemitImapUserSettingsResponse>>;
86
+ } | {
87
+ signedOut: boolean;
88
+ data: undefined;
89
+ error: null;
90
+ isError: false;
91
+ isPending: true;
92
+ isLoading: true;
93
+ isLoadingError: false;
94
+ isRefetchError: false;
95
+ isSuccess: false;
96
+ isPlaceholderData: false;
97
+ status: "pending";
98
+ dataUpdatedAt: number;
99
+ errorUpdatedAt: number;
100
+ failureCount: number;
101
+ failureReason: import("@remit/api-http-client").ApiError | null;
102
+ errorUpdateCount: number;
103
+ isFetched: boolean;
104
+ isFetchedAfterMount: boolean;
105
+ isFetching: boolean;
106
+ isInitialLoading: boolean;
107
+ isPaused: boolean;
108
+ isRefetching: boolean;
109
+ isStale: boolean;
110
+ isEnabled: boolean;
111
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<RemitImapUserSettingsResponse>, import("@remit/api-http-client").ApiError>>;
112
+ fetchStatus: import("@tanstack/query-core").FetchStatus;
113
+ promise: Promise<NoInfer<RemitImapUserSettingsResponse>>;
114
+ } | {
115
+ signedOut: boolean;
116
+ data: undefined;
117
+ error: null;
118
+ isError: false;
119
+ isPending: true;
120
+ isLoadingError: false;
121
+ isRefetchError: false;
122
+ isSuccess: false;
123
+ isPlaceholderData: false;
124
+ status: "pending";
125
+ dataUpdatedAt: number;
126
+ errorUpdatedAt: number;
127
+ failureCount: number;
128
+ failureReason: import("@remit/api-http-client").ApiError | null;
129
+ errorUpdateCount: number;
130
+ isFetched: boolean;
131
+ isFetchedAfterMount: boolean;
132
+ isFetching: boolean;
133
+ isLoading: boolean;
134
+ isInitialLoading: boolean;
135
+ isPaused: boolean;
136
+ isRefetching: boolean;
137
+ isStale: boolean;
138
+ isEnabled: boolean;
139
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<RemitImapUserSettingsResponse>, import("@remit/api-http-client").ApiError>>;
140
+ fetchStatus: import("@tanstack/query-core").FetchStatus;
141
+ promise: Promise<NoInfer<RemitImapUserSettingsResponse>>;
142
+ } | {
143
+ signedOut: boolean;
144
+ data: NoInfer<RemitImapUserSettingsResponse>;
145
+ isError: false;
146
+ error: null;
147
+ isPending: false;
148
+ isLoading: false;
149
+ isLoadingError: false;
150
+ isRefetchError: false;
151
+ isSuccess: true;
152
+ isPlaceholderData: true;
153
+ status: "success";
154
+ dataUpdatedAt: number;
155
+ errorUpdatedAt: number;
156
+ failureCount: number;
157
+ failureReason: import("@remit/api-http-client").ApiError | null;
158
+ errorUpdateCount: number;
159
+ isFetched: boolean;
160
+ isFetchedAfterMount: boolean;
161
+ isFetching: boolean;
162
+ isInitialLoading: boolean;
163
+ isPaused: boolean;
164
+ isRefetching: boolean;
165
+ isStale: boolean;
166
+ isEnabled: boolean;
167
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<RemitImapUserSettingsResponse>, import("@remit/api-http-client").ApiError>>;
168
+ fetchStatus: import("@tanstack/query-core").FetchStatus;
169
+ promise: Promise<NoInfer<RemitImapUserSettingsResponse>>;
170
+ };
171
+ export declare const useSaveClassification: () => import("@tanstack/react-query").UseMutationResult<RemitImapUserSettingsResponse, import("@remit/api-http-client").ApiError | import("@remit/api-http-client").ValidationError, import("@remit/api-http-client").Options<import("@remit/api-http-client").UserSettingsOperationsUpdateUserSettingsData>, unknown>;
172
+ export declare const useClearClassification: () => import("@tanstack/react-query").UseMutationResult<RemitImapUserSettingsResponse, import("@remit/api-http-client").ApiError, import("@remit/api-http-client").Options<import("@remit/api-http-client").UserSettingsOperationsClearClassificationProviderData>, unknown>;
173
+ export declare const useTestClassification: () => import("@tanstack/react-query").UseMutationResult<import("@remit/api-http-client").RemitImapClassificationTestResponse, import("@remit/api-http-client").ApiError | import("@remit/api-http-client").ValidationError, import("@remit/api-http-client").Options<import("@remit/api-http-client").UserSettingsOperationsTestClassificationProviderData>, unknown>;
@@ -0,0 +1,47 @@
1
+ import { userSettingsOperationsClearClassificationProviderMutation, userSettingsOperationsGetUserSettingsOptions, userSettingsOperationsTestClassificationProviderMutation, userSettingsOperationsUpdateUserSettingsMutation, } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
2
+ import { useMutation, useQuery, useQueryClient, } from "@tanstack/react-query";
3
+ import { useEffect } from "react";
4
+ import { classificationActionMeta, classificationQueryMeta, isClassificationSignedOut, } from "../lib/classification";
5
+ import { reportSignedOut } from "../lib/signed-out";
6
+ const reportIfSignedOut = (error) => {
7
+ if (isClassificationSignedOut(error))
8
+ reportSignedOut();
9
+ };
10
+ const storeSettings = (queryClient) => (settings) => {
11
+ queryClient.setQueryData(userSettingsOperationsGetUserSettingsOptions().queryKey, settings);
12
+ };
13
+ export const useClassificationSettings = () => {
14
+ const query = useQuery({
15
+ ...userSettingsOperationsGetUserSettingsOptions(),
16
+ meta: classificationQueryMeta,
17
+ });
18
+ const signedOut = query.isError && isClassificationSignedOut(query.error);
19
+ useEffect(() => {
20
+ if (signedOut)
21
+ reportSignedOut();
22
+ }, [signedOut]);
23
+ return { ...query, signedOut };
24
+ };
25
+ export const useSaveClassification = () => {
26
+ const queryClient = useQueryClient();
27
+ return useMutation({
28
+ ...userSettingsOperationsUpdateUserSettingsMutation(),
29
+ meta: classificationActionMeta,
30
+ onSuccess: storeSettings(queryClient),
31
+ onError: reportIfSignedOut,
32
+ });
33
+ };
34
+ export const useClearClassification = () => {
35
+ const queryClient = useQueryClient();
36
+ return useMutation({
37
+ ...userSettingsOperationsClearClassificationProviderMutation(),
38
+ meta: classificationActionMeta,
39
+ onSuccess: storeSettings(queryClient),
40
+ onError: reportIfSignedOut,
41
+ });
42
+ };
43
+ export const useTestClassification = () => useMutation({
44
+ ...userSettingsOperationsTestClassificationProviderMutation(),
45
+ meta: classificationActionMeta,
46
+ onError: reportIfSignedOut,
47
+ });
@@ -0,0 +1,40 @@
1
+ import type { RemitImapClassificationConfigured, RemitImapClassificationField, RemitImapClassificationPreset, RemitImapClassificationPresetGroup, RemitImapClassificationPresetId, RemitImapClassificationSettings, RemitImapClassificationTestFailed, RemitImapUpdateUserSettingsInput } from "@remit/api-http-client/types.gen.ts";
2
+ export declare const classificationQueryMeta: {
3
+ softErrorStatuses: number[];
4
+ };
5
+ export declare const classificationActionMeta: {
6
+ ownsServerErrors: true;
7
+ softErrorStatuses: number[];
8
+ };
9
+ export declare const isClassificationSignedOut: (error: unknown) => boolean;
10
+ export interface ProviderDraft {
11
+ presetId: RemitImapClassificationPresetId | undefined;
12
+ model: string;
13
+ baseUrl: string;
14
+ apiKey: string;
15
+ }
16
+ export declare const draftFromSettings: (settings: RemitImapClassificationSettings) => ProviderDraft;
17
+ export declare const draftForPreset: (presetId: RemitImapClassificationPresetId, settings: RemitImapClassificationSettings) => ProviderDraft;
18
+ export interface PresetGroup {
19
+ group: RemitImapClassificationPresetGroup;
20
+ label: string;
21
+ presets: RemitImapClassificationPreset[];
22
+ }
23
+ export declare const groupPresets: (presets: readonly RemitImapClassificationPreset[]) => PresetGroup[];
24
+ export declare const needsBaseUrl: (preset: RemitImapClassificationPreset) => boolean;
25
+ export declare const hasSavedKey: (settings: RemitImapClassificationSettings, presetId: RemitImapClassificationPresetId | undefined) => settings is RemitImapClassificationConfigured;
26
+ export type ProviderSave = {
27
+ ok: true;
28
+ body: RemitImapUpdateUserSettingsInput;
29
+ } | {
30
+ ok: false;
31
+ field: RemitImapClassificationField;
32
+ message: string;
33
+ };
34
+ export declare const PASTE_KEY = "Paste an API key";
35
+ export declare const BAD_URL = "Enter a URL that starts with http:// or https://";
36
+ export declare const providerSave: (draft: ProviderDraft, preset: RemitImapClassificationPreset, settings: RemitImapClassificationSettings) => ProviderSave;
37
+ export declare const switchingFrom: (settings: RemitImapClassificationSettings, presetId: RemitImapClassificationPresetId | undefined, presets: readonly RemitImapClassificationPreset[]) => RemitImapClassificationPreset | undefined;
38
+ export declare const testFailureHeadline: (failure: RemitImapClassificationTestFailed) => string;
39
+ export declare const classificationReportHref: (title: string, detail: string) => string;
40
+ export declare const presetNote: (preset: RemitImapClassificationPreset) => string;