@oxy.so/services 14.18.1 → 14.19.0

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/lib/commonjs/ui/components/AccountLanguageBoundary.js +4 -2
  2. package/lib/commonjs/ui/components/AccountLanguageBoundary.js.map +1 -1
  3. package/lib/commonjs/ui/components/LanguageBridge.js +63 -22
  4. package/lib/commonjs/ui/components/LanguageBridge.js.map +1 -1
  5. package/lib/commonjs/ui/context/OxyHostedContext.js +18 -2
  6. package/lib/commonjs/ui/context/OxyHostedContext.js.map +1 -1
  7. package/lib/commonjs/ui/hooks/useLanguageManagement.js +40 -11
  8. package/lib/commonjs/ui/hooks/useLanguageManagement.js.map +1 -1
  9. package/lib/commonjs/ui/session/hostSession.js +14 -2
  10. package/lib/commonjs/ui/session/hostSession.js.map +1 -1
  11. package/lib/module/ui/components/AccountLanguageBoundary.js +4 -2
  12. package/lib/module/ui/components/AccountLanguageBoundary.js.map +1 -1
  13. package/lib/module/ui/components/LanguageBridge.js +64 -23
  14. package/lib/module/ui/components/LanguageBridge.js.map +1 -1
  15. package/lib/module/ui/context/OxyHostedContext.js +18 -2
  16. package/lib/module/ui/context/OxyHostedContext.js.map +1 -1
  17. package/lib/module/ui/hooks/useLanguageManagement.js +40 -11
  18. package/lib/module/ui/hooks/useLanguageManagement.js.map +1 -1
  19. package/lib/module/ui/session/hostSession.js +14 -2
  20. package/lib/module/ui/session/hostSession.js.map +1 -1
  21. package/lib/typescript/commonjs/ui/components/AccountLanguageBoundary.d.ts.map +1 -1
  22. package/lib/typescript/commonjs/ui/components/LanguageBridge.d.ts.map +1 -1
  23. package/lib/typescript/commonjs/ui/context/OxyHostedContext.d.ts +2 -1
  24. package/lib/typescript/commonjs/ui/context/OxyHostedContext.d.ts.map +1 -1
  25. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts +11 -6
  26. package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts.map +1 -1
  27. package/lib/typescript/commonjs/ui/hooks/useLanguageManagement.d.ts +11 -1
  28. package/lib/typescript/commonjs/ui/hooks/useLanguageManagement.d.ts.map +1 -1
  29. package/lib/typescript/commonjs/ui/session/hostSession.d.ts.map +1 -1
  30. package/lib/typescript/module/ui/components/AccountLanguageBoundary.d.ts.map +1 -1
  31. package/lib/typescript/module/ui/components/LanguageBridge.d.ts.map +1 -1
  32. package/lib/typescript/module/ui/context/OxyHostedContext.d.ts +2 -1
  33. package/lib/typescript/module/ui/context/OxyHostedContext.d.ts.map +1 -1
  34. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts +11 -6
  35. package/lib/typescript/module/ui/context/oxyContextTypes.d.ts.map +1 -1
  36. package/lib/typescript/module/ui/hooks/useLanguageManagement.d.ts +11 -1
  37. package/lib/typescript/module/ui/hooks/useLanguageManagement.d.ts.map +1 -1
  38. package/lib/typescript/module/ui/session/hostSession.d.ts.map +1 -1
  39. package/package.json +3 -3
  40. package/src/ui/components/AccountLanguageBoundary.tsx +3 -1
  41. package/src/ui/components/LanguageBridge.tsx +75 -23
  42. package/src/ui/components/__tests__/LanguageBridge.test.tsx +55 -0
  43. package/src/ui/context/OxyHostedContext.tsx +28 -2
  44. package/src/ui/context/oxyContextTypes.ts +11 -6
  45. package/src/ui/hooks/useLanguageManagement.ts +47 -12
  46. package/src/ui/session/hostSession.ts +18 -2
@@ -27,6 +27,13 @@ export interface UseLanguageManagementOptions {
27
27
  * `null` the device locale (or a locally-chosen guest override) is used.
28
28
  */
29
29
  user: User | null;
30
+ /**
31
+ * The platform's preferred languages, primary first, where the platform names
32
+ * them (a session host's `preferredLanguages`, ADR 0058 R11). When present
33
+ * they are the app's language, signed in or out, and ready from the first
34
+ * render: neither the account, the guest override nor storage is waited for.
35
+ */
36
+ platformLanguages?: readonly string[] | null;
30
37
  onError?: (error: ApiError) => void;
31
38
  logger?: (message: string, error?: unknown) => void;
32
39
  }
@@ -91,6 +98,21 @@ export function setPrimaryLocale(languages: readonly string[], locale: string):
91
98
  return [canonical, ...languages.filter((entry) => entry !== canonical)];
92
99
  }
93
100
 
