@remit/web-client 0.0.331 → 0.0.333

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 (46) hide show
  1. package/dist/src/auth/AccountMenu.js +1 -1
  2. package/dist/src/auth/BetterAuthShell.d.ts +12 -2
  3. package/dist/src/auth/BetterAuthShell.js +40 -7
  4. package/dist/src/auth/ResetPasswordPage.d.ts +12 -0
  5. package/dist/src/auth/ResetPasswordPage.js +98 -0
  6. package/dist/src/auth/auth-refusal.d.ts +10 -0
  7. package/dist/src/auth/auth-refusal.js +14 -0
  8. package/dist/src/auth/better-auth-config.js +4 -0
  9. package/dist/src/auth/provider.d.ts +1 -0
  10. package/dist/src/auth/session-state.d.ts +8 -3
  11. package/dist/src/auth/session-state.js +8 -3
  12. package/dist/src/components/settings/people/PeoplePanel.d.ts +1 -0
  13. package/dist/src/components/settings/people/PeoplePanel.js +72 -0
  14. package/dist/src/components/settings/people/PersonActionDialog.d.ts +11 -0
  15. package/dist/src/components/settings/people/PersonActionDialog.js +52 -0
  16. package/dist/src/components/settings/people/ResetLinkDialog.d.ts +11 -0
  17. package/dist/src/components/settings/people/ResetLinkDialog.js +23 -0
  18. package/dist/src/hooks/usePeople.d.ts +174 -0
  19. package/dist/src/hooks/usePeople.js +28 -0
  20. package/dist/src/hooks/usePersonAction.d.ts +17 -0
  21. package/dist/src/hooks/usePersonAction.js +60 -0
  22. package/dist/src/lib/error-classifier.d.ts +16 -4
  23. package/dist/src/lib/error-classifier.js +28 -7
  24. package/dist/src/lib/network-error.d.ts +8 -0
  25. package/dist/src/lib/network-error.js +12 -1
  26. package/dist/src/lib/people.d.ts +49 -0
  27. package/dist/src/lib/people.js +125 -0
  28. package/dist/src/lib/rum-adapter.js +4 -1
  29. package/dist/src/routeTree.gen.d.ts +29 -3
  30. package/dist/src/routeTree.gen.js +14 -0
  31. package/dist/src/routes/reset-password/$token.d.ts +5 -0
  32. package/dist/src/routes/reset-password/$token.js +10 -0
  33. package/dist/src/routes/settings/accounts.js +3 -2
  34. package/dist/src/routes/settings/advanced.js +3 -2
  35. package/dist/src/routes/settings/appearance.js +3 -2
  36. package/dist/src/routes/settings/calendars.js +3 -2
  37. package/dist/src/routes/settings/filters.js +3 -2
  38. package/dist/src/routes/settings/folders.js +3 -2
  39. package/dist/src/routes/settings/labels.js +3 -2
  40. package/dist/src/routes/settings/people.d.ts +1 -0
  41. package/dist/src/routes/settings/people.js +20 -0
  42. package/dist/src/routes/settings/senders.js +3 -2
  43. package/dist/src/routes/settings/warnings.js +3 -2
  44. package/dist/src/routes/settings.d.ts +5 -0
  45. package/dist/src/routes/settings.js +23 -1
  46. package/package.json +2 -2
