import { fetch , FetchMethods , FetchResultTypes , QueryError } from '@sapphire/fetch' ; import type { PhishermanReportType , PhishermanReturnType } from './PhishermanTypes' ; import os from 'node:os' ; /**
 * The cached apiKey which was created using  setApiKey let storedApiKey ; param domain param apiKey optionally pass a Phiserman API key for making this request. This will default to  storedApiKey , which can be configured through  setApiKey .
 *  since export async function checkDomain ( domain , apiKey = storedApiKey ) { const result = await fetch < PhishermanReturnType > ( `https://api.phisherman.gg/v2/domains/check/${ domain }` , { headers : { 'Content-Type' : 'application/json' , 'User-Agent' : `Sapphire Phisherman/1.0.0 (node-fetch) ${ os . platform ( ) }/${ os . release ( ) } (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)` , Authorization : `Bearer ${ apiKey }` } } , FetchResultTypes . JSON ) ; return { ... result , isScam : result . classification === 'safe' || result . classification === 'unknown' ? false : true } ; } param domain param apiKey optionally pass a Phiserman API key for making this request. This will default to  storedApiKey , which can be configured through  setApiKey .
 *  since export function reportDomain ( domain , apiKey = storedApiKey ) { return fetch < PhishermanReportType > ( `https://api.phisherman.gg/v2/phish/report` , { method : FetchMethods . Put , headers : { 'Content-Type' : 'application/json' , 'User-Agent' : `Sapphire Phisherman/1.0.0 (node-fetch) ${ os . platform ( ) }/${ os . release ( ) } (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)` , Authorization : `Bearer ${ apiKey }` } , body : JSON . stringify ( { url : domain } ) } , FetchResultTypes . JSON ) ; } param key since export async function setApiKey ( key ) { await checkApiKey ( key ) ; storedApiKey = key ; } async function checkApiKey ( apiKey ) { try { await fetch < { message : string ; success : false ; } > ( `https://api.phisherman.gg/v2/domains/check/verified.test.phisherman.gg` , { headers : { 'Content-Type' : 'application/json' , 'User-Agent' : `Sapphire Phisherman/1.0.0 (node-fetch) ${ os . platform ( ) }/${ os . release ( ) } (https://github.com/sapphiredev/utilities/tree/main/packages/phisherman)` , Authorization : `Bearer ${ apiKey }` } } , FetchResultTypes . JSON ) ; } catch ( error ) { const typedError = error as QueryError ; if ( typedError . code === 401 && typedError . toJSON ( ) . message === 'missing permissions or invalid API key' ) { throw new Error ( '[SapphirePhisherman]: Invalid API key provided' ) ; } throw error ; } }