Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(external-rest-api): preserve credential-change guidance

Josuéddfe6d29b89f
diff --git a/external-rest-api/package-lock.json b/external-rest-api/package-lock.json
index dd9f4c6a3..43870353b 100644
--- a/external-rest-api/package-lock.json
+++ b/external-rest-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-external-rest-api",
- "version": "0.1.101",
+ "version": "0.1.102",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-external-rest-api",
- "version": "0.1.101",
+ "version": "0.1.102",
"dependencies": {
"@clerum/jwt-key-policy": "file:../packages/jwt-key-policy",
"cors": "^2.8.5",
diff --git a/external-rest-api/package.json b/external-rest-api/package.json
index 4b1a80ddc..40131493f 100644
--- a/external-rest-api/package.json
+++ b/external-rest-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-external-rest-api",
- "version": "0.1.101",
+ "version": "0.1.102",
"description": "External REST API for profile, team management, and RPC token brokerage",
"main": "dist/main.js",
"engines": {
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.ts
index bd16a13e4..47ac0184b 100644
--- a/external-rest-api/src/releaseManifest.ts
+++ b/external-rest-api/src/releaseManifest.ts
@@ -8,7 +8,7 @@ export type ReleaseManifest = {
export const releaseManifest: ReleaseManifest = {
releaseId: 'v0.10.0',
- externalRestApiVersion: '0.1.101',
+ externalRestApiVersion: '0.1.102',
rpcProxyVersion: '0.1.126',
desktopVersion: '0.10.0',
minimumDesktopVersion: '0.1.252',
diff --git a/external-rest-api/src/routes/me.ts b/external-rest-api/src/routes/me.ts
index 985351d9f..79410f4a4 100644
--- a/external-rest-api/src/routes/me.ts
+++ b/external-rest-api/src/routes/me.ts
@@ -1,4 +1,5 @@
import { Router } from 'express'
+import { ControlApiError } from '../controlApiClient.js'
import {
type AuthedRequest,
extractAuthToken,
@@ -16,6 +17,7 @@ import {
updatePassword,
updateProfile,
} from '../services/meService.js'
+import { PASSWORD_CREDENTIAL_CHANGED_PUBLIC_RESPONSE } from './mePasswordErrors.js'
const teamDirectoryRateLimit = createRateLimiter({
windowMs: 60_000,
@@ -148,6 +150,19 @@ export function createMeRouter(): Router {
return
}
if (message.includes('(409)')) {
+ const upstreamError =
+ error instanceof ControlApiError &&
+ error.body &&
+ typeof error.body === 'object' &&
+ 'error' in error.body
+ ? error.body.error
+ : undefined
+ if (upstreamError === 'credential_changed') {
+ res
+ .status(PASSWORD_CREDENTIAL_CHANGED_PUBLIC_RESPONSE.status)
+ .json(PASSWORD_CREDENTIAL_CHANGED_PUBLIC_RESPONSE.body)
+ return
+ }
res.status(409).json({ error: 'Password is not set' })
return
}
diff --git a/external-rest-api/src/routes/mePasswordErrors.ts b/external-rest-api/src/routes/mePasswordErrors.ts
new file mode 100644
index 000000000..b4354bf24
--- /dev/null
+++ b/external-rest-api/src/routes/mePasswordErrors.ts
@@ -0,0 +1,7 @@
+export const PASSWORD_CREDENTIAL_CHANGED_PUBLIC_RESPONSE = Object.freeze({
+ status: 409,
+ body: Object.freeze({
+ error:
+ 'Your password changed during this request. Sign in again with your new password.' as const,
+ }),
+})
diff --git a/external-rest-api/test/routes.accessForwarding.test.ts b/external-rest-api/test/routes.accessForwarding.test.ts
index c371cfcdf..79861606b 100644
--- a/external-rest-api/test/routes.accessForwarding.test.ts
+++ b/external-rest-api/test/routes.accessForwarding.test.ts
@@ -1,6 +1,10 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import express from 'express'
import request from 'supertest'
+import {
+ PASSWORD_CREDENTIAL_CHANGED_RESPONSE,
+ PASSWORD_NOT_SET_RESPONSE,
+} from '../../control-api/src/routes/external/passwordErrorResponses.js'
import { createMeRouter } from '../src/routes/me.js'
import { createTeamRouter } from '../src/routes/team.js'
@@ -15,6 +19,7 @@ const meServiceMock = vi.hoisted(() => ({
getMe: vi.fn(),
listTeams: vi.fn(),
switchTeam: vi.fn(),
+ updatePassword: vi.fn(),
updateProfile: vi.fn(),
}))
@@ -51,6 +56,7 @@ describe('routes/access forwarding', () => {
meServiceMock.getMe.mockReset()
meServiceMock.listTeams.mockReset()
meServiceMock.switchTeam.mockReset()
+ meServiceMock.updatePassword.mockReset()
meServiceMock.updateProfile.mockReset()
teamServiceMock.getTeamContexts.mockReset()
teamServiceMock.getTeamAgents.mockReset()
@@ -70,6 +76,20 @@ describe('routes/access forwarding', () => {
return app
}
+ async function preparePasswordApiError(response: { status: number; body: unknown }) {
+ authTokenMock.verifyToken.mockReturnValue(claims)
+ const actualService = await vi.importActual<typeof import('../src/services/meService.js')>(
+ '../src/services/meService.js'
+ )
+ meServiceMock.updatePassword.mockImplementation(actualService.updatePassword)
+ return vi.spyOn(globalThis, 'fetch').mockResolvedValue(
+ new Response(JSON.stringify(response.body), {
+ status: response.status,
+ headers: { 'content-type': 'application/json' },
+ })
+ )
+ }
+
it('forwards /me/contexts and /me/agents with claim-bound userId', async () => {
authTokenMock.verifyToken.mockReturnValue(claims)
meServiceMock.getMyContexts.mockResolvedValue({ userId: 'user-1', contextIds: ['ctx-a'] })
@@ -147,6 +167,42 @@ describe('routes/access forwarding', () => {
expect(meServiceMock.getMyTeamDirectory).toHaveBeenCalledWith('user-1', 'good-token')
})
+ it('maps the Control API credential-changed response to actionable password guidance', async () => {
+ const upstreamFetch = await preparePasswordApiError(PASSWORD_CREDENTIAL_CHANGED_RESPONSE)
+ const app = appWith(createMeRouter)
+
+ try {
+ await request(app)
+ .put('/me/password')
+ .set('authorization', 'Bearer good-token')
+ .send({ currentPassword: 'synthetic-current', newPassword: 'synthetic-next-password' })
+ .expect(409)
+ .expect({
+ error: 'Your password changed during this request. Sign in again with your new password.',
+ })
+ expect(upstreamFetch).toHaveBeenCalledTimes(1)
+ } finally {
+ upstreamFetch.mockRestore()
+ }
+ })
+
+ it('preserves the password-not-set message for the existing Control API 409 response', async () => {
+ const upstreamFetch = await preparePasswordApiError(PASSWORD_NOT_SET_RESPONSE)
+ const app = appWith(createMeRouter)
+
+ try {
+ await request(app)
+ .put('/me/password')
+ .set('authorization', 'Bearer good-token')
+ .send({ currentPassword: 'synthetic-current', newPassword: 'synthetic-next-password' })
+ .expect(409)
+ .expect({ error: 'Password is not set' })
+ expect(upstreamFetch).toHaveBeenCalledTimes(1)
+ } finally {
+ upstreamFetch.mockRestore()
+ }
+ })
+
it('rate limits initial /me/teams/directory per authenticated user', async () => {
authTokenMock.verifyToken.mockReturnValue({
...claims,
diff --git a/profile-ui/app/components/__tests__/SettingsContent.test.tsx b/profile-ui/app/components/__tests__/SettingsContent.test.tsx
index d0a547d0f..5c3647565 100644
--- a/profile-ui/app/components/__tests__/SettingsContent.test.tsx
+++ b/profile-ui/app/components/__tests__/SettingsContent.test.tsx
@@ -5,6 +5,7 @@ import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-li
import type { DesktopEnvironmentResponse } from '@/app/types/api'
import type { Me } from '@/app/types/profile'
import desktopEnvironmentFixture from '@/test/fixtures/desktop-environment-response.json'
+import { PASSWORD_CREDENTIAL_CHANGED_PUBLIC_RESPONSE } from '../../../../external-rest-api/src/routes/mePasswordErrors.js'
import { SettingsContent } from '../../settings/SettingsContent'
const mocks = vi.hoisted(() => ({
@@ -152,3 +153,44 @@ describe('Settings desktop setup handoff', () => {
expect(mocks.navigateToDesktopApp).toHaveBeenCalledWith(desktopHref)
})
})
+
+describe('Settings password update recovery messaging', () => {
+ it('shows actionable guidance from the External REST credential-change response', async () => {
+ const publicResponse = PASSWORD_CREDENTIAL_CHANGED_PUBLIC_RESPONSE
+ const publicMessage = publicResponse.body.error
+ const actualApi = await vi.importActual<typeof import('@lib/api')>('@lib/api')
+ mocks.updatePassword.mockImplementation(actualApi.updatePassword)
+ const upstreamFetch = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
+ new Response(JSON.stringify(publicResponse.body), {
+ status: publicResponse.status,
+ statusText: 'Conflict',
+ headers: { 'content-type': 'application/json' },
+ })
+ )
+
+ try {
+ render(<SettingsContent activeSettingsTab="profile" activeSocialTab="telegram" />)
+ const openButton = await screen.findByRole('button', { name: 'Update password' })
+ fireEvent.click(openButton)
+
+ const dialog = await screen.findByRole('dialog', { name: 'Update password' })
+ fireEvent.change(within(dialog).getByLabelText('Current password'), {
+ target: { value: 'Synthetic-current-password' },
+ })
+ fireEvent.change(within(dialog).getByLabelText('New password'), {
+ target: { value: 'Synthetic-next-password' },
+ })
+ fireEvent.change(within(dialog).getByLabelText('Confirm new password'), {
+ target: { value: 'Synthetic-next-password' },
+ })
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Update password' }))
+
+ expect(await within(dialog).findByText(`409 Conflict - ${publicMessage}`)).toBeInTheDocument()
+ expect(mocks.logout).not.toHaveBeenCalled()
+ expect(mocks.routerReplace).not.toHaveBeenCalled()
+ expect(mocks.showToast).not.toHaveBeenCalled()
+ } finally {
+ upstreamFetch.mockRestore()
+ }
+ })
+})
diff --git a/profile-ui/package-lock.json b/profile-ui/package-lock.json
index 348c55153..21e2516b4 100644
--- a/profile-ui/package-lock.json
+++ b/profile-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.166",
+ "version": "0.1.167",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-profile-ui",
- "version": "0.1.166",
+ "version": "0.1.167",
"dependencies": {
"@clerum/desktop-app-links": "file:../packages/desktop-app-links",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/profile-ui/package.json b/profile-ui/package.json
index 052c0e788..a7555ae59 100644
--- a/profile-ui/package.json
+++ b/profile-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.166",
+ "version": "0.1.167",
"private": true,
"scripts": {
"dev": "next dev",