@@ -0,0 +1,174 @@
1
+ /**
2
+ * The People list. A 404 means this server has no People page, which hides it;
3
+ * a 403 for a disabled caller or the kill switch raises the signed-out notice,
4
+ * so neither ever reads as an empty list.
5
+ */
6
+ export declare const usePeople: () => {
7
+ unavailable: boolean;
8
+ data: NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>;
9
+ error: import("@remit/api-http-client").PeopleOperationsListPeopleError;
10
+ isError: true;
11
+ isPending: false;
12
+ isLoading: false;
13
+ isLoadingError: false;
14
+ isRefetchError: true;
15
+ isSuccess: false;
16
+ isPlaceholderData: false;
17
+ status: "error";
18
+ dataUpdatedAt: number;
19
+ errorUpdatedAt: number;
20
+ failureCount: number;
21
+ failureReason: import("@remit/api-http-client").PeopleOperationsListPeopleError | null;
22
+ errorUpdateCount: number;
23
+ isFetched: boolean;
24
+ isFetchedAfterMount: boolean;
25
+ isFetching: boolean;
26
+ isInitialLoading: boolean;
27
+ isPaused: boolean;
28
+ isRefetching: boolean;
29
+ isStale: boolean;
30
+ isEnabled: boolean;
31
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>, import("@remit/api-http-client").PeopleOperationsListPeopleError>>;
32
+ fetchStatus: import("@tanstack/query-core").FetchStatus;
33
+ promise: Promise<NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>>;
34
+ } | {
35
+ unavailable: boolean;
36
+ data: NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>;
37
+ error: null;
38
+ isError: false;
39
+ isPending: false;
40
+ isLoading: false;
41
+ isLoadingError: false;
42
+ isRefetchError: false;
43
+ isSuccess: true;
44
+ isPlaceholderData: false;
45
+ status: "success";
46
+ dataUpdatedAt: number;
47
+ errorUpdatedAt: number;
48
+ failureCount: number;
49
+ failureReason: import("@remit/api-http-client").PeopleOperationsListPeopleError | null;
50
+ errorUpdateCount: number;
51
+ isFetched: boolean;
52
+ isFetchedAfterMount: boolean;
53
+ isFetching: boolean;
54
+ isInitialLoading: boolean;
55
+ isPaused: boolean;
56
+ isRefetching: boolean;
57
+ isStale: boolean;
58
+ isEnabled: boolean;
59
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>, import("@remit/api-http-client").PeopleOperationsListPeopleError>>;
60
+ fetchStatus: import("@tanstack/query-core").FetchStatus;
61
+ promise: Promise<NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>>;
62
+ } | {
63
+ unavailable: boolean;
64
+ data: undefined;
65
+ error: import("@remit/api-http-client").PeopleOperationsListPeopleError;
66
+ isError: true;
67
+ isPending: false;
68
+ isLoading: false;
69
+ isLoadingError: true;
70
+ isRefetchError: false;
71
+ isSuccess: false;
72
+ isPlaceholderData: false;
73
+ status: "error";
74
+ dataUpdatedAt: number;
75
+ errorUpdatedAt: number;
76
+ failureCount: number;
77
+ failureReason: import("@remit/api-http-client").PeopleOperationsListPeopleError | null;
78
+ errorUpdateCount: number;
79
+ isFetched: boolean;
80
+ isFetchedAfterMount: boolean;
81
+ isFetching: boolean;
82
+ isInitialLoading: boolean;
83
+ isPaused: boolean;
84
+ isRefetching: boolean;
85
+ isStale: boolean;
86
+ isEnabled: boolean;
87
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>, import("@remit/api-http-client").PeopleOperationsListPeopleError>>;
88
+ fetchStatus: import("@tanstack/query-core").FetchStatus;
89
+ promise: Promise<NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>>;
90
+ } | {
91
+ unavailable: boolean;
92
+ data: undefined;
93
+ error: null;
94
+ isError: false;
95
+ isPending: true;
96
+ isLoading: true;
97
+ isLoadingError: false;
98
+ isRefetchError: false;
99
+ isSuccess: false;
100
+ isPlaceholderData: false;
101
+ status: "pending";
102
+ dataUpdatedAt: number;
103
+ errorUpdatedAt: number;
104
+ failureCount: number;
105
+ failureReason: import("@remit/api-http-client").PeopleOperationsListPeopleError | null;
106
+ errorUpdateCount: number;
107
+ isFetched: boolean;
108
+ isFetchedAfterMount: boolean;
109
+ isFetching: boolean;
110
+ isInitialLoading: boolean;
111
+ isPaused: boolean;
112
+ isRefetching: boolean;
113
+ isStale: boolean;
114
+ isEnabled: boolean;
115
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>, import("@remit/api-http-client").PeopleOperationsListPeopleError>>;
116
+ fetchStatus: import("@tanstack/query-core").FetchStatus;
117
+ promise: Promise<NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>>;
118
+ } | {
119
+ unavailable: boolean;
120
+ data: undefined;
121
+ error: null;
122
+ isError: false;
123
+ isPending: true;
124
+ isLoadingError: false;
125
+ isRefetchError: false;
126
+ isSuccess: false;
127
+ isPlaceholderData: false;
128
+ status: "pending";
129
+ dataUpdatedAt: number;
130
+ errorUpdatedAt: number;
131
+ failureCount: number;
132
+ failureReason: import("@remit/api-http-client").PeopleOperationsListPeopleError | null;
133
+ errorUpdateCount: number;
134
+ isFetched: boolean;
135
+ isFetchedAfterMount: boolean;
136
+ isFetching: boolean;
137
+ isLoading: boolean;
138
+ isInitialLoading: boolean;
139
+ isPaused: boolean;
140
+ isRefetching: boolean;
141
+ isStale: boolean;
142
+ isEnabled: boolean;
143
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>, import("@remit/api-http-client").PeopleOperationsListPeopleError>>;
144
+ fetchStatus: import("@tanstack/query-core").FetchStatus;
145
+ promise: Promise<NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>>;
146
+ } | {
147
+ unavailable: boolean;
148
+ data: NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>;
149
+ isError: false;
150
+ error: null;
151
+ isPending: false;
152
+ isLoading: false;
153
+ isLoadingError: false;
154
+ isRefetchError: false;
155
+ isSuccess: true;
156
+ isPlaceholderData: true;
157
+ status: "success";
158
+ dataUpdatedAt: number;
159
+ errorUpdatedAt: number;
160
+ failureCount: number;
161
+ failureReason: import("@remit/api-http-client").PeopleOperationsListPeopleError | null;
162
+ errorUpdateCount: number;
163
+ isFetched: boolean;
164
+ isFetchedAfterMount: boolean;
165
+ isFetching: boolean;
166
+ isInitialLoading: boolean;
167
+ isPaused: boolean;
168
+ isRefetching: boolean;
169
+ isStale: boolean;
170
+ isEnabled: boolean;
171
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>, import("@remit/api-http-client").PeopleOperationsListPeopleError>>;
172
+ fetchStatus: import("@tanstack/query-core").FetchStatus;
173
+ promise: Promise<NoInfer<import("@remit/api-http-client").RemitImapPeopleListResponse>>;
174
+ };
@@ -0,0 +1,28 @@
1
+ import { peopleOperationsListPeopleOptions } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useEffect } from "react";
4
+ import { isNotFound } from "../lib/error-classifier";
5
+ import { isPeopleSignedOut, peopleQueryMeta } from "../lib/people";
6
+ import { reportSignedOut } from "../lib/signed-out";
7
+ const peopleQueryOptions = () => ({
8
+ ...peopleOperationsListPeopleOptions(),
9
+ meta: peopleQueryMeta,
10
+ retry: false,
11
+ });
12
+ /**
13
+ * The People list. A 404 means this server has no People page, which hides it;
14
+ * a 403 for a disabled caller or the kill switch raises the signed-out notice,
15
+ * so neither ever reads as an empty list.
16
+ */
17
+ export const usePeople = () => {
18
+ const query = useQuery(peopleQueryOptions());
19
+ const signedOut = query.isError && isPeopleSignedOut(query.error);
20
+ useEffect(() => {
21
+ if (signedOut)
22
+ reportSignedOut();
23
+ }, [signedOut]);
24
+ return {
25
+ ...query,
26
+ unavailable: query.isError && isNotFound(query.error),
27
+ };
28
+ };
@@ -0,0 +1,17 @@
1
+ import type { RemitImapPerson, RemitImapStepUpAction } from "@remit/api-http-client/types.gen.ts";
2
+ export interface PersonActionInput {
3
+ action: RemitImapStepUpAction;
4
+ person: RemitImapPerson;
5
+ }
6
+ export interface PersonActionResult {
7
+ person: RemitImapPerson;
8
+ resetUrl: string | undefined;
9
+ }
10
+ /**
11
+ * One People action behind its own password step-up: the token is earned for
12
+ * this action on this person and spent at once, never stored. The password
13
+ * reaches the request through this closure, so it never becomes mutation
14
+ * variables, and `gcTime: 0` drops the result, reset link included, once the
15
+ * dialog lets go of it.
16
+ */
17
+ export declare const usePersonAction: (password: string) => import("@tanstack/react-query").UseMutationResult<PersonActionResult, Error, PersonActionInput, unknown>;
@@ -0,0 +1,60 @@
1
+ import { peopleOperationsListPeopleQueryKey } from "@remit/api-http-client/@tanstack/react-query.gen.ts";
2
+ import { peopleOperationsCreatePasswordReset, peopleOperationsCreateStepUp, peopleOperationsSignOutPerson, peopleOperationsUpdatePerson, } from "@remit/api-http-client/sdk.gen.ts";
3
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
4
+ import { peopleActionMeta, replacePerson } from "../lib/people";
5
+ const runAction = async ({ action, person }, stepUpToken) => {
6
+ const path = { userId: person.userId };
7
+ if (action === "SignOut") {
8
+ const { data } = await peopleOperationsSignOutPerson({
9
+ path,
10
+ body: { stepUpToken },
11
+ throwOnError: true,
12
+ });
13
+ return { person: data, resetUrl: undefined };
14
+ }
15
+ if (action === "ResetPassword") {
16
+ const { data } = await peopleOperationsCreatePasswordReset({
17
+ path,
18
+ body: { stepUpToken },
19
+ throwOnError: true,
20
+ });
21
+ return { person: data.person, resetUrl: data.resetUrl };
22
+ }
23
+ const { data } = await peopleOperationsUpdatePerson({
24
+ path,
25
+ body: {
26
+ status: action === "Disable" ? "Disabled" : "Active",
27
+ stepUpToken,
28
+ },
29
+ throwOnError: true,
30
+ });
31
+ return { person: data, resetUrl: undefined };
32
+ };
33
+ /**
34
+ * One People action behind its own password step-up: the token is earned for
35
+ * this action on this person and spent at once, never stored. The password
36
+ * reaches the request through this closure, so it never becomes mutation
37
+ * variables, and `gcTime: 0` drops the result, reset link included, once the
38
+ * dialog lets go of it.
39
+ */
40
+ export const usePersonAction = (password) => {
41
+ const queryClient = useQueryClient();
42
+ return useMutation({
43
+ meta: peopleActionMeta,
44
+ gcTime: 0,
45
+ mutationFn: async (input) => {
46
+ const { data } = await peopleOperationsCreateStepUp({
47
+ body: {
48
+ password,
49
+ action: input.action,
50
+ userId: input.person.userId,
51
+ },
52
+ throwOnError: true,
53
+ });
54
+ return runAction(input, data.stepUpToken);
55
+ },
56
+ onSuccess: ({ person }) => {
57
+ queryClient.setQueryData(peopleOperationsListPeopleQueryKey(), (list) => list ? { people: replacePerson(list.people, person) } : list);
58
+ },
59
+ });
60
+ };
@@ -53,9 +53,10 @@ export declare const isClientBug: (error: unknown) => boolean;
53
53
  */