101
+ /**
102
+ * The first of `candidates` that resolves to a supported catalog locale, either
103
+ * exactly or by base-language match (`fr-BE` → `fr-FR`), or `undefined`.
104
+ */
105
+ function firstSupportedLocale(candidates: readonly string[]): string | undefined {
106
+ for (const candidate of candidates) {
107
+ const exact = normalizeLocale(candidate);
108
+ if (exact) return exact;
109
+ const base = getBaseLanguage(candidate);
110
+ const byBase = SUPPORTED_LANGUAGES.find((entry) => entry.language === base);
111
+ if (byBase) return byBase.code;
112
+ }
113
+ return undefined;
114
+ }
115
+
94
116
  /**
95
117
  * Resolve the device/browser locale, mapped to a supported catalog locale.
96
118
  *
@@ -123,15 +145,7 @@ function resolveDeviceLocale(): string {
123
145
  // navigator-provided candidates (or the fallback locale below).
124
146
  }
125
147
 
126
- for (const candidate of candidates) {
127
- const exact = normalizeLocale(candidate);
128
- if (exact) return exact;
129
- const base = getBaseLanguage(candidate);
130
- const byBase = SUPPORTED_LANGUAGES.find((entry) => entry.language === base);
131
- if (byBase) return byBase.code;
132
- }
133
-
134
- return FALLBACK_LOCALE;
148
+ return firstSupportedLocale(candidates) ?? FALLBACK_LOCALE;
135
149
  }
136
150
 
137
151
  /**
@@ -143,6 +157,9 @@ function resolveDeviceLocale(): string {
143
157
  * follow the account's language automatically.
144
158
  * - Signed out → a locally-chosen guest override if one exists, otherwise the
145
159
  * device locale.
160
+ * - On a platform that names its preferred languages (ADR 0058 R11) → those,
161
+ * signed in or out, from the first render, as a Mac app follows the
162
+ * system's preferred languages.
146
163
  *
147
164
  * The only external system this hook synchronizes with is local storage (the
148
165
  * guest override), which is loaded once on mount.
@@ -154,6 +171,7 @@ export const useLanguageManagement = ({
154
171
  entryLinkReady = true,
155
172
  legacyLanguageKeys,
156
173
  user,
174
+ platformLanguages = null,
157
175
  onError,
158
176
  logger,
159
177
  }: UseLanguageManagementOptions): UseLanguageManagementResult => {
@@ -279,19 +297,36 @@ export const useLanguageManagement = ({
279
297
 
280
298
  const setLanguage = useCallback((locale: string) => setLanguages([locale]), [setLanguages]);
281
299
 
300
+ // The platform's languages as supported locales, primary first; `null` where
301
+ // the platform names none. Keyed by value: a new snapshot of the same
302
+ // languages changes nothing.
303
+ const platformKey = platformLanguages ? JSON.stringify(platformLanguages) : null;
304
+ const platform = useMemo<string[] | null>(() => {
305
+ if (platformKey === null) return null;
306
+ const tags: string[] = JSON.parse(platformKey);
307
+ const supported = tags.flatMap((tag) => firstSupportedLocale([tag]) ?? []);
308
+ return supported.length ? [...new Set(supported)] : [FALLBACK_LOCALE];
309
+ }, [platformKey]);
310
+
282
311
  const languages = useMemo<string[]>(() => {
312
+ if (platform) {
313
+ return platform;
314
+ }
283
315
  if (user) {
284
316
  return getUserLanguages(user);
285
317
  }
286
318
  return guestLanguages;
287
- }, [user, guestLanguages]);
319
+ }, [platform, user, guestLanguages]);
288
320
 
289
321
  const currentLanguage = useMemo<string>(() => {
322
+ if (platform) {
323
+ return platform[0] ?? FALLBACK_LOCALE;
324
+ }
290
325
  if (user) {
291
326
  return getPrimaryLanguage(user) ?? FALLBACK_LOCALE;
292
327
  }
293
328
  return guestLanguages[0] ?? deviceLanguage;
294
- }, [user, guestLanguages, deviceLanguage]);
329
+ }, [platform, user, guestLanguages, deviceLanguage]);
295
330
 
296
331
  const metadata = useMemo(() => getLanguageMetadata(currentLanguage), [currentLanguage]);
297
332
  const languageName = useMemo(() => getLanguageName(currentLanguage), [currentLanguage]);
@@ -302,7 +337,7 @@ export const useLanguageManagement = ({
302
337
 
303
338
  return {
304
339
  currentLanguage,
305
- isLanguageReady,
340
+ isLanguageReady: platform !== null || isLanguageReady,
306
341
  languages,
307
342
  metadata,
308
343
  languageName,
@@ -107,6 +107,15 @@ function validAccount(account: unknown): OxyHostAccount | null {
107
107
  };
108
108
  }
109
109
 
110
+ /** The platform's preferred languages (R11): the non-empty tags, or none at all. */
111
+ function validPreferredLanguages(languages: unknown): { preferredLanguages?: string[] } {
112
+ if (!Array.isArray(languages)) return {};
113
+ const kept = languages.filter(
114
+ (language): language is string => typeof language === 'string' && language !== '',
115
+ );
116
+ return kept.length > 0 ? { preferredLanguages: kept } : {};
117
+ }
118
+
110
119
  /**
111
120
  * The host's snapshot, checked. A host that throws or answers something that is
112
121
  * not a snapshot is `unavailable` — signed out, never a reason to sign in here.
@@ -124,13 +133,20 @@ export function readHostSnapshot(host: OxySessionHost): OxyHostSnapshot {
124
133
  return UNAVAILABLE;
125
134
  }
126
135
  const online = candidate.online === true;
136
+ const preferred = validPreferredLanguages(candidate.preferredLanguages);
127
137
  if (candidate.status === 'signed_in') {
128
138
  const account = validAccount(candidate.account);
129
139
  if (!account) return UNAVAILABLE;
130
- return { status: 'signed_in', revision: candidate.revision, account, online };
140
+ return { status: 'signed_in', revision: candidate.revision, account, online, ...preferred };
131
141
  }
132
142
  if (candidate.status === 'signed_out' || candidate.status === 'unavailable') {
133
- return { status: candidate.status, revision: candidate.revision, account: null, online };
143
+ return {
144
+ status: candidate.status,
145
+ revision: candidate.revision,
146
+ account: null,
147
+ online,
148
+ ...preferred,
149
+ };
134
150
  }
135
151
  return UNAVAILABLE;
136
152
  }