-
-
Notifications
You must be signed in to change notification settings - Fork 424
feat(ui): add keytrace-style identity visualizer (poc) #2616
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
Draft
BittuBarnwal7479
wants to merge
10
commits into
npmx-dev:main
Choose a base branch
from
BittuBarnwal7479:feat/adopt-keytrace
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
45e8b97
feat: add Keytrace profile composable and API integration
invalid-email-address 5043d74
fix: refactor code by formatting the components and types
invalid-email-address d44a199
test: fix unit test
invalid-email-address 67f45f3
refactor: fix failed components test, remove error translations from …
invalid-email-address e72233a
Update i18n schema after removing unused common.error key
invalid-email-address 1e2c977
Update i18n/locales/de-AT.json
BittuBarnwal7479 eaf0536
fix: failed e2e test
invalid-email-address ad9e428
fix: failed test
invalid-email-address bb5b2e9
feat(keytrace): integrate real claims + reverify flow
invalid-email-address 0fbd549
refactor: standardize code formatting and improve readability across …
invalid-email-address File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,370 @@ | ||
| <script setup lang="ts"> | ||
| import type { | ||
| KeytraceAccount, | ||
| KeytraceReverifyRequest, | ||
| KeytraceReverifyResponse, | ||
| KeytraceVerificationStatus, | ||
| } from '#shared/types/keytrace' | ||
|
|
||
| const props = defineProps<{ | ||
| identity: string | ||
| account: KeytraceAccount | ||
| }>() | ||
|
|
||
| const platformLabelMap: Record<string, string> = { | ||
| github: 'GitHub', | ||
| npm: 'npm', | ||
| mastodon: 'Mastodon', | ||
| discord: 'Discord', | ||
| orcid: 'ORCID', | ||
| } | ||
|
|
||
| const platformIconMap: Record<string, string> = { | ||
| github: 'i-simple-icons:github', | ||
| npm: 'i-simple-icons:npm', | ||
| mastodon: 'i-simple-icons:mastodon', | ||
| discord: 'i-simple-icons:discord', | ||
| orcid: 'i-simple-icons:orcid', | ||
| } | ||
|
|
||
| const proofMethodLabelMap: Record<KeytraceAccount['proofMethod'], string> = { | ||
| dns: 'DNS', | ||
| github: 'GitHub', | ||
| npm: 'npm', | ||
| mastodon: 'Mastodon', | ||
| pgp: 'PGP', | ||
| other: 'other', | ||
| } | ||
|
|
||
| const statusLabelMap: Record<KeytraceAccount['status'], string> = { | ||
| verified: 'Verified', | ||
| unverified: 'Unverified', | ||
| stale: 'Stale', | ||
| failed: 'Failed', | ||
| } | ||
|
|
||
| const statusClassMap: Record<KeytraceAccount['status'], string> = { | ||
| verified: 'bg-emerald-500/15 text-emerald-300 border-emerald-500/30', | ||
| unverified: 'bg-yellow-500/15 text-yellow-300 border-yellow-500/30', | ||
| stale: 'bg-orange-500/15 text-orange-300 border-orange-500/30', | ||
| failed: 'bg-red-500/15 text-red-300 border-red-500/30', | ||
| } | ||
|
|
||
| const platformLabel = computed(() => { | ||
| const normalizedPlatform = props.account.platform.toLowerCase() | ||
| return platformLabelMap[normalizedPlatform] ?? props.account.platform | ||
| }) | ||
|
|
||
| const platformIconClass = computed(() => { | ||
| const normalizedPlatform = props.account.platform.toLowerCase() | ||
| return platformIconMap[normalizedPlatform] ?? 'i-lucide:user-round' | ||
| }) | ||
|
|
||
| const accountDisplayName = computed(() => props.account.displayName || props.account.username) | ||
| const accountAvatar = computed(() => props.account.avatar) | ||
|
|
||
| const localStatus = ref<KeytraceVerificationStatus>(props.account.status) | ||
| const localLastCheckedAt = ref(props.account.lastCheckedAt) | ||
| const localFailureReason = ref(props.account.failureReason) | ||
| const isReverifying = ref(false) | ||
| const reverifyError = ref<string | null>(null) | ||
| const panelVisible = ref(false) | ||
| const currentVerificationStep = ref(-1) | ||
| const reverifyTimeoutId = ref<ReturnType<typeof setTimeout> | null>(null) | ||
|
|
||
| const verificationSteps = [ | ||
| 'Matching service provider', | ||
| 'Fetching proof', | ||
| 'Checking for DID', | ||
| 'Server verification', | ||
| ] | ||
|
|
||
| function getErrorMessage(error: unknown): string { | ||
| if (typeof error === 'string') { | ||
| return error | ||
| } | ||
|
|
||
| if (error && typeof error === 'object') { | ||
| const maybeError = error as { | ||
| message?: unknown | ||
| statusMessage?: unknown | ||
| data?: { message?: unknown } | ||
| } | ||
|
|
||
| if (typeof maybeError.data?.message === 'string' && maybeError.data.message.trim()) { | ||
| return maybeError.data.message | ||
| } | ||
|
|
||
| if (typeof maybeError.statusMessage === 'string' && maybeError.statusMessage.trim()) { | ||
| return maybeError.statusMessage | ||
| } | ||
|
|
||
| if (typeof maybeError.message === 'string' && maybeError.message.trim()) { | ||
| return maybeError.message | ||
| } | ||
| } | ||
|
|
||
| return 'Unknown error' | ||
| } | ||
|
|
||
| watch( | ||
| () => props.account, | ||
| account => { | ||
| localStatus.value = account.status | ||
| localLastCheckedAt.value = account.lastCheckedAt | ||
| localFailureReason.value = account.failureReason | ||
| }, | ||
| { immediate: true }, | ||
| ) | ||
|
|
||
| const statusLabel = computed(() => statusLabelMap[localStatus.value]) | ||
| const statusClasses = computed(() => statusClassMap[localStatus.value]) | ||
| const proofMethodLabel = computed(() => proofMethodLabelMap[props.account.proofMethod]) | ||
|
|
||
| const shouldShowFailureReason = computed( | ||
| () => | ||
| !!localFailureReason.value && | ||
| (localStatus.value === 'failed' || | ||
| localStatus.value === 'stale' || | ||
| localStatus.value === 'unverified'), | ||
| ) | ||
|
|
||
| function closeReverifyPanel() { | ||
| panelVisible.value = false | ||
| } | ||
|
|
||
| function cancelReverifyTimeout() { | ||
| if (reverifyTimeoutId.value) { | ||
| clearTimeout(reverifyTimeoutId.value) | ||
| reverifyTimeoutId.value = null | ||
| } | ||
| } | ||
|
|
||
| onUnmounted(() => { | ||
| cancelReverifyTimeout() | ||
| }) | ||
|
|
||
| async function reverifyAccount() { | ||
| cancelReverifyTimeout() | ||
| isReverifying.value = true | ||
| reverifyError.value = null | ||
| panelVisible.value = true | ||
| currentVerificationStep.value = -1 | ||
|
|
||
| const runStep = async (stepIndex: number) => { | ||
| currentVerificationStep.value = stepIndex | ||
| await new Promise(resolve => setTimeout(resolve, 220)) | ||
| } | ||
|
|
||
| try { | ||
| const body: KeytraceReverifyRequest = { | ||
| identity: props.identity, | ||
| platform: props.account.platform, | ||
| username: props.account.username, | ||
| url: props.account.url, | ||
| } | ||
|
|
||
| const responsePromise = $fetch<KeytraceReverifyResponse>('/api/keytrace/reverify', { | ||
| method: 'POST', | ||
| body, | ||
| }) | ||
|
|
||
| // Attach rejection handler to prevent unhandled promise rejection warnings | ||
| responsePromise.catch(() => {}) | ||
|
|
||
| await runStep(0) | ||
| await runStep(1) | ||
| await runStep(2) | ||
| await runStep(3) | ||
|
|
||
| const response = await responsePromise | ||
|
|
||
| localStatus.value = response.status | ||
| localLastCheckedAt.value = response.lastCheckedAt | ||
| localFailureReason.value = response.failureReason | ||
| currentVerificationStep.value = verificationSteps.length | ||
| } catch (error) { | ||
| // oxlint-disable-next-line no-console -- log reverify failures for observability | ||
| console.error('[keytrace] reverify failed', error) | ||
| const errorMessage = getErrorMessage(error) | ||
| localFailureReason.value = errorMessage | ||
| reverifyError.value = `Re-verification failed: ${errorMessage}` | ||
| } finally { | ||
| isReverifying.value = false | ||
|
|
||
| const closeDelay = reverifyError.value ? 3000 : 1000 | ||
| reverifyTimeoutId.value = setTimeout(() => { | ||
| closeReverifyPanel() | ||
| reverifyTimeoutId.value = null | ||
| }, closeDelay) | ||
| } | ||
| } | ||
| function getStepState(stepIndex: number): 'done' | 'active' | 'idle' { | ||
| if (currentVerificationStep.value > stepIndex) { | ||
| return 'done' | ||
| } | ||
|
|
||
| if (currentVerificationStep.value === stepIndex && isReverifying.value && !reverifyError.value) { | ||
| return 'active' | ||
| } | ||
|
|
||
| if (currentVerificationStep.value >= verificationSteps.length) { | ||
| return 'done' | ||
| } | ||
|
|
||
| return 'idle' | ||
| } | ||
|
|
||
| function formatDate(value: string): string { | ||
| const date = new Date(value) | ||
| if (Number.isNaN(date.getTime())) { | ||
| return 'Unknown date' | ||
| } | ||
|
|
||
| return new Intl.DateTimeFormat('en-US', { | ||
| month: 'short', | ||
| day: 'numeric', | ||
| year: 'numeric', | ||
| timeZone: 'UTC', | ||
| }).format(date) | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
| <div class="rounded-md border border-border bg-bg-subtle px-3 py-3 sm:px-4"> | ||
| <div class="flex items-start justify-between gap-3"> | ||
| <div class="min-w-0"> | ||
| <div class="flex items-center gap-3 min-w-0"> | ||
| <LinkBase | ||
| v-if="account.url" | ||
| :to="account.url" | ||
| noUnderline | ||
| class="inline-flex items-center gap-3 min-w-0 hover:text-accent" | ||
| > | ||
| <div | ||
| class="size-10 rounded-full border border-border overflow-hidden bg-bg-muted shrink-0 flex items-center justify-center" | ||
| > | ||
| <img | ||
| v-if="accountAvatar" | ||
| :src="accountAvatar" | ||
| :alt="accountDisplayName" | ||
| class="w-full h-full object-cover" | ||
| /> | ||
| <span v-else :class="platformIconClass" class="size-4" aria-hidden="true" /> | ||
| </div> | ||
| <p class="font-mono text-base sm:text-lg font-medium min-w-0 break-words"> | ||
| {{ accountDisplayName }} | ||
| </p> | ||
| </LinkBase> | ||
|
|
||
| <div v-else class="inline-flex items-center gap-3 min-w-0"> | ||
| <div | ||
| class="size-10 rounded-full border border-border overflow-hidden bg-bg-muted shrink-0 flex items-center justify-center" | ||
| > | ||
| <img | ||
| v-if="accountAvatar" | ||
| :src="accountAvatar" | ||
| :alt="accountDisplayName" | ||
| class="w-full h-full object-cover" | ||
| /> | ||
| <span v-else :class="platformIconClass" class="size-4" aria-hidden="true" /> | ||
| </div> | ||
| <p class="font-mono text-base sm:text-lg font-medium min-w-0 break-words"> | ||
| {{ accountDisplayName }} | ||
| </p> | ||
| </div> | ||
|
|
||
| <span | ||
| class="inline-flex items-center rounded-full border px-2 py-0.5 text-xs font-mono" | ||
| :class="statusClasses" | ||
| > | ||
| {{ statusLabel }} | ||
| </span> | ||
| </div> | ||
|
|
||
| <p class="mt-2 text-sm text-fg-muted min-w-0 break-words"> | ||
| via {{ proofMethodLabel }} | ||
| <span aria-hidden="true" class="mx-1">·</span> | ||
| Added {{ formatDate(account.addedAt) }} | ||
| <span aria-hidden="true" class="mx-1">·</span> | ||
| Last checked {{ formatDate(localLastCheckedAt) }} | ||
| </p> | ||
|
|
||
| <p v-if="shouldShowFailureReason" class="mt-2 text-sm text-fg-muted min-w-0 break-words"> | ||
| {{ localFailureReason }} | ||
| </p> | ||
| </div> | ||
|
|
||
| <div class="flex flex-col items-end gap-2 shrink-0"> | ||
| <div class="flex items-center gap-2"> | ||
| <TooltipBase | ||
| :is-visible="panelVisible || isReverifying" | ||
| position="bottom" | ||
| :offset="8" | ||
| interactive | ||
| :tooltip-attr="{ 'role': 'dialog', 'aria-label': 'Re-verify claim' }" | ||
| > | ||
| <ButtonBase | ||
| size="sm" | ||
| :disabled="isReverifying" | ||
| :classicon="isReverifying ? 'i-lucide:loader-circle' : 'i-lucide:refresh-cw'" | ||
| @click="reverifyAccount" | ||
| > | ||
| {{ isReverifying ? 'Checking...' : 'Re-verify' }} | ||
| </ButtonBase> | ||
|
|
||
| <template #content> | ||
| <div class="w-72 max-w-full p-2 sm:p-3"> | ||
| <p class="font-mono text-sm font-medium">Re-verify Claim</p> | ||
| <p class="text-sm text-fg-subtle mt-1">{{ platformLabel }}</p> | ||
|
|
||
| <ul class="mt-3 space-y-2"> | ||
| <li | ||
| v-for="(stepLabel, stepIndex) in verificationSteps" | ||
| :key="stepLabel" | ||
| class="flex items-center gap-2 text-sm" | ||
| :class="{ | ||
| 'text-fg': getStepState(stepIndex) === 'done', | ||
| 'text-fg-subtle': getStepState(stepIndex) === 'idle', | ||
| }" | ||
| > | ||
| <span | ||
| class="size-4 inline-flex items-center justify-center rounded-full border" | ||
| :class="{ | ||
| 'border-emerald-400/60 text-emerald-300': | ||
| getStepState(stepIndex) === 'done', | ||
| 'border-accent/70 text-accent': getStepState(stepIndex) === 'active', | ||
| 'border-border text-fg-subtle': getStepState(stepIndex) === 'idle', | ||
| }" | ||
| > | ||
| <span | ||
| v-if="getStepState(stepIndex) === 'done'" | ||
| class="i-lucide:check size-3" | ||
| aria-hidden="true" | ||
| /> | ||
| <span | ||
| v-else-if="getStepState(stepIndex) === 'active'" | ||
| class="i-lucide:loader-circle size-3 animate-spin" | ||
| aria-hidden="true" | ||
| /> | ||
| <span v-else class="size-2 rounded-full bg-current/70" aria-hidden="true" /> | ||
| </span> | ||
| <span>{{ stepLabel }}</span> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| </template> | ||
| </TooltipBase> | ||
| </div> | ||
|
|
||
| <p | ||
| v-if="reverifyError" | ||
| class="text-sm text-red-300 min-w-0 break-words text-end" | ||
| role="alert" | ||
| > | ||
| {{ reverifyError }} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </template> | ||
Oops, something went wrong.
Oops, something went wrong.
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.