54
54
  export declare const isAlwaysFatal: (error: unknown) => boolean;
55
55
  /**
56
- * The session is gone. Not 403: a handler answers 403 for a resource belonging
57
- * to another account config, which is a refusal a call site can state where it
58
- * stands. A 401 is the user signed out from under whatever they were doing.
56
+ * The session is gone. Not any 403: a handler answers 403 for a resource
57
+ * belonging to another account config, which is a refusal a call site can state
58
+ * where it stands. A 401 is the user signed out from under whatever they were
59
+ * doing, and so is a token mint the server refused.
59
60
  */
60
61
  export declare const isUnauthenticated: (error: unknown) => boolean;
61
62
  /**
@@ -69,7 +70,9 @@ export declare const isUnauthenticated: (error: unknown) => boolean;
69
70
  * answered "I'm broken"; that is never benign. The single exception is a
70
71
  * 502/503/504 on a call site that declared it is polling across a restart it
71
72
  * asked for (`meta.restartExpected`, #468): there the backend being gone is
72
- * the operation working, and that call site renders the wait itself.
73
+ * the operation working, and that call site renders the wait itself. The
74
+ * other is a user action whose call site states the failure on the screen
75
+ * the user is on, with a report link (`meta.ownsServerErrors`).
73
76
  * 3. A client-side exception ALWAYS escalates, on the same terms. It is our
74
77
  * bug; there is nothing for the user to retry and nothing to dismiss.
75
78
  * 4. A 401 NEVER escalates here: the session is gone, and the signed-out
@@ -126,5 +129,14 @@ export declare const softErrorStatuses: (...statuses: number[]) => {
126
129
  export declare const restartExpectedMeta: {
127
130
  restartExpected: true;
128
131
  };
132
+ /**
133
+ * For a user action that shows its own server failure where the user acted, as
134
+ * the People actions do: a banner naming what did not happen, with a prefilled
135
+ * report. A 401 still goes to the signed-out notice and a client bug still
136
+ * escalates.
137
+ */
138
+ export declare const ownsServerErrorsMeta: {
139
+ ownsServerErrors: true;
140
+ };
129
141
  /** The record is not there. */
