diff --git a/.changeset/me-localization-endpoint.md b/.changeset/me-localization-endpoint.md new file mode 100644 index 0000000000..2a4784f36c --- /dev/null +++ b/.changeset/me-localization-endpoint.md @@ -0,0 +1,12 @@ +--- +"@objectstack/plugin-hono-server": minor +--- + +Expose resolved regional defaults to every authenticated user. + +Adds `GET /api/v1/auth/me/localization` returning the request tenant's resolved +`{ currency, locale, timezone }` from the ExecutionContext (ADR-0053). The +`localization` SETTINGS are gated to `setup.access`, but the resolved defaults +are needed by every renderer to format currency/dates/numbers — so they are +surfaced here without that gate. Enables a client to format a currency field +in the tenant's default currency when the field omits its own. diff --git a/packages/plugins/plugin-hono-server/src/hono-plugin.ts b/packages/plugins/plugin-hono-server/src/hono-plugin.ts index ef57472d9a..4d13aebb54 100644 --- a/packages/plugins/plugin-hono-server/src/hono-plugin.ts +++ b/packages/plugins/plugin-hono-server/src/hono-plugin.ts @@ -718,6 +718,25 @@ export class HonoServerPlugin implements Plugin { } }); + // GET /me/localization — the resolved regional defaults (currency / + // locale / timezone) for the current request's tenant, exposed to EVERY + // authenticated user. The `localization` SETTINGS are gated to + // `setup.access`, but the resolved defaults are needed by every renderer + // to format currency/dates/numbers — so they ride on the request + // ExecutionContext (ADR-0053) and are surfaced here without that gate. + rawApp.get(`${prefix}/auth/me/localization`, async (c: any) => { + const execCtx = await resolveCtx(c); + if (!execCtx?.userId) { + return c.json({ authenticated: false }); + } + return c.json({ + authenticated: true, + currency: execCtx.currency ?? null, + locale: execCtx.locale ?? null, + timezone: execCtx.timezone ?? null, + }); + }); + // GET /me/apps — list apps the current user is allowed to enter. // Filters `metadata.list('app')` by: // 1. AppSchema.requiredPermissions ⊆ ctx.systemPermissions