@connextar/house 0.24.0 → 0.25.1

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 (65) hide show
  1. package/README.md +62 -13
  2. package/dist/account/data-contract.d.ts +20 -0
  3. package/dist/account/data-contract.d.ts.map +1 -1
  4. package/dist/account/data-contract.js +17 -3
  5. package/dist/account/data-contract.js.map +1 -1
  6. package/dist/account/index.d.ts +1 -1
  7. package/dist/account/index.d.ts.map +1 -1
  8. package/dist/account/index.js +1 -1
  9. package/dist/account/index.js.map +1 -1
  10. package/dist/admin/access.d.ts +22 -2
  11. package/dist/admin/access.d.ts.map +1 -1
  12. package/dist/admin/access.js +35 -7
  13. package/dist/admin/access.js.map +1 -1
  14. package/dist/admin/index.d.ts +1 -1
  15. package/dist/admin/index.d.ts.map +1 -1
  16. package/dist/admin/index.js +1 -1
  17. package/dist/admin/index.js.map +1 -1
  18. package/dist/admin/second-factor-index.d.ts +1 -1
  19. package/dist/admin/second-factor-index.d.ts.map +1 -1
  20. package/dist/admin/second-factor-index.js.map +1 -1
  21. package/dist/admin/second-factor.d.ts +17 -6
  22. package/dist/admin/second-factor.d.ts.map +1 -1
  23. package/dist/admin/second-factor.js +5 -3
  24. package/dist/admin/second-factor.js.map +1 -1
  25. package/dist/admin/view-as.d.ts +12 -3
  26. package/dist/admin/view-as.d.ts.map +1 -1
  27. package/dist/admin/view-as.js +6 -2
  28. package/dist/admin/view-as.js.map +1 -1
  29. package/dist/analytics/posthog-extensions.d.ts +2 -0
  30. package/dist/analytics/posthog-extensions.d.ts.map +1 -1
  31. package/dist/analytics/posthog-extensions.js +2 -0
  32. package/dist/analytics/posthog-extensions.js.map +1 -1
  33. package/dist/auth/step-up-index.d.ts +1 -1
  34. package/dist/auth/step-up-index.d.ts.map +1 -1
  35. package/dist/auth/step-up-index.js.map +1 -1
  36. package/dist/auth/step-up.d.ts +22 -0
  37. package/dist/auth/step-up.d.ts.map +1 -1
  38. package/dist/auth/step-up.js +8 -6
  39. package/dist/auth/step-up.js.map +1 -1
  40. package/dist/whats-new/index.d.ts +1 -1
  41. package/dist/whats-new/index.d.ts.map +1 -1
  42. package/dist/whats-new/index.js +1 -1
  43. package/dist/whats-new/index.js.map +1 -1
  44. package/dist/whats-new/use-whats-new.d.ts +7 -1
  45. package/dist/whats-new/use-whats-new.d.ts.map +1 -1
  46. package/dist/whats-new/use-whats-new.js +10 -6
  47. package/dist/whats-new/use-whats-new.js.map +1 -1
  48. package/dist/words.d.ts +12 -0
  49. package/dist/words.d.ts.map +1 -0
  50. package/dist/words.js +17 -0
  51. package/dist/words.js.map +1 -0
  52. package/package.json +2 -2
  53. package/src/account/data-contract.ts +34 -4
  54. package/src/account/index.ts +3 -0
  55. package/src/admin/access.ts +50 -9
  56. package/src/admin/index.ts +2 -0
  57. package/src/admin/second-factor-index.ts +1 -0
  58. package/src/admin/second-factor.ts +19 -5
  59. package/src/admin/view-as.ts +20 -4
  60. package/src/analytics/posthog-extensions.ts +2 -0
  61. package/src/auth/step-up-index.ts +1 -1
  62. package/src/auth/step-up.ts +28 -6
  63. package/src/whats-new/index.ts +1 -1
  64. package/src/whats-new/use-whats-new.ts +13 -6
  65. package/src/words.ts +16 -0
