Files
accounted/components/extensions/general/inbox-address-copy.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

36 lines
1.6 KiB
TypeScript

import { copyToClipboard } from '@/lib/browser/copy-to-clipboard'
/**
* Copy state for the inbox address in the workspace header.
*
* `idle` claims nothing, `copied` is only reachable after the clipboard write
* resolved, and `failed` means the address is NOT on the clipboard.
*/
export type AddressCopyState = 'idle' | 'copied' | 'failed'
/**
* Copy the document-inbox address and report which state the header must show.
*
* Why this exists as its own function: the previous handler fired
* `navigator.clipboard.writeText(...).catch(() => {})` and then showed
* "Adress kopierad" unconditionally, so an insecure context, a blocking
* Permissions-Policy or a document that had lost focus produced a success
* message with an empty clipboard. The user then waits for supplier invoices at
* an address they never captured, and nothing in the UI ever contradicts that.
*
* `unavailable` (no Clipboard API at all) and `failed` (the write was rejected)
* collapse into one UI state on purpose: from the user's side both mean the
* address is not on the clipboard and manual selection is the only way to get
* it. The distinction only matters for logging, which this surface does not do.
*
* Call this as the first `await` in the click handler: a clipboard write issued
* after another await runs outside the click's transient user activation and is
* rejected on that ground alone.
*/
export async function copyInboxAddress(
address: string,
): Promise<Exclude<AddressCopyState, 'idle'>> {
const result = await copyToClipboard(address)
return result === 'copied' ? 'copied' : 'failed'
}