Edits history of script submission #12173 for ' Validate name data (foxentry)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Foxentry = {
      apiKey: string;
    };
    /**
     * Validate name data
     * Foxentry allows you to check the validity and real existence of names and their combinations.
     */
    export async function main(
      auth: Foxentry,
      api_version: string | undefined,
      foxentry_include_request_details: string | undefined,
      body: {
        request: {
          customId?: string;
          query: { name?: string; surname?: string } | { nameSurname: string };
          options?: {
            dataScope?: "basic" | "full";
            dataSource?: string[];
            acceptDegrees?: false | true;
            acceptContext?: false | true;
            validationDepth?: "minimal" | "moderate" | "strict";
            smartMode?: false | true;
          };
          client?: {
            ip?: string;
            country?: string;
            location?: { lat?: number; lon?: number };
          };
        };
      },
    ) {
      const url = new URL(`https://api.foxentry.com/name/validate`);
    
      const headers: Record<string, string> = {
        "Content-Type": "application/json",
        Authorization: "Bearer " + auth.apiKey,
      };
    
      if (api_version) {
        headers["api-version"] = api_version;
      }
      if (foxentry_include_request_details) {
        headers["foxentry-include-request-details"] = foxentry_include_request_details;
      }
    
      const response = await fetch(url, {
        method: "POST",
        headers,
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 428 days ago