@@ -1,3 +1,4 @@
1
+ import { fillWords } from "../words.js";
1
2
  import { DEFAULT_ADMIN_PROOF_PREFIX, sessionProofReader, type AuthWithProofs } from "./proof.js";
2
3
 
3
4
  /**
@@ -61,25 +62,49 @@ export interface AdminRefusalWording {
61
62
  fixHref?: string | null;
62
63
  }
63
64
 
64
- /** Per reason, the words and the link an app wants instead of the house's. */
65
- export type AdminRefusalWords = Partial<Record<AdminRefusalReason, AdminRefusalWording>>;
65
+ /**
66
+ * The places only the app knows, which the house's sentences and links name through placeholders. Set them once
67
+ * rather than rewriting whole sentences; an app's own `message` or `fixHref` may use the same placeholders.
68
+ */
69
+ export interface AdminPlaces {
70
+ /** Where two-factor is turned on, as the app's screens name it: "Settings › Account & security". `{securitySettings}`. */
71
+ securitySettings?: string;
72
+ /** That screen's address: "/settings?tab=security#two-factor". `{securitySettingsHref}`. */
73
+ securitySettingsHref?: string;
74
+ /** The sign-in page: "/login". `{signInHref}`. */
75
+ signInHref?: string;
76
+ }
77
+
78
+ export const DEFAULT_ADMIN_PLACES: Required<AdminPlaces> = {
79
+ securitySettings: "your account’s security settings",
80
+ securitySettingsHref: "/settings#two-factor",
81
+ signInHref: "/sign-in",
82
+ };
83
+
84
+ /** Per reason, the words and the link an app wants instead of the house's, and the places its sentences name. */
85
+ export type AdminRefusalWords = Partial<Record<AdminRefusalReason, AdminRefusalWording>> & { places?: AdminPlaces };
66
86
 
87
+ /**
88
+ * The house's sentences and links, as templates. `{securitySettings}`, `{securitySettingsHref}` and `{signInHref}`
89
+ * are filled from `words.places`. The two links to the security settings also carry `?admin=<reason>`, so the page
90
+ * can say why the person was sent there (`adminRefusalFromParam`).
91
+ */
67
92
  export const DEFAULT_ADMIN_REFUSAL_WORDS: Record<AdminRefusalReason, Required<AdminRefusalWording>> = {
68
- "signed-out": { message: "Sign in to use administration.", fixHref: "/sign-in" },
93
+ "signed-out": { message: "Sign in to use administration.", fixHref: "{signInHref}" },
69
94
  "session-ended": {
70
95
  message: "This sign-in has ended. Sign in again to use administration.",
71
- fixHref: "/sign-in",
96
+ fixHref: "{signInHref}",
72
97
  },
73
98
  "not-admin": { message: "Only an administrator can do that.", fixHref: null },
74
99
  "two-factor-off": {
75
100
  message:
76
- "Administration needs two-factor authentication on your account. Turn it on in Settings › Account & security, then come back.",
77
- fixHref: "/settings?admin=two-factor-off#two-factor",
101
+ "Administration needs two-factor authentication on your account. Turn it on in {securitySettings}, then come back.",
102
+ fixHref: "{securitySettingsHref}",
78
103
  },
79
104
  "sign-in-without-second-factor": {
80
105
  message:
81
106
  "Administration needs a sign-in that used your authenticator code or a passkey, and this one didn’t. Sign out, then sign in with your email, password and code — or with a passkey.",
82
- fixHref: "/settings?admin=sign-in-without-second-factor#two-factor",
107
+ fixHref: "{securitySettingsHref}",
83
108
  },
84
109
  "viewing-as": {
85
110
  message: "You’re viewing as somebody else. Stop viewing as them to use administration.",
@@ -87,6 +112,16 @@ export const DEFAULT_ADMIN_REFUSAL_WORDS: Record<AdminRefusalReason, Required<Ad
87
112
  },
88
113
  };
