@byline/host-tanstack-start 2.5.1 → 2.6.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/dist/admin-shell/admin-roles/container.js +38 -24
- package/dist/admin-shell/admin-roles/delete.js +9 -7
- package/dist/admin-shell/admin-roles/list.js +20 -16
- package/dist/admin-shell/admin-users/container.js +79 -56
- package/dist/admin-shell/admin-users/delete.js +10 -8
- package/dist/admin-shell/admin-users/list.js +27 -18
- package/dist/admin-shell/chrome/admin-app-bar.js +5 -2
- package/dist/admin-shell/chrome/breadcrumbs/breadcrumbs.js +3 -1
- package/dist/admin-shell/chrome/dashboard.js +13 -11
- package/dist/admin-shell/chrome/hamburger.js +3 -1
- package/dist/admin-shell/chrome/menu-drawer.js +7 -5
- package/dist/admin-shell/chrome/preview-toggle.js +5 -3
- package/dist/admin-shell/chrome/route-error.d.ts +3 -2
- package/dist/admin-shell/chrome/route-error.js +29 -22
- package/dist/admin-shell/chrome/sign-in-page.d.ts +16 -4
- package/dist/admin-shell/chrome/sign-in-page.js +38 -13
- package/dist/admin-shell/chrome/sign-in-page.module.js +1 -0
- package/dist/admin-shell/chrome/sign-in-page_module.css +8 -1
- package/dist/admin-shell/collections/api.js +6 -5
- package/dist/admin-shell/collections/create.js +12 -4
- package/dist/admin-shell/collections/edit.js +112 -37
- package/dist/admin-shell/collections/history.js +17 -12
- package/dist/admin-shell/collections/list.js +18 -13
- package/dist/admin-shell/collections/preview-link.d.ts +1 -10
- package/dist/admin-shell/collections/preview-link.js +9 -11
- package/dist/admin-shell/collections/resolve-preview-url.d.ts +34 -0
- package/dist/admin-shell/collections/resolve-preview-url.js +17 -0
- package/dist/admin-shell/collections/restore-version-modal.js +13 -14
- package/dist/admin-shell/collections/tanstack-navigation-guard.d.ts +1 -1
- package/dist/admin-shell/collections/view-menu.js +7 -5
- package/dist/i18n/index.d.ts +19 -0
- package/dist/i18n/index.js +4 -0
- package/dist/i18n/locale-cookie.d.ts +17 -0
- package/dist/i18n/locale-cookie.js +26 -0
- package/dist/i18n/locale-definitions.d.ts +29 -0
- package/dist/i18n/locale-definitions.js +27 -0
- package/dist/i18n/resolve-locale.d.ts +20 -0
- package/dist/i18n/resolve-locale.js +43 -0
- package/dist/i18n/server-translator.d.ts +33 -0
- package/dist/i18n/server-translator.js +19 -0
- package/dist/integrations/byline-admin-services.js +2 -0
- package/dist/integrations/byline-field-services.d.ts +3 -3
- package/dist/routes/create-admin-account-route.js +6 -3
- package/dist/routes/create-admin-dashboard-route.js +3 -1
- package/dist/routes/create-admin-layout-route.js +48 -25
- package/dist/routes/create-admin-permissions-route.js +4 -2
- package/dist/routes/create-admin-role-edit-route.js +5 -3
- package/dist/routes/create-admin-roles-list-route.js +4 -2
- package/dist/routes/create-admin-user-edit-route.js +5 -3
- package/dist/routes/create-admin-users-list-route.js +4 -2
- package/dist/routes/create-collection-api-route.js +5 -3
- package/dist/routes/create-collection-create-route.js +4 -2
- package/dist/routes/create-collection-edit-route.js +4 -2
- package/dist/routes/create-collection-history-route.js +5 -3
- package/dist/routes/create-collection-list-route.js +11 -5
- package/dist/routes/create-sign-in-route.js +10 -1
- package/dist/server-fns/admin-account/change-password.d.ts +1 -0
- package/dist/server-fns/admin-account/get.d.ts +1 -0
- package/dist/server-fns/admin-account/update.d.ts +1 -0
- package/dist/server-fns/admin-users/create.d.ts +1 -0
- package/dist/server-fns/admin-users/get.d.ts +1 -0
- package/dist/server-fns/admin-users/list.d.ts +1 -0
- package/dist/server-fns/admin-users/set-password.d.ts +1 -0
- package/dist/server-fns/admin-users/update.d.ts +1 -0
- package/dist/server-fns/auth/sign-in.js +18 -0
- package/dist/server-fns/i18n/get-active-locale.d.ts +8 -0
- package/dist/server-fns/i18n/get-active-locale.js +6 -0
- package/dist/server-fns/i18n/index.d.ts +10 -0
- package/dist/server-fns/i18n/index.js +2 -0
- package/dist/server-fns/i18n/set-locale.d.ts +25 -0
- package/dist/server-fns/i18n/set-locale.js +42 -0
- package/package.json +16 -7
- package/src/admin-shell/admin-roles/container.tsx +41 -31
- package/src/admin-shell/admin-roles/delete.tsx +10 -11
- package/src/admin-shell/admin-roles/list.tsx +29 -16
- package/src/admin-shell/admin-users/container.tsx +77 -50
- package/src/admin-shell/admin-users/delete.tsx +11 -12
- package/src/admin-shell/admin-users/list.tsx +39 -18
- package/src/admin-shell/chrome/admin-app-bar.tsx +5 -2
- package/src/admin-shell/chrome/breadcrumbs/breadcrumbs.tsx +3 -1
- package/src/admin-shell/chrome/dashboard.tsx +9 -3
- package/src/admin-shell/chrome/hamburger.tsx +3 -1
- package/src/admin-shell/chrome/menu-drawer.tsx +7 -5
- package/src/admin-shell/chrome/preview-toggle.tsx +6 -4
- package/src/admin-shell/chrome/route-error.tsx +39 -26
- package/src/admin-shell/chrome/sign-in-page.module.css +10 -1
- package/src/admin-shell/chrome/sign-in-page.tsx +46 -12
- package/src/admin-shell/collections/api.tsx +5 -1
- package/src/admin-shell/collections/create.tsx +10 -4
- package/src/admin-shell/collections/edit.tsx +79 -72
- package/src/admin-shell/collections/history.tsx +18 -12
- package/src/admin-shell/collections/list.tsx +25 -14
- package/src/admin-shell/collections/preview-link.tsx +20 -33
- package/src/admin-shell/collections/resolve-preview-url.test.node.ts +167 -0
- package/src/admin-shell/collections/resolve-preview-url.ts +67 -0
- package/src/admin-shell/collections/restore-version-modal.tsx +11 -12
- package/src/admin-shell/collections/tanstack-navigation-guard.ts +1 -1
- package/src/admin-shell/collections/view-menu.tsx +9 -5
- package/src/i18n/index.ts +26 -0
- package/src/i18n/locale-cookie.ts +68 -0
- package/src/i18n/locale-definitions.ts +48 -0
- package/src/i18n/resolve-locale.ts +96 -0
- package/src/i18n/server-translator.ts +60 -0
- package/src/integrations/byline-admin-services.ts +2 -0
- package/src/integrations/byline-field-services.ts +7 -3
- package/src/routes/create-admin-account-route.tsx +6 -4
- package/src/routes/create-admin-dashboard-route.tsx +5 -1
- package/src/routes/create-admin-layout-route.tsx +53 -20
- package/src/routes/create-admin-permissions-route.tsx +4 -2
- package/src/routes/create-admin-role-edit-route.tsx +5 -3
- package/src/routes/create-admin-roles-list-route.tsx +5 -2
- package/src/routes/create-admin-user-edit-route.tsx +5 -3
- package/src/routes/create-admin-users-list-route.tsx +4 -2
- package/src/routes/create-collection-api-route.tsx +5 -3
- package/src/routes/create-collection-create-route.tsx +7 -2
- package/src/routes/create-collection-edit-route.tsx +4 -2
- package/src/routes/create-collection-history-route.tsx +5 -3
- package/src/routes/create-collection-list-route.tsx +8 -10
- package/src/routes/create-sign-in-route.tsx +14 -1
- package/src/server-fns/auth/sign-in.ts +45 -0
- package/src/server-fns/i18n/get-active-locale.ts +26 -0
- package/src/server-fns/i18n/index.ts +11 -0
- package/src/server-fns/i18n/set-locale.ts +103 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Persist the admin user's interface locale preference.
|
|
11
|
+
*
|
|
12
|
+
* Always writes the `byline_admin_lng` cookie so the browser carries the new
|
|
13
|
+
* locale to subsequent requests, including any SSR pre-resolution. When
|
|
14
|
+
* an admin session is present the column on `admin_users.preferred_locale`
|
|
15
|
+
* is also updated so the choice follows the user across devices.
|
|
16
|
+
*
|
|
17
|
+
* Locale validation is host-side: the request locale must appear in
|
|
18
|
+
* `config.i18n.interface.locales` (or be `null`, which clears the
|
|
19
|
+
* cookie + column and re-engages the detection cascade). Validation
|
|
20
|
+
* lives here rather than in the admin module so the rule stays close
|
|
21
|
+
* to the host's i18n config.
|
|
22
|
+
*
|
|
23
|
+
* Pre-auth path: the login page itself is translated. When the request
|
|
24
|
+
* has no admin session, the cookie write still fires so the locale
|
|
25
|
+
* switcher works on the sign-in surface — the DB write simply skips.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { createServerFn } from '@tanstack/react-start'
|
|
29
|
+
|
|
30
|
+
import type { AccountResponse } from '@byline/admin/admin-account'
|
|
31
|
+
import { setPreferredLocaleCommand } from '@byline/admin/admin-account'
|
|
32
|
+
import { AuthError, AuthErrorCodes } from '@byline/auth'
|
|
33
|
+
|
|
34
|
+
import { getAdminRequestContext } from '../../auth/auth-context.js'
|
|
35
|
+
import { clearAdminLocaleCookie, setAdminLocaleCookie } from '../../i18n/locale-cookie.js'
|
|
36
|
+
import { bylineCore } from '../../integrations/byline-core.js'
|
|
37
|
+
|
|
38
|
+
export interface SetInterfaceLocaleInput {
|
|
39
|
+
/** BCP 47 tag, or `null` to clear the preference. */
|
|
40
|
+
locale: string | null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface SetInterfaceLocaleResult {
|
|
44
|
+
ok: true
|
|
45
|
+
/** Echo of the persisted value. `null` means the column was cleared. */
|
|
46
|
+
locale: string | null
|
|
47
|
+
/**
|
|
48
|
+
* Freshened admin user row when the request resolved an authenticated
|
|
49
|
+
* actor. `null` on the pre-auth path (sign-in page, no admin store
|
|
50
|
+
* configured). Form-shaped callers lift this into local state; the
|
|
51
|
+
* top-bar `<LanguageMenu>` ignores it.
|
|
52
|
+
*/
|
|
53
|
+
account: AccountResponse | null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const setInterfaceLocaleFn = createServerFn({ method: 'POST' })
|
|
57
|
+
.inputValidator((input: SetInterfaceLocaleInput) => input)
|
|
58
|
+
.handler(async ({ data }): Promise<SetInterfaceLocaleResult> => {
|
|
59
|
+
const core = bylineCore()
|
|
60
|
+
const locales = core.config.i18n.interface.locales
|
|
61
|
+
|
|
62
|
+
// Validate against the permitted set. `null` is always permitted —
|
|
63
|
+
// it's the "use detection" signal.
|
|
64
|
+
if (data.locale != null && !locales.includes(data.locale)) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`[setInterfaceLocaleFn] locale '${data.locale}' is not in i18n.interface.locales [${locales.join(', ')}].`
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Cookie write — fires unconditionally so the pre-auth login page
|
|
71
|
+
// can switch locales without an admin session.
|
|
72
|
+
if (data.locale == null) {
|
|
73
|
+
clearAdminLocaleCookie()
|
|
74
|
+
} else {
|
|
75
|
+
setAdminLocaleCookie(data.locale)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// DB write — skipped when there is no admin session. We catch the
|
|
79
|
+
// unauthenticated error specifically; any other error (transport,
|
|
80
|
+
// refresh failure that isn't just "no session") still bubbles up.
|
|
81
|
+
const adminStore = core.adminStore
|
|
82
|
+
if (adminStore == null) {
|
|
83
|
+
// No admin store configured — cookie-only. Headless tooling
|
|
84
|
+
// paths typically don't have one wired.
|
|
85
|
+
return { ok: true as const, locale: data.locale, account: null }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const context = await getAdminRequestContext()
|
|
90
|
+
const account = await setPreferredLocaleCommand(
|
|
91
|
+
context,
|
|
92
|
+
{ locale: data.locale },
|
|
93
|
+
{ store: adminStore }
|
|
94
|
+
)
|
|
95
|
+
return { ok: true as const, locale: data.locale, account }
|
|
96
|
+
} catch (err) {
|
|
97
|
+
if (err instanceof AuthError && err.code === AuthErrorCodes.UNAUTHENTICATED) {
|
|
98
|
+
// Expected on the pre-auth path. Cookie already written.
|
|
99
|
+
return { ok: true as const, locale: data.locale, account: null }
|
|
100
|
+
}
|
|
101
|
+
throw err
|
|
102
|
+
}
|
|
103
|
+
})
|