app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

navigation-copy.ts (860B)


      1 import { decodeProductReference } from './nostr/references.ts';
      2 // Explicit click callers alone use this public, hint-free coordinate action.
      3 export async function copyProductReference(
      4   value: unknown,
      5   origin: unknown
      6 ): Promise<boolean> {
      7   const reference = decodeProductReference(value);
      8   if (!reference || typeof origin !== 'string' || origin.length > 2048)
      9     return false;
     10   try {
     11     const host = new URL(origin);
     12     if (
     13       host.origin !== origin ||
     14       host.username ||
     15       host.password ||
     16       (host.protocol !== 'https:' &&
     17         !(
     18           host.protocol === 'http:' &&
     19           ['127.0.0.1', 'localhost', '[::1]'].includes(host.hostname)
     20         ))
     21     )
     22       return false;
     23     await navigator.clipboard.writeText(
     24       `${host.origin}/products/${reference.naddr}`
     25     );
     26     return true;
     27   } catch {
     28     return false;
     29   }
     30 }