1
0
forked from boos/BoosAPI

refactor: remove deprecated apiKey from site management and update related functionality

- Removed apiKey from SiteRow type and related forms in Sites component.
- Updated site saving logic to handle site creation without apiKey.
- Adjusted tests to ensure apiKey is not included in site editor state.
- Refactored Tokens component to support embedded mode and redirect logic.
- Added migration tests for site apiKey to account migration service.
- Implemented siteApiKeyMigrationService to handle migration of apiKey to account tokens.
- Enhanced tests for segmented connections in Accounts and redirect logic for Tokens.
This commit is contained in:
cita
2026-03-07 15:03:30 +08:00
parent a98a6f2c18
commit c31bbcbb51
30 changed files with 1960 additions and 592 deletions
+14 -6
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { buildSiteSaveAction } from './sitesEditor.js';
import { buildSiteSaveAction, emptySiteForm, siteFormFromSite } from './sitesEditor.js';
describe('buildSiteSaveAction', () => {
it('returns add action in add mode', () => {
@@ -10,7 +10,6 @@ describe('buildSiteSaveAction', () => {
url: 'https://a.example.com/',
externalCheckinUrl: 'https://checkin.a.example.com',
platform: 'new-api',
apiKey: 'sk-1',
proxyUrl: 'http://127.0.0.1:7890',
globalWeight: '1.2',
},
@@ -23,7 +22,6 @@ describe('buildSiteSaveAction', () => {
url: 'https://a.example.com/',
externalCheckinUrl: 'https://checkin.a.example.com',
platform: 'new-api',
apiKey: 'sk-1',
proxyUrl: 'http://127.0.0.1:7890',
globalWeight: '1.2',
},
@@ -38,7 +36,6 @@ describe('buildSiteSaveAction', () => {
url: 'https://b.example.com',
externalCheckinUrl: '',
platform: 'one-api',
apiKey: '',
proxyUrl: '',
globalWeight: '0.8',
},
@@ -52,7 +49,6 @@ describe('buildSiteSaveAction', () => {
url: 'https://b.example.com',
externalCheckinUrl: '',
platform: 'one-api',
apiKey: '',
proxyUrl: '',
globalWeight: '0.8',
},
@@ -68,11 +64,23 @@ describe('buildSiteSaveAction', () => {
url: 'https://c.example.com',
externalCheckinUrl: '',
platform: '',
apiKey: '',
proxyUrl: '',
globalWeight: '1',
},
),
).toThrow('editingSiteId is required in edit mode');
});
it('does not expose deprecated apiKey in site editor state', () => {
expect(emptySiteForm()).not.toHaveProperty('apiKey');
expect(siteFormFromSite({
name: 'site-d',
url: 'https://d.example.com',
externalCheckinUrl: null,
platform: 'new-api',
proxyUrl: null,
globalWeight: 1,
apiKey: 'sk-legacy-site-key',
})).not.toHaveProperty('apiKey');
});
});
+1 -3
View File
@@ -3,7 +3,6 @@ export type SiteForm = {
url: string;
externalCheckinUrl: string;
platform: string;
apiKey: string;
proxyUrl: string;
globalWeight: string;
};
@@ -17,7 +16,7 @@ type SiteSaveAction =
| { kind: 'update'; id: number; payload: SiteForm };
export function emptySiteForm(): SiteForm {
return { name: '', url: '', externalCheckinUrl: '', platform: '', apiKey: '', proxyUrl: '', globalWeight: '1' };
return { name: '', url: '', externalCheckinUrl: '', platform: '', proxyUrl: '', globalWeight: '1' };
}
export function siteFormFromSite(site: Partial<SiteForm> & {
@@ -32,7 +31,6 @@ export function siteFormFromSite(site: Partial<SiteForm> & {
url: site.url ?? '',
externalCheckinUrl: site.externalCheckinUrl ?? '',
platform: site.platform ?? '',
apiKey: site.apiKey ?? '',
proxyUrl: site.proxyUrl ?? '',
globalWeight,
};