89
114
 
115
+ const SENT_TO_SETTINGS = new Set<AdminRefusalReason>(["two-factor-off", "sign-in-without-second-factor"]);
116
+
117
+ /** `href` with `admin=<reason>` added to its query, before any `#fragment`. */
118
+ function withAdminParam(href: string, reason: AdminRefusalReason): string {
119
+ const hash = href.indexOf("#");
120
+ const path = hash === -1 ? href : href.slice(0, hash);
121
+ const fragment = hash === -1 ? "" : href.slice(hash);
122
+ return `${path}${path.includes("?") ? "&" : "?"}admin=${encodeURIComponent(reason)}${fragment}`;
123
+ }
124
+
90
125
  const STATUS: Record<AdminRefusalReason, 401 | 403> = {
91
126
  "signed-out": 401,
92
127
  "session-ended": 401,
@@ -100,11 +135,17 @@ const STATUS: Record<AdminRefusalReason, 401 | 403> = {
100
135
  export function adminRefusal(reason: AdminRefusalReason, words: AdminRefusalWords = {}): AdminRefusal {
101
136
  const own = words[reason];
102
137
  const fallback = DEFAULT_ADMIN_REFUSAL_WORDS[reason];
138
+ const places: Record<string, string> = { ...DEFAULT_ADMIN_PLACES };
139
+ for (const [key, value] of Object.entries(words.places ?? {})) if (value?.trim()) places[key] = value.trim();
140
+ const ownHref = own && "fixHref" in own && own.fixHref !== undefined;
141
+ const href = ownHref ? own.fixHref! : fallback.fixHref;
142
+ let fixHref = href === null ? null : fillWords(href, places);
143
+ if (fixHref !== null && !ownHref && SENT_TO_SETTINGS.has(reason)) fixHref = withAdminParam(fixHref, reason);
103
144
  return {
104
145
  ok: false,
105
146
  reason,
106
- message: own?.message ?? fallback.message,
107
- fixHref: own && "fixHref" in own && own.fixHref !== undefined ? own.fixHref : fallback.fixHref,
147
+ message: fillWords(own?.message ?? fallback.message, places),
148
+ fixHref,
108
149
  status: STATUS[reason],
109
150
  };
110
151
  }
@@ -8,6 +8,7 @@
8
8
  export {
9
9
  ADMIN_REFUSAL_REASONS,
10
10
  AdminRefusalError,
11
+ DEFAULT_ADMIN_PLACES,
11
12
  DEFAULT_ADMIN_REFUSAL_WORDS,
12
13
  adminAccess,
13
14
  adminRefusal,
@@ -19,6 +20,7 @@ export {
19
20
  type AdminAccessFacts,
20
21
  type AdminAccessLookups,
21
22
  type AdminAccessOptions,
23
+ type AdminPlaces,
22
24
  type AdminRefusal,
23
25
  type AdminRefusalReason,
24
26
  type AdminRefusalWording,
@@ -10,6 +10,7 @@ export {
10
10
  ADMIN_SECOND_FACTOR_SESSIONS_ID,
11
11
  ADMIN_TWO_FACTOR_CHANGE_PATHS,
12
12
  adminSecondFactorSessions,
13
+ type AdminFactorChange,
13
14
  type AdminSecondFactorSessionsOptions,
14
15
  type AdminSignIn,
15
16
  } from "./second-factor.js";
@@ -80,8 +80,20 @@ export interface AdminSecondFactorSessionsOptions {
80
80
  standing?: string;
81
81
  /** The sign-in event's scope. Default platform. */
82
82
  scope?: AdminAuditScope;
83
- /** The refusals' words. */
84
- messages?: { factorChange?: string; passkeyNeedsTwoFactor?: string };
83
+ /**
84
+ * The refusals' words. Each is a sentence, or a function of the refused route for an app that says which change
85
+ * was refused — FB Web re-threw the plugin's error in its own words until it could.
86
+ */
87
+ messages?: {
88
+ factorChange?: string | ((refused: AdminFactorChange) => string);
89
+ passkeyNeedsTwoFactor?: string | ((refused: AdminFactorChange) => string);
90
+ };
91
+ }
92
+
93
+ /** The route a factor-change refusal is for: adding a passkey, or reading or changing two-factor. */
94
+ export interface AdminFactorChange {
95
+ path: string;
96
+ factor: "passkey" | "two-factor";
85
97
  }
86
98
 
87
99
  export interface AdminSignIn {
@@ -289,10 +301,12 @@ export function adminSecondFactorSessions(options: AdminSecondFactorSessionsOpti
289
301
  addsPasskey && !twoFactorOn
290
302
  ? ADMIN_SECOND_FACTOR_ERROR_CODES.ADMIN_PASSKEY_NEEDS_TWO_FACTOR
291
303
  : ADMIN_SECOND_FACTOR_ERROR_CODES.ADMIN_SECOND_FACTOR_REQUIRED;
292
- const message =
304
+ const refused: AdminFactorChange = { path: ctx.path, factor: addsPasskey ? "passkey" : "two-factor" };
305
+ const words =
293
306
  refusal.code === "ADMIN_PASSKEY_NEEDS_TWO_FACTOR"
294
- ? (options.messages?.passkeyNeedsTwoFactor ?? refusal.message)
295
- : (options.messages?.factorChange ?? refusal.message);
307
+ ? options.messages?.passkeyNeedsTwoFactor
308
+ : options.messages?.factorChange;
309
+ const message = (typeof words === "function" ? words(refused) : words)?.trim() || refusal.message;
296
310
  throw new APIError("FORBIDDEN", { code: refusal.code, message });
297
311
  }),
298
312
  };
@@ -1,5 +1,6 @@
1
1
  import { createHmac, timingSafeEqual } from "node:crypto";
2
2
 
3
+ import { fillWords } from "../words.js";
3
4
  import { AdminRefusalError, adminRefusal, type AdminAccess, type AdminRefusal } from "./access.js";
4
5
  import {
5
6
  emitSafely,
@@ -336,8 +337,17 @@ export interface MaybeViewing {
336
337
  */
337
338
  export interface ViewingAsWords {
338
339
  appName?: string;
339
- /** The whole sentence. `name` is null when the view's person has no name to give. */
340
- message?: (refusal: { name: string | null; what: string; appName: string | null }) => string;
340
+ /**
341
+ * The whole sentence: a template with `{app}`, `{name}` and `{what}` — "You are viewing {app} as {name}. Stop
342
+ * viewing as them before {what}." — or a function for anything a template can't say. `name` is "somebody else"
343
+ * in a template, and null to a function, when the view's person has no name to give.
344
+ */
345
+ message?: string | ((refusal: { name: string | null; what: string; appName: string | null }) => string);
346
+ /**
347
+ * When whether the request is a view can't be told (the lookup threw), the request is refused. Template with
348
+ * `{what}`; default "Could not tell whether this request is a “view as”, so {what} was refused."
349
+ */
350
+ undetermined?: string;
341
351
  }
342
352
 
343
353
  export interface RefuseWhileViewingAsOptions extends ViewingAsWords {
@@ -348,7 +358,10 @@ export interface RefuseWhileViewingAsOptions extends ViewingAsWords {
348
358
  /** The sentence a refusal under "view as" says — the house's, with the app's name, or the app's own. */
349
359
  export function viewingAsMessage(name: string | null | undefined, what: string, words: ViewingAsWords = {}): string {
350
360
  const appName = words.appName?.trim() || null;
351
- if (words.message) return words.message({ name: name || null, what, appName });
361
+ if (typeof words.message === "function") return words.message({ name: name || null, what, appName });
362
+ if (typeof words.message === "string" && words.message.trim()) {
363
+ return fillWords(words.message, { app: appName ?? "", name: name || "somebody else", what });
364
+ }
352
365
  const viewing = appName ? `viewing ${appName} as` : "viewing as";
353
366
  return `You’re ${viewing} ${name || "somebody else"}. Stop viewing as them before ${what}.`;
354
367
  }
@@ -414,7 +427,10 @@ export function viewingAsGate(options: ViewingAsGateOptions): ViewingAsGate {
414
427
  try {
415
428
  viewing = await lookup();
416
429
  } catch (error) {
417
- const message = `Could not tell whether this request is a “view as”, so ${what} was refused.`;
430
+ const message = fillWords(
431
+ options.undetermined?.trim() || "Could not tell whether this request is a “view as”, so {what} was refused.",
432
+ { what },
433
+ );
418
434
  if (options.makeError) throw options.makeError(message);
419
435
  throw new AdminRefusalError(adminRefusal("viewing-as", { "viewing-as": { message } }), { cause: error });
420
436
  }
@@ -12,6 +12,8 @@
12
12
  * all. Found in PharmaLine 0.27.5: a platform admin's changelog still fetched both scripts from `/ingest/static/`.
13
13
  *
14
14
  * They are the app's posthog-js (an optional peer), so the extensions always match the version that loads them.
15
+ * The peer's floor is 1.434: up to 1.383, posthog-js fetches each script even when it is already registered, so this
16
+ * import would change nothing (five apps on 1.300–1.383 found that in the 0.25.0 rollout).
15
17
  */
16
18
  import "posthog-js/dist/exception-autocapture.js";
17
19
  import "posthog-js/dist/dead-clicks-autocapture.js";
@@ -3,7 +3,7 @@
3
3
  * entry point stays free of any Better Auth import and safe for client components; the client plugin is
4
4
  * `@connextar/house/auth/step-up/client`.
5
5
  */
6
- export { stepUp, type PasskeyAddedData, type StepUpOptions } from "./step-up.js";
6
+ export { stepUp, type PasskeyAddedData, type StepUpMessages, type StepUpOptions } from "./step-up.js";
7
7
  export {
8
8
  DEFAULT_STEP_UP_MAX_ATTEMPTS,
9
9
  DEFAULT_STEP_UP_WINDOW_SECONDS,
@@ -77,6 +77,24 @@ export interface StepUpOptions {
77
77
  * passkey stays. With Better Auth's `advanced.backgroundTasks` set, it runs in the background.
78
78
  */
79
79
  onPasskeyAdded?: (data: PasskeyAddedData) => Promise<void> | void;
80
+ /**
81
+ * The refusals' words, where the app's differ. Each replaces one sentence; the codes stay the same, so the app's
82
+ * client still tells them apart by `code`.
83
+ */
84
+ messages?: StepUpMessages;
85
+ }
86
+
87
+ export interface StepUpMessages {
88
+ /** A passkey route refused for want of a recent confirmation. Default "Confirm it's you before adding a passkey." */
89
+ requiredForPasskey?: string;
90
+ /** Any other guarded route refused for want of one. */
91
+ required?: string;
92
+ /** Too many wrong codes and passwords this session. */
93
+ locked?: string;
94
+ /** A password offered by an account that confirms with its code. */
95
+ useCode?: string;
96
+ /** A password offered by an account that has none. */
97
+ noPassword?: string;
80
98
  }
81
99
 
82
100
  export interface PasskeyAddedData {
@@ -133,6 +151,10 @@ export function stepUp(options: StepUpOptions = {}) {
133
151
  const routes = new Set<string>(options.routes ?? STEP_UP_PASSKEY_ROUTES);
134
152
  const passkeyRoutes: readonly string[] = STEP_UP_PASSKEY_ROUTES;
135
153
  const codeRoutes: readonly string[] = STEP_UP_CODE_ROUTES;
154
+ const said: StepUpMessages = Object.fromEntries(
155
+ Object.entries(options.messages ?? {}).map(([key, value]) => [key, value?.trim() || undefined]),
156
+ );
157
+ const lockedWords = said.locked ? { message: said.locked } : {};
136
158
 
137
159
  if (!Number.isFinite(windowSeconds) || windowSeconds <= 0) {
138
160
  throw new Error(`[step-up] windowSeconds must be a positive number of seconds, got ${String(windowSeconds)}.`);
@@ -243,8 +265,8 @@ export function stepUp(options: StepUpOptions = {}) {
243
265
  throw new APIError("FORBIDDEN", {
244
266
  code: STEP_UP_ERROR_CODES.STEP_UP_REQUIRED.code,
245
267
  message: passkeyRoutes.includes(ctx.path)
246
- ? STEP_UP_ERROR_CODES.STEP_UP_REQUIRED.message
247
- : STEP_UP_REQUIRED_GENERIC_MESSAGE,
268
+ ? said.requiredForPasskey || STEP_UP_ERROR_CODES.STEP_UP_REQUIRED.message
269
+ : said.required || STEP_UP_REQUIRED_GENERIC_MESSAGE,
248
270
  needs: status.needs,
249
271
  });
250
272
  }),
@@ -257,7 +279,7 @@ export function stepUp(options: StepUpOptions = {}) {
257
279
  // No live session: a sign-in finishing with its code. Two-factor off: enrolment. Neither confirms anything.
258
280
  if (!live || live.user.twoFactorEnabled !== true) return;
259
281
  if ((await attemptsUsed(ctx.context, live.session.id)) >= maxAttempts) {
260
- throw new APIError("FORBIDDEN", { ...STEP_UP_ERROR_CODES.STEP_UP_LOCKED, needs: "code" });
282
+ throw new APIError("FORBIDDEN", { ...STEP_UP_ERROR_CODES.STEP_UP_LOCKED, ...lockedWords, needs: "code" });
261
283
  }
262
284
  pending.set(ctx.context, { session: live.session });
263
285
  }),
@@ -394,13 +416,13 @@ export function stepUp(options: StepUpOptions = {}) {
394
416
  code: STEP_UP_ERROR_CODES.STEP_UP_PASSWORD_NOT_ACCEPTED.code,
395
417
  message:
396
418
  needs === "code"
397
- ? "Enter the code from your authenticator app instead."
398
- : "This account has no password. Sign in again to confirm it's you.",
419
+ ? said.useCode || "Enter the code from your authenticator app instead."
420
+ : said.noPassword || "This account has no password. Sign in again to confirm it's you.",
399
421
  needs,
400
422
  });
401
423
  }
402
424
  if ((await attemptsUsed(ctx.context, live.session.id)) >= maxAttempts) {
403
- throw new APIError("FORBIDDEN", { ...STEP_UP_ERROR_CODES.STEP_UP_LOCKED, needs });
425
+ throw new APIError("FORBIDDEN", { ...STEP_UP_ERROR_CODES.STEP_UP_LOCKED, ...lockedWords, needs });
404
426
  }
405
427
  try {
406
428
  // Better Auth's own check: the credential account's hash, its configured verifier, a constant-time
@@ -40,4 +40,4 @@ export {
40
40
  type WhatsNewLinkProps,
41
41
  type WhatsNewTitleProps,
42
42
  } from "./body.js";
43
- export { useWhatsNew, type UseWhatsNewOptions, type WhatsNew } from "./use-whats-new.js";
43
+ export { WHATS_NEW_SAVE_LABELS, useWhatsNew, type UseWhatsNewOptions, type WhatsNew } from "./use-whats-new.js";
@@ -16,8 +16,15 @@ export interface UseWhatsNewOptions {
16
16
  markSeen: (version: string) => Promise<boolean>;
17
17
  /** Somebody viewing as this person: never opens, never stores. */
18
18
  readOnly?: boolean;
19
+ /** What the person is told when storing fails, where the app's words differ. */
20
+ labels?: Partial<typeof WHATS_NEW_SAVE_LABELS>;
19
21
  }
20
22
 
23
+ export const WHATS_NEW_SAVE_LABELS = {
24
+ saveFailedTitle: "Couldn't save that you've seen what's new",
25
+ saveFailedText: "It may show again next time you visit.",
26
+ };
27
+
21
28
  export interface WhatsNew {
22
29
  open: boolean;
23
30
  /** For the dialog's `onOpenChange`. Closing it any way — Escape, a click outside — counts as seen. */
@@ -40,7 +47,7 @@ export interface WhatsNew {
40
47
  * through the app's `ActionFeedbackProvider`, and the dialog stays closed for
41
48
  * this visit rather than coming back to ask again.
42
49
  */
43
- export function useWhatsNew({ initial, markSeen, readOnly = false }: UseWhatsNewOptions): WhatsNew {
50
+ export function useWhatsNew({ initial, markSeen, readOnly = false, labels }: UseWhatsNewOptions): WhatsNew {
44
51
  const report = useActionReporter();
45
52
  const [open, setOpenState] = React.useState(false);
46
53
  const isOpen = React.useRef(false);
@@ -48,13 +55,13 @@ export function useWhatsNew({ initial, markSeen, readOnly = false }: UseWhatsNew
48
55
  const stored = React.useRef(false);
49
56
 
50
57
  // Read through a ref so the callbacks below keep one identity across renders.
51
- const latest = React.useRef({ initial, markSeen, readOnly, report });
58
+ const latest = React.useRef({ initial, markSeen, readOnly, report, labels });
52
59
  React.useEffect(() => {
53
- latest.current = { initial, markSeen, readOnly, report };
60
+ latest.current = { initial, markSeen, readOnly, report, labels };
54
61
  });
55
62
 
56
63
  const store = React.useCallback(async (quietly: boolean) => {
57
- const { initial: data, markSeen: save, readOnly: viewingAs, report: tell } = latest.current;
64
+ const { initial: data, markSeen: save, readOnly: viewingAs, report: tell, labels: own } = latest.current;
58
65
  if (!data || viewingAs || stored.current) return;
59
66
  stored.current = true;
60
67
  let saved = false;
@@ -69,8 +76,8 @@ export function useWhatsNew({ initial, markSeen, readOnly = false }: UseWhatsNew
69
76
  if (quietly) return;
70
77
  tell({
71
78
  tone: "error",
72
- title: "Couldn't save that you've seen what's new",
73
- description: "It may show again next time you visit.",
79
+ title: own?.saveFailedTitle || WHATS_NEW_SAVE_LABELS.saveFailedTitle,
80
+ description: own?.saveFailedText || WHATS_NEW_SAVE_LABELS.saveFailedText,
74
81
  });
75
82
  }, []);
76
83
 
package/src/words.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The house's wording convention: a default sentence that names something only the app knows — its name, the
3
+ * place its settings live, what its records are called — is a template with `{placeholders}`, and the app fills
4
+ * them. An app never rewrites the house's text after the fact: Quickie matched the view-as refusal with a regex,
5
+ * and FB Web re-threw the second-factor refusal in its own words, and either would have stopped working, silently,
6
+ * at the first changed character.
7
+ *
8
+ * `{name}` is replaced when `values` has `name`; a placeholder with no value is left as written, so a missing word
9
+ * shows up in a test rather than as an empty gap in a sentence.
10
+ */
11
+ export function fillWords(template: string, values: Readonly<Record<string, string | null | undefined>>): string {
12
+ return template.replace(/\{([a-zA-Z][a-zA-Z0-9]*)\}/g, (whole, key: string) => {
13
+ const value = values[key];
14
+ return typeof value === "string" ? value : whole;
15
+ });
16
+ }