@oxy.so/services 14.16.0 → 14.18.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.
- package/lib/commonjs/ui/components/LanguageBridge.js +7 -3
- package/lib/commonjs/ui/components/LanguageBridge.js.map +1 -1
- package/lib/commonjs/ui/components/setupFlow/OxySetupFlow.js +2 -1
- package/lib/commonjs/ui/components/setupFlow/OxySetupFlow.js.map +1 -1
- package/lib/commonjs/ui/context/OxyContext.js +1 -0
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/context/OxyHostedContext.js +28 -2
- package/lib/commonjs/ui/context/OxyHostedContext.js.map +1 -1
- package/lib/commonjs/ui/hooks/useI18n.js +4 -2
- package/lib/commonjs/ui/hooks/useI18n.js.map +1 -1
- package/lib/commonjs/ui/session/hostSession.js +11 -2
- package/lib/commonjs/ui/session/hostSession.js.map +1 -1
- package/lib/module/ui/components/LanguageBridge.js +7 -3
- package/lib/module/ui/components/LanguageBridge.js.map +1 -1
- package/lib/module/ui/components/setupFlow/OxySetupFlow.js +2 -1
- package/lib/module/ui/components/setupFlow/OxySetupFlow.js.map +1 -1
- package/lib/module/ui/context/OxyContext.js +1 -0
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/context/OxyHostedContext.js +29 -3
- package/lib/module/ui/context/OxyHostedContext.js.map +1 -1
- package/lib/module/ui/hooks/useI18n.js +4 -2
- package/lib/module/ui/hooks/useI18n.js.map +1 -1
- package/lib/module/ui/session/hostSession.js +11 -2
- package/lib/module/ui/session/hostSession.js.map +1 -1
- package/lib/typescript/commonjs/ui/components/LanguageBridge.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/setupFlow/OxySetupFlow.d.ts +6 -0
- package/lib/typescript/commonjs/ui/components/setupFlow/OxySetupFlow.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/context/OxyHostedContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts +8 -0
- package/lib/typescript/commonjs/ui/context/oxyContextTypes.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useI18n.d.ts +1 -1
- package/lib/typescript/commonjs/ui/hooks/useI18n.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/session/hostSession.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/LanguageBridge.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/setupFlow/OxySetupFlow.d.ts +6 -0
- package/lib/typescript/module/ui/components/setupFlow/OxySetupFlow.d.ts.map +1 -1
- package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/module/ui/context/OxyHostedContext.d.ts.map +1 -1
- package/lib/typescript/module/ui/context/oxyContextTypes.d.ts +8 -0
- package/lib/typescript/module/ui/context/oxyContextTypes.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useI18n.d.ts +1 -1
- package/lib/typescript/module/ui/hooks/useI18n.d.ts.map +1 -1
- package/lib/typescript/module/ui/session/hostSession.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/ui/components/LanguageBridge.tsx +6 -3
- package/src/ui/components/__tests__/LanguageBridge.test.tsx +17 -0
- package/src/ui/components/setupFlow/OxySetupFlow.tsx +8 -1
- package/src/ui/components/setupFlow/__tests__/OxySetupFlow.test.tsx +6 -0
- package/src/ui/context/OxyContext.tsx +1 -0
- package/src/ui/context/OxyHostedContext.tsx +43 -3
- package/src/ui/context/oxyContextTypes.ts +8 -0
- package/src/ui/hooks/useI18n.ts +4 -2
- package/src/ui/session/hostSession.ts +15 -1
|
@@ -93,6 +93,12 @@ export interface OxySetupFlowProps {
|
|
|
93
93
|
/** Back is offered on the current step only when this is given. */
|
|
94
94
|
onBack?: () => void;
|
|
95
95
|
/** Default: the SDK's own "Back". */
|
|
96
|
+
/**
|
|
97
|
+
* The language the flow's own words speak (its progress, its announcements, the default Back),
|
|
98
|
+
* a BCP 47 tag. A platform's setup passes its system's: the flow then stays in it after the
|
|
99
|
+
* sign-in, when the runtime turns to the account's own language. Default: the runtime's.
|
|
100
|
+
*/
|
|
101
|
+
locale?: string;
|
|
96
102
|
backLabel?: string;
|
|
97
103
|
/** "Step 2 of 5" and the dots. Default `true`. */
|
|
98
104
|
showProgress?: boolean;
|
|
@@ -181,10 +187,11 @@ export const OxySetupFlow: React.FC<OxySetupFlowProps> = ({
|
|
|
181
187
|
current,
|
|
182
188
|
onBack,
|
|
183
189
|
backLabel,
|
|
190
|
+
locale,
|
|
184
191
|
showProgress = true,
|
|
185
192
|
onMaxWidthChange,
|
|
186
193
|
}) => {
|
|
187
|
-
const { t } = useI18n();
|
|
194
|
+
const { t } = useI18n(locale);
|
|
188
195
|
const theme = useTheme();
|
|
189
196
|
const reducedMotion = usePrefersReducedMotion();
|
|
190
197
|
const index = steps.findIndex((candidate) => candidate.id === current);
|
|
@@ -208,6 +208,12 @@ describe('progress', () => {
|
|
|
208
208
|
expect(dots.getAttribute('data-count')).toBe('4');
|
|
209
209
|
});
|
|
210
210
|
|
|
211
|
+
it('speaks the locale the host pins it to, whatever the runtime speaks', async () => {
|
|
212
|
+
render(flow({ current: 'create-pin', locale: 'es-ES' }));
|
|
213
|
+
// Spanish loads on demand; the flow re-translates once it lands.
|
|
214
|
+
expect(await screen.findByText('Paso 3 de 4')).toBeTruthy();
|
|
215
|
+
});
|
|
216
|
+
|
|
211
217
|
it('is left out with showProgress false', () => {
|
|
212
218
|
render(flow({ current: 'create-pin', showProgress: false }));
|
|
213
219
|
expect(screen.queryByTestId('oxy-setup-progress')).toBeNull();
|
|
@@ -1842,6 +1842,7 @@ export const OxyRuntimeProvider: React.FC<OxyRuntimeProviderProps> = ({
|
|
|
1842
1842
|
error,
|
|
1843
1843
|
currentLanguage,
|
|
1844
1844
|
isLanguageReady: isLanguageReady && entryLink.campaignReady,
|
|
1845
|
+
isAccountLanguageKnown: false,
|
|
1845
1846
|
campaignAttribution: entryLink.campaignAttribution,
|
|
1846
1847
|
currentLanguages,
|
|
1847
1848
|
currentLanguageMetadata,
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
} from 'react';
|
|
35
35
|
import { OxyServices, logger as loggerUtil } from '@oxy.so/core';
|
|
36
36
|
import type { AccountNode, CreateAccountInput, User } from '@oxy.so/core';
|
|
37
|
-
import type { OxyHostRequest, OxySessionHost } from '@oxy.so/core/host';
|
|
37
|
+
import type { OxyHostAccount, OxyHostRequest, OxySessionHost } from '@oxy.so/core/host';
|
|
38
38
|
import type { AccountDialogView } from '@oxy.so/core/session';
|
|
39
39
|
import { createUserEventSocket, type UserEventSocket } from '@oxy.so/core/session';
|
|
40
40
|
import { useQueryClient } from '@tanstack/react-query';
|
|
@@ -72,7 +72,13 @@ import {
|
|
|
72
72
|
registerAccountDialogControls,
|
|
73
73
|
notifyAccountDialogVisibility,
|
|
74
74
|
} from '../navigation/accountDialogManager';
|
|
75
|
-
import {
|
|
75
|
+
import {
|
|
76
|
+
createHostSession,
|
|
77
|
+
HostedSessionError,
|
|
78
|
+
readHostSnapshot,
|
|
79
|
+
userFromHostAccount,
|
|
80
|
+
type HostSession,
|
|
81
|
+
} from '../session/hostSession';
|
|
76
82
|
import { AppAssertionProvider } from '../appAssertion/AppAssertionContext';
|
|
77
83
|
import type { LogoutResult, OxyContextState, OxyRuntimeProviderProps } from './oxyContextTypes';
|
|
78
84
|
import {
|
|
@@ -108,6 +114,18 @@ const NO_DEVICE: RuntimeSessionClient = {
|
|
|
108
114
|
};
|
|
109
115
|
const NO_DEVICE_HOST = { setCurrentAccountId: () => undefined };
|
|
110
116
|
|
|
117
|
+
/**
|
|
118
|
+
* What the host's snapshot says of the account's languages, as a stable value
|
|
119
|
+
* for `useSyncExternalStore`: `''` when nobody is signed in (the guest or
|
|
120
|
+
* device language is the answer), the account as JSON when it carries its
|
|
121
|
+
* languages, or `null` while only the account's own profile can tell.
|
|
122
|
+
*/
|
|
123
|
+
function languageAccountOf(host: OxySessionHost): string | null {
|
|
124
|
+
const snapshot = readHostSnapshot(host);
|
|
125
|
+
if (snapshot.status !== 'signed_in') return '';
|
|
126
|
+
return snapshot.account?.languages ? JSON.stringify(snapshot.account) : null;
|
|
127
|
+
}
|
|
128
|
+
|
|
111
129
|
/**
|
|
112
130
|
* Which of the platform's screens an `openAccountDialog(view)` asks for: its
|
|
113
131
|
* sign-in when signed out; while signed in, every view of the dialog — the
|
|
@@ -307,6 +325,26 @@ export const OxyHostedRuntimeProvider: React.FC<OxyHostedRuntimeProviderProps> =
|
|
|
307
325
|
onAuthStateChangeRef.current?.(runtime.getSnapshot().account);
|
|
308
326
|
}, [authResolved, userId, runtime]);
|
|
309
327
|
|
|
328
|
+
// The account's languages as the platform's snapshot gives them (ADR 0022 on a
|
|
329
|
+
// session host): the language is known from the first render, offline too,
|
|
330
|
+
// while the account itself is published only with its token (ADR 0058).
|
|
331
|
+
const subscribeHost = useCallback(
|
|
332
|
+
(listener: () => void) => (host ? host.subscribe(listener) : () => undefined),
|
|
333
|
+
[host],
|
|
334
|
+
);
|
|
335
|
+
const readLanguageAccount = useCallback(() => (host ? languageAccountOf(host) : null), [host]);
|
|
336
|
+
const languageAccount = useSyncExternalStore(
|
|
337
|
+
subscribeHost,
|
|
338
|
+
readLanguageAccount,
|
|
339
|
+
readLanguageAccount,
|
|
340
|
+
);
|
|
341
|
+
const languageUser = useMemo(() => {
|
|
342
|
+
if (user) return user;
|
|
343
|
+
if (!languageAccount) return null;
|
|
344
|
+
return userFromHostAccount(JSON.parse(languageAccount) as OxyHostAccount, null);
|
|
345
|
+
}, [languageAccount, user]);
|
|
346
|
+
const isAccountLanguageKnown = languageAccount !== null;
|
|
347
|
+
|
|
310
348
|
const entryLink = useEntryLink({
|
|
311
349
|
storage,
|
|
312
350
|
storageKey: `${storageKeyPrefix}_campaign_attribution`,
|
|
@@ -328,7 +366,7 @@ export const OxyHostedRuntimeProvider: React.FC<OxyHostedRuntimeProviderProps> =
|
|
|
328
366
|
entryUrl: entryLink.url,
|
|
329
367
|
entryLinkReady: entryLink.ready,
|
|
330
368
|
legacyLanguageKeys,
|
|
331
|
-
user,
|
|
369
|
+
user: languageUser,
|
|
332
370
|
onError,
|
|
333
371
|
logger,
|
|
334
372
|
});
|
|
@@ -524,6 +562,7 @@ export const OxyHostedRuntimeProvider: React.FC<OxyHostedRuntimeProviderProps> =
|
|
|
524
562
|
error,
|
|
525
563
|
currentLanguage,
|
|
526
564
|
isLanguageReady: isLanguageReady && entryLink.campaignReady,
|
|
565
|
+
isAccountLanguageKnown,
|
|
527
566
|
campaignAttribution: entryLink.campaignAttribution,
|
|
528
567
|
currentLanguages,
|
|
529
568
|
currentLanguageMetadata,
|
|
@@ -583,6 +622,7 @@ export const OxyHostedRuntimeProvider: React.FC<OxyHostedRuntimeProviderProps> =
|
|
|
583
622
|
error,
|
|
584
623
|
currentLanguage,
|
|
585
624
|
isLanguageReady,
|
|
625
|
+
isAccountLanguageKnown,
|
|
586
626
|
entryLink.campaignReady,
|
|
587
627
|
entryLink.campaignAttribution,
|
|
588
628
|
currentLanguages,
|
|
@@ -100,6 +100,14 @@ export interface OxyContextState {
|
|
|
100
100
|
/** Active UI locale (`language-REGION`): the account's primary locale when signed in, else the guest/device locale. */
|
|
101
101
|
currentLanguage: string;
|
|
102
102
|
isLanguageReady: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Whether the account's language is known before the session resolves: on a
|
|
105
|
+
* session host (ADR 0058) whose snapshot carries the account's languages, or
|
|
106
|
+
* says nobody is signed in, from the first render. The language bridge then
|
|
107
|
+
* waits for neither the token nor a profile read (ADR 0022). Always `false`
|
|
108
|
+
* where this SDK holds the session itself.
|
|
109
|
+
*/
|
|
110
|
+
isAccountLanguageKnown: boolean;
|
|
103
111
|
campaignAttribution?: CampaignAttribution;
|
|
104
112
|
/** Ordered account locales (primary first) when signed in, or the single guest override when signed out. */
|
|
105
113
|
currentLanguages: string[];
|
package/src/ui/hooks/useI18n.ts
CHANGED
|
@@ -25,9 +25,11 @@ export type Translate = (key: string, vars?: Record<string, string | number>) =>
|
|
|
25
25
|
*
|
|
26
26
|
* Anything that reads or mutates session state uses `useOxy()`, which throws.
|
|
27
27
|
*/
|
|
28
|
-
export function useI18n() {
|
|
28
|
+
export function useI18n(locale?: string) {
|
|
29
29
|
const oxy = useOptionalOxy();
|
|
30
|
-
|
|
30
|
+
// A surface the host pins to a language of its own (a platform's setup, in the system's
|
|
31
|
+
// language before and after the sign-in) speaks it; anything else, the runtime's.
|
|
32
|
+
const currentLanguage = locale ?? oxy?.currentLanguage ?? FALLBACK_LOCALE;
|
|
31
33
|
// Core's non-English dictionaries load on demand; re-translate when one lands.
|
|
32
34
|
const localesVersion = useSyncExternalStore(
|
|
33
35
|
subscribeLocales,
|
|
@@ -97,6 +97,13 @@ function validAccount(account: unknown): OxyHostAccount | null {
|
|
|
97
97
|
...(typeof candidate.avatar === 'string' && candidate.avatar
|
|
98
98
|
? { avatar: candidate.avatar }
|
|
99
99
|
: {}),
|
|
100
|
+
...(Array.isArray(candidate.languages)
|
|
101
|
+
? {
|
|
102
|
+
languages: candidate.languages.filter(
|
|
103
|
+
(language): language is string => typeof language === 'string' && language !== '',
|
|
104
|
+
),
|
|
105
|
+
}
|
|
106
|
+
: {}),
|
|
100
107
|
};
|
|
101
108
|
}
|
|
102
109
|
|
|
@@ -140,6 +147,12 @@ export function userFromHostAccount(account: OxyHostAccount, base: User | null):
|
|
|
140
147
|
publicKey: known?.publicKey ?? '',
|
|
141
148
|
name,
|
|
142
149
|
avatar: account.avatar ?? known?.avatar ?? null,
|
|
150
|
+
// The platform's last read of the languages until the profile is read here,
|
|
151
|
+
// which is the fresher of the two (ADR 0022's only read of the owner's own
|
|
152
|
+
// preferences).
|
|
153
|
+
...(known?.languages === undefined && account.languages
|
|
154
|
+
? { languages: [...account.languages] }
|
|
155
|
+
: {}),
|
|
143
156
|
} as User;
|
|
144
157
|
}
|
|
145
158
|
|
|
@@ -149,7 +162,8 @@ function sameProfile(user: User | null, account: OxyHostAccount): boolean {
|
|
|
149
162
|
user.id === account.id &&
|
|
150
163
|
user.username === account.handle &&
|
|
151
164
|
(account.displayName === undefined || user.name?.displayName === account.displayName) &&
|
|
152
|
-
(account.avatar === undefined || user.avatar === account.avatar)
|
|
165
|
+
(account.avatar === undefined || user.avatar === account.avatar) &&
|
|
166
|
+
(account.languages === undefined || user.languages !== undefined)
|
|
153
167
|
);
|
|
154
168
|
}
|
|
155
169
|
|