130
142
  export declare const isNotFound: (error: unknown) => boolean;
@@ -91,11 +91,20 @@ export const isClientBug = (error) => !hasHttpStatus(error) && !isAbortError(err
91
91
  */
92
92
  export const isAlwaysFatal = (error) => isServerError(error) || isClientBug(error);
93
93
  /**
94
- * The session is gone. Not 403: a handler answers 403 for a resource belonging
95
- * to another account config, which is a refusal a call site can state where it
96
- * stands. A 401 is the user signed out from under whatever they were doing.
94
+ * The bearer token could not be minted because the server refused the session
95
+ * itself: the self-host kill switch is on, or the account was disabled. Read by
96
+ * name, as `isAbortError` does, so this module never loads the auth client.
97
97
  */
98
- export const isUnauthenticated = (error) => getErrorStatus(error) === 401;
98
+ const isRefusedTokenMint = (error) => error instanceof Error &&
99
+ error.name === "AuthTokenError" &&
100
+ getErrorStatus(error) === 403;
101
+ /**
102
+ * The session is gone. Not any 403: a handler answers 403 for a resource
103
+ * belonging to another account config, which is a refusal a call site can state
104
+ * where it stands. A 401 is the user signed out from under whatever they were
105
+ * doing, and so is a token mint the server refused.
106
+ */
107
+ export const isUnauthenticated = (error) => getErrorStatus(error) === 401 || isRefusedTokenMint(error);
99
108
  const isSoftErrorMeta = (error, meta) => {
100
109
  if (meta?.softError === true)
101
110
  return true;
@@ -139,7 +148,9 @@ const isDesignedRestartGap = (error, meta) => {
139
148
  * answered "I'm broken"; that is never benign. The single exception is a
140
149
  * 502/503/504 on a call site that declared it is polling across a restart it
141
150
  * asked for (`meta.restartExpected`, #468): there the backend being gone is
142
- * the operation working, and that call site renders the wait itself.
151
+ * the operation working, and that call site renders the wait itself. The
152
+ * other is a user action whose call site states the failure on the screen
153
+ * the user is on, with a report link (`meta.ownsServerErrors`).
143
154
  * 3. A client-side exception ALWAYS escalates, on the same terms. It is our
144
155
  * bug; there is nothing for the user to retry and nothing to dismiss.
145
156
  * 4. A 401 NEVER escalates here: the session is gone, and the signed-out
@@ -154,8 +165,9 @@ const isDesignedRestartGap = (error, meta) => {
154
165
  * one status and not the rest, `meta.softErrorStatuses`.
155
166
  */
156
167
  export const shouldEscalate = (error, meta) => {
157
- if (isServerError(error))
158
- return !isDesignedRestartGap(error, meta);
168
+ if (isServerError(error)) {
169
+ return (!isDesignedRestartGap(error, meta) && meta?.ownsServerErrors !== true);
170
+ }
159
171
  if (isAbortError(error))
160
172
  return false;
161
173
  if (isNetworkError(error))
@@ -206,5 +218,14 @@ export const softErrorStatuses = (...statuses) => ({ softErrorStatuses: statuses
206
218
  export const restartExpectedMeta = {
207
219
  restartExpected: true,
208
220
  };
221
+ /**
222
+ * For a user action that shows its own server failure where the user acted, as
223
+ * the People actions do: a banner naming what did not happen, with a prefilled
224
+ * report. A 401 still goes to the signed-out notice and a client bug still
225
+ * escalates.
226
+ */
227
+ export const ownsServerErrorsMeta = {
228
+ ownsServerErrors: true,
229
+ };
209
230
  /** The record is not there. */
210
231
  export const isNotFound = (error) => getErrorStatus(error) === 404;
@@ -27,5 +27,13 @@ export declare class NetworkError extends Error {
27
27
  * breadcrumb (method, path, status, duration, correlation id) for bug reports.
28
28
  * A deliberate abort is not a request outcome worth reporting, so it is
29
29
  * re-thrown before any breadcrumb is written.
30
+ *
31
+ * Redirects are never followed. Behind Cloudflare Access an expired session
32
+ * answers with a 302 to the login page on another origin, which sends no CORS
33
+ * headers, so a followed redirect rejects as "Failed to fetch" and would read
34
+ * as an offline blip. No API route redirects a fetch, so an opaque redirect
35
+ * means the session is gone and becomes a 401, the signed-out path. The
36
+ * `redirect` in `init` overrides the one on a `Request` input, which is what
37
+ * the generated client passes.
30
38
  */
31
39
  export declare const taggedFetch: typeof fetch;
@@ -46,11 +46,22 @@ const isDeliberateAbort = (error) => typeof error === "object" &&
46
46
  * breadcrumb (method, path, status, duration, correlation id) for bug reports.
47
47
  * A deliberate abort is not a request outcome worth reporting, so it is
48
48
  * re-thrown before any breadcrumb is written.
49
+ *
50
+ * Redirects are never followed. Behind Cloudflare Access an expired session
51
+ * answers with a 302 to the login page on another origin, which sends no CORS
52
+ * headers, so a followed redirect rejects as "Failed to fetch" and would read
53
+ * as an offline blip. No API route redirects a fetch, so an opaque redirect
54
+ * means the session is gone and becomes a 401, the signed-out path. The
55
+ * `redirect` in `init` overrides the one on a `Request` input, which is what
56
+ * the generated client passes.
49
57
  */
50
58
  export const taggedFetch = async (input, init) => {
51
59
  const startedAt = performance.now();
52
60
  try {
53
- const response = await fetch(input, init);
61
+ const received = await fetch(input, { ...init, redirect: "manual" });
62
+ const response = received.type === "opaqueredirect"
63
+ ? new Response(null, { status: 401 })
64
+ : received;
54
65
  recordRequest({
55
66
  input,
56
67
  init,
@@ -0,0 +1,49 @@
1
+ import type { RemitImapPerson, RemitImapStepUpAction } from "@remit/api-http-client/types.gen.ts";
2
+ /**
3
+ * The list read owns its refusals: a 404 means this server has no People page
4
+ * (self sign-up is open, or it is not a self-host), and a 403 means the caller
5
+ * may no longer act, which the page turns into the signed-out notice.
6
+ */
7
+ export declare const peopleQueryMeta: {
8
+ softErrorStatuses: number[];
9
+ };
10
+ /**
11
+ * The action dialogs own every refusal the People operations answer, and a
12
+ * server failure too: it shows as the banner over the list.
13
+ */
14
+ export declare const peopleActionMeta: {
15
+ ownsServerErrors: true;
16
+ softErrorStatuses: number[];
17
+ };
18
+ /**
19
+ * A People refusal that means the caller's session no longer counts: the kill
20
+ * switch is on, or the caller's own account was disabled.
21
+ */
22
+ export declare const isPeopleSignedOut: (error: unknown) => boolean;
23
+ export type PeopleFailure = {
24
+ kind: "signedOut";
25
+ } | {
26
+ kind: "wrongPassword";
27
+ } | {
28
+ kind: "locked";
29
+ } | {
30
+ kind: "failed";
31
+ reason: string;
32
+ };
33
+ export declare const peopleListFailureReason: (error: unknown) => string;
34
+ export declare const classifyPeopleFailure: (error: unknown) => PeopleFailure;
35
+ export interface PersonActionCopy {
36
+ title: string;
37
+ body: string;
38
+ confirmLabel: string;
39
+ failedTitle: string;
40
+ destructive: boolean;
41
+ }
42
+ export declare const personActionCopy: (action: RemitImapStepUpAction, email: string) => PersonActionCopy;
43
+ /**
44
+ * A prefilled issue for a People action the server failed. It names the action
45
+ * and the server's answer, never the password or a token.
46
+ */
47
+ export declare const peopleReportHref: (title: string, error: unknown) => string;
48
+ export declare const formatPersonDate: (epochMs: number, now: Date) => string;
49
+ export declare const replacePerson: (people: readonly RemitImapPerson[], person: RemitImapPerson) => RemitImapPerson[];
@@ -0,0 +1,125 @@
1
+ import { PeopleErrorCode } from "@remit/domain-enums";
2
+ import { codedApiErrorBody } from "./api";
3
+ import { buildBugReportContext, buildGitHubIssueUrl } from "./bug-report";
4
+ import { getErrorStatus, isNetworkError, ownsServerErrorsMeta, softErrorStatuses, } from "./error-classifier";
5
+ import { formatDatePreset } from "./format";
6
+ /**
7
+ * The list read owns its refusals: a 404 means this server has no People page
8
+ * (self sign-up is open, or it is not a self-host), and a 403 means the caller
9
+ * may no longer act, which the page turns into the signed-out notice.
10
+ */
11
+ export const peopleQueryMeta = softErrorStatuses(403, 404);
12
+ /**
13
+ * The action dialogs own every refusal the People operations answer, and a
14
+ * server failure too: it shows as the banner over the list.
15
+ */
16
+ export const peopleActionMeta = {
17
+ ...softErrorStatuses(403, 404, 409, 429),
18
+ ...ownsServerErrorsMeta,
19
+ };
20
+ const SIGNED_OUT_CODES = new Set([
21
+ PeopleErrorCode.SignInDisabled,
22
+ PeopleErrorCode.CallerDisabled,
23
+ ]);
24
+ /**
25
+ * A People refusal that means the caller's session no longer counts: the kill
26
+ * switch is on, or the caller's own account was disabled.
27
+ */
28
+ export const isPeopleSignedOut = (error) => {
29
+ if (getErrorStatus(error) !== 403)
30
+ return false;
31
+ const code = codedApiErrorBody(error)?.code;
32
+ return code !== undefined && SIGNED_OUT_CODES.has(code);
33
+ };
34
+ const failureReason = (error) => {
35
+ if (isNetworkError(error)) {
36
+ return "The server could not be reached. Nothing changed. Try again.";
37
+ }
38
+ const code = codedApiErrorBody(error)?.code;
39
+ if (code === PeopleErrorCode.CannotDisableSelf) {
40
+ return "You cannot disable your own account, so one account always stays on.";
41
+ }
42
+ if (code === PeopleErrorCode.StepUpRequired) {
43
+ return "The password check did not carry over to the action. Nothing changed. Try again.";
44
+ }
45
+ if (code === PeopleErrorCode.ForeignOrigin) {
46
+ return "The server refused a request from this address. Nothing changed. Open this page from the server's own address.";
47
+ }
48
+ if (getErrorStatus(error) === 404) {
49
+ return "That account is gone, or this server no longer has a People page. Reload the page.";
50
+ }
51
+ return "Something went wrong on the server. Nothing changed. Try again.";
52
+ };
53
+ export const peopleListFailureReason = (error) => isNetworkError(error)
54
+ ? "The server could not be reached. Check your connection and try again."
55
+ : "The server did not answer as expected. Try again.";
56
+ export const classifyPeopleFailure = (error) => {
57
+ if (getErrorStatus(error) === 401 || isPeopleSignedOut(error)) {
58
+ return { kind: "signedOut" };
59
+ }
60
+ const code = codedApiErrorBody(error)?.code;
61
+ if (code === PeopleErrorCode.WrongPassword)
62
+ return { kind: "wrongPassword" };
63
+ if (code === PeopleErrorCode.StepUpLocked)
64
+ return { kind: "locked" };
65
+ return { kind: "failed", reason: failureReason(error) };
66
+ };
67
+ export const personActionCopy = (action, email) => {
68
+ if (action === "Disable") {
69
+ return {
70
+ title: `Disable ${email}?`,
71
+ body: "They are signed out everywhere within 15 minutes and cannot sign in until you enable them again. Their calendar feed links stop working. Their mail stays.",
72
+ confirmLabel: "Disable",
73
+ failedTitle: `${email} was not disabled`,
74
+ destructive: true,
75
+ };
76
+ }
77
+ if (action === "Enable") {
78
+ return {
79
+ title: `Enable ${email}?`,
80
+ body: "They can sign in again with their password. Calendar feed links they shared before stay off; they make new ones in Settings.",
81
+ confirmLabel: "Enable",
82
+ failedTitle: `${email} was not enabled`,
83
+ destructive: false,
84
+ };
85
+ }
86
+ if (action === "SignOut") {
87
+ return {
88
+ title: `Sign ${email} out everywhere?`,
89
+ body: "Every session and connected app of theirs ends within 15 minutes. They can sign in again with their password.",
90
+ confirmLabel: "Sign out everywhere",
91
+ failedTitle: `${email} was not signed out`,
92
+ destructive: true,
93
+ };
94
+ }
95
+ return {
96
+ title: `Reset the password of ${email}?`,
97
+ body: "Their password stops working at once and they are signed out everywhere. You get a link to give them, which works once, for 24 hours.",
98
+ confirmLabel: "Make a reset link",
99
+ failedTitle: `No reset link was made for ${email}`,
100
+ destructive: true,
101
+ };
102
+ };
103
+ /**
104
+ * A prefilled issue for a People action the server failed. It names the action
105
+ * and the server's answer, never the password or a token.
106
+ */
107
+ export const peopleReportHref = (title, error) => {
108
+ const status = getErrorStatus(error);
109
+ const code = codedApiErrorBody(error)?.code;
110
+ const message = error instanceof Error ? error.message : String(error);
111
+ const answer = [status ?? "no response", code, message]
112
+ .filter((part) => part !== undefined && part !== "")
113
+ .join(" ");
114
+ return buildGitHubIssueUrl(buildBugReportContext({
115
+ title: `People: ${title}`,
116
+ errorMessage: `${title}. The server answered: ${answer}`,
117
+ }));
118
+ };
119
+ const sameDay = (a, b) => a.getFullYear() === b.getFullYear() &&
120
+ a.getMonth() === b.getMonth() &&
121
+ a.getDate() === b.getDate();
122
+ export const formatPersonDate = (epochMs, now) => sameDay(new Date(epochMs), now)
123
+ ? "Today"
124
+ : formatDatePreset(epochMs, "medium");
125
+ export const replacePerson = (people, person) => people.map((candidate) => candidate.userId === person.userId ? person : candidate);
@@ -2,8 +2,11 @@ import { AwsRum } from "aws-rum-web";
2
2
  import { getRuntimeConfig } from "../runtime-config";
3
3
  import { noopTelemetry } from "./telemetry";
4
4
  const ID_TOKEN_PATTERN = /([?&](token|access_token|id_token|authorization)=[^&]*)|\/messages\/[a-z0-9_-]+/gi;
5
+ const RESET_TOKEN_PATTERN = /\/reset-password\/[^/?#\s]+/gi;
5
6
  function scrubIds(value) {
6
- return value.replace(ID_TOKEN_PATTERN, "[redacted]");
7
+ return value
8
+ .replace(ID_TOKEN_PATTERN, "[redacted]")
9
+ .replace(RESET_TOKEN_PATTERN, "/reset-password/[redacted]");
7
10
  }
8
11
  function sanitizePath(path) {
9
12
  const qIndex = path.indexOf("?");