Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8
feat: names of people on control panel#900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 129 additions & 5 deletions
134 infrastructure/control-panel/src/routes/api/evaults/+server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,143 @@ | ||
| import { json } from '@sveltejs/kit'; | ||
| import type { RequestHandler } from '@sveltejs/kit'; | ||
| import { registryService } from '$lib/services/registry'; | ||
| import { env } from '$env/dynamic/public'; | ||
| import { registryService, type RegistryVault } from '$lib/services/registry'; | ||
| const USER_ONTOLOGY_ID = '550e8400-e29b-41d4-a716-446655440000'; | ||
| const GROUP_ONTOLOGY_ID = 'a8bfb7cf-3200-4b25-9ea9-ee41100f212e'; | ||
| const META_ENVELOPES_QUERY = ` | ||
| query MetaEnvelopes($filter: MetaEnvelopeFilterInput, $first: Int) { | ||
| metaEnvelopes(filter: $filter, first: $first) { | ||
| edges { | ||
| node { | ||
| parsed | ||
| } | ||
| } | ||
| } | ||
| } | ||
| `; | ||
| export interface EVault { | ||
| id: string; // evault identifier (evault field from registry) | ||
| name: string; // display name (ename or evault) | ||
| type: 'user' | 'group'; // derived from ontology lookup | ||
| ename: string; // w3id identifier | ||
| uri: string; // resolved service URI | ||
| evault: string; // evault identifier | ||
| status: string; // derived from health check | ||
| serviceUrl?: string; // same as uri for display | ||
| } | ||
| export const GET: RequestHandler = async () => { | ||
| function firstNonEmptyString(...values: unknown[]): string | null { | ||
| for (const value of values) { | ||
| if (typeof value === 'string' && value.trim().length > 0) { | ||
| return value.trim(); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| async function fetchFirstParsedByOntology( | ||
| vault: RegistryVault, | ||
| ontologyId: string, | ||
| token: string | ||
| ): Promise<Record<string, unknown> | null> { | ||
| try { | ||
| const response = await fetch(`${vault.uri}/graphql`, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'X-ENAME': vault.ename, | ||
| Authorization: `Bearer ${token}` | ||
| }, | ||
coodos marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| body: JSON.stringify({ | ||
| query: META_ENVELOPES_QUERY, | ||
| variables: { | ||
| filter: { ontologyId }, | ||
| first: 1 | ||
| } | ||
| }), | ||
| signal: AbortSignal.timeout(2500) | ||
| }); | ||
| if (!response.ok) { | ||
| return null; | ||
| } | ||
| const payload = await response.json(); | ||
| const parsed = payload?.data?.metaEnvelopes?.edges?.[0]?.node?.parsed; | ||
| if (!parsed || typeof parsed !== 'object') { | ||
| return null; | ||
| } | ||
| return parsed as Record<string, unknown>; | ||
| } catch { | ||
| return null; | ||
| } | ||
| } | ||
| async function resolveVaultIdentity( | ||
| vault: RegistryVault, | ||
| token: string | ||
| ): Promise<{ name: string; type: 'user' | 'group' }> { | ||
| const defaultName = firstNonEmptyString(vault.ename, vault.evault, 'Unknown') || 'Unknown'; | ||
| const userProfile = await fetchFirstParsedByOntology(vault, USER_ONTOLOGY_ID, token); | ||
| if (userProfile) { | ||
| return { | ||
| type: 'user', | ||
| name: | ||
| firstNonEmptyString(userProfile.displayName, userProfile.username, vault.ename, vault.evault) || | ||
| defaultName | ||
| }; | ||
| } | ||
| const groupManifest = await fetchFirstParsedByOntology(vault, GROUP_ONTOLOGY_ID, token); | ||
| if (groupManifest) { | ||
| return { | ||
| type: 'group', | ||
| name: | ||
| firstNonEmptyString(groupManifest.name, groupManifest.eName, vault.ename, vault.evault) || | ||
| defaultName | ||
| }; | ||
| } | ||
| return { | ||
| type: 'group', | ||
| name: defaultName | ||
| }; | ||
| } | ||
| async function requestPlatformToken(platform: string): Promise<string> { | ||
| const registryUrl = env.PUBLIC_REGISTRY_URL || 'https://registry.staging.metastate.foundation'; | ||
| const response = await fetch(new URL('/platforms/certification', registryUrl).toString(), { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json' | ||
| }, | ||
| body: JSON.stringify({ platform }), | ||
| signal: AbortSignal.timeout(2500) | ||
| }); | ||
| if (!response.ok) { | ||
| throw new Error(`Failed to get platform token: HTTP ${response.status}`); | ||
| } | ||
| const data = (await response.json()) as { token?: string }; | ||
| if (!data.token) { | ||
| throw new Error('Failed to get platform token: missing token in response'); | ||
| } | ||
| return data.token; | ||
| } | ||
| export const GET: RequestHandler = async ({ url }) => { | ||
| try { | ||
| const platform = env.PUBLIC_CONTROL_PANEL_URL || url.origin; | ||
| const token = await requestPlatformToken(platform); | ||
coodos marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // Fetch all evaults from registry | ||
| const registryVaults = await registryService.getEVaults(); | ||
| @@ -23,8 +147,7 @@ export const GET: RequestHandler = async () => { | ||
| // Use evault identifier as the primary ID, fallback to ename | ||
| const evaultId = vault.evault || vault.ename; | ||
| // Determine display name (prefer ename, fallback to evault) | ||
| const displayName = vault.ename || vault.evault || 'Unknown'; | ||
| const identity = await resolveVaultIdentity(vault, token); | ||
| // Check health status by attempting to fetch from URI | ||
| let status = 'Unknown'; | ||
| @@ -39,7 +162,8 @@ export const GET: RequestHandler = async () => { | ||
| return { | ||
| id: evaultId, | ||
| name: displayName, | ||
| name: identity.name, | ||
| type: identity.type, | ||
| ename: vault.ename, | ||
| uri: vault.uri, | ||
| evault: vault.evault, | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.