Edits history of script submission #5101 for ' List DNS Records (cloudflare)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * List DNS Records
     * List, search, sort, and filter a zones' DNS records.
     */
    export async function main(
      auth: Cloudflare,
      zone_identifier: string,
      name: string | undefined,
      type:
        | "A"
        | "AAAA"
        | "CAA"
        | "CERT"
        | "CNAME"
        | "DNSKEY"
        | "DS"
        | "HTTPS"
        | "LOC"
        | "MX"
        | "NAPTR"
        | "NS"
        | "PTR"
        | "SMIMEA"
        | "SRV"
        | "SSHFP"
        | "SVCB"
        | "TLSA"
        | "TXT"
        | "URI"
        | undefined,
      content: string | undefined,
      proxied: string | undefined,
      match: "any" | "all" | undefined,
      comment: string | undefined,
      comment_present: string | undefined,
      comment_absent: string | undefined,
      comment_exact: string | undefined,
      comment_contains: string | undefined,
      comment_startswith: string | undefined,
      comment_endswith: string | undefined,
      tag: string | undefined,
      tag_present: string | undefined,
      tag_absent: string | undefined,
      tag_exact: string | undefined,
      tag_contains: string | undefined,
      tag_startswith: string | undefined,
      tag_endswith: string | undefined,
      search: string | undefined,
      tag_match: "any" | "all" | undefined,
      page: string | undefined,
      per_page: string | undefined,
      order: "type" | "name" | "content" | "ttl" | "proxied" | undefined,
      direction: "asc" | "desc" | undefined
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/dns_records`
      );
      for (const [k, v] of [
        ["name", name],
        ["type", type],
        ["content", content],
        ["proxied", proxied],
        ["match", match],
        ["comment", comment],
        ["comment.present", comment_present],
        ["comment.absent", comment_absent],
        ["comment.exact", comment_exact],
        ["comment.contains", comment_contains],
        ["comment.startswith", comment_startswith],
        ["comment.endswith", comment_endswith],
        ["tag", tag],
        ["tag.present", tag_present],
        ["tag.absent", tag_absent],
        ["tag.exact", tag_exact],
        ["tag.contains", tag_contains],
        ["tag.startswith", tag_startswith],
        ["tag.endswith", tag_endswith],
        ["search", search],
        ["tag_match", tag_match],
        ["page", page],
        ["per_page", per_page],
        ["order", order],
        ["direction", direction],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 383 days ago

  • nativets
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * List DNS Records
     * List, search, sort, and filter a zones' DNS records.
     */
    export async function main(
      auth: Cloudflare,
      zone_identifier: string,
      name: string | undefined,
      type:
        | "A"
        | "AAAA"
        | "CAA"
        | "CERT"
        | "CNAME"
        | "DNSKEY"
        | "DS"
        | "HTTPS"
        | "LOC"
        | "MX"
        | "NAPTR"
        | "NS"
        | "PTR"
        | "SMIMEA"
        | "SRV"
        | "SSHFP"
        | "SVCB"
        | "TLSA"
        | "TXT"
        | "URI"
        | undefined,
      content: string | undefined,
      proxied: string | undefined,
      match: "any" | "all" | undefined,
      comment: string | undefined,
      comment_present: string | undefined,
      comment_absent: string | undefined,
      comment_exact: string | undefined,
      comment_contains: string | undefined,
      comment_startswith: string | undefined,
      comment_endswith: string | undefined,
      tag: string | undefined,
      tag_present: string | undefined,
      tag_absent: string | undefined,
      tag_exact: string | undefined,
      tag_contains: string | undefined,
      tag_startswith: string | undefined,
      tag_endswith: string | undefined,
      search: string | undefined,
      tag_match: "any" | "all" | undefined,
      page: string | undefined,
      per_page: string | undefined,
      order: "type" | "name" | "content" | "ttl" | "proxied" | undefined,
      direction: "asc" | "desc" | undefined
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/dns_records`
      );
      for (const [k, v] of [
        ["name", name],
        ["type", type],
        ["content", content],
        ["proxied", proxied],
        ["match", match],
        ["comment", comment],
        ["comment.present", comment_present],
        ["comment.absent", comment_absent],
        ["comment.exact", comment_exact],
        ["comment.contains", comment_contains],
        ["comment.startswith", comment_startswith],
        ["comment.endswith", comment_endswith],
        ["tag", tag],
        ["tag.present", tag_present],
        ["tag.absent", tag_absent],
        ["tag.exact", tag_exact],
        ["tag.contains", tag_contains],
        ["tag.startswith", tag_startswith],
        ["tag.endswith", tag_endswith],
        ["search", search],
        ["tag_match", tag_match],
        ["page", page],
        ["per_page", per_page],
        ["order", order],
        ["direction", direction],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 920 days ago