Edits history of script submission #5614 for ' Update Member (cloudflare)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * Update Member
     * Modify an account member.
     */
    export async function main(
      auth: Cloudflare,
      identifier: string,
      account_identifier: string,
      body: {
        id: string;
        roles: {
          description: string;
          id: string;
          name: string;
          permissions: {
            analytics?: { read?: boolean; write?: boolean; [k: string]: unknown };
            billing?: { read?: boolean; write?: boolean; [k: string]: unknown };
            cache_purge?: { read?: boolean; write?: boolean; [k: string]: unknown };
            dns?: { read?: boolean; write?: boolean; [k: string]: unknown };
            dns_records?: { read?: boolean; write?: boolean; [k: string]: unknown };
            lb?: { read?: boolean; write?: boolean; [k: string]: unknown };
            logs?: { read?: boolean; write?: boolean; [k: string]: unknown };
            organization?: {
              read?: boolean;
              write?: boolean;
              [k: string]: unknown;
            };
            ssl?: { read?: boolean; write?: boolean; [k: string]: unknown };
            waf?: { read?: boolean; write?: boolean; [k: string]: unknown };
            zone_settings?: {
              read?: boolean;
              write?: boolean;
              [k: string]: unknown;
            };
            zones?: { read?: boolean; write?: boolean; [k: string]: unknown };
            [k: string]: unknown;
          } & { [k: string]: unknown };
          [k: string]: unknown;
        }[];
        status: { [k: string]: unknown };
        user: {
          email: string;
          first_name?: string;
          id?: string;
          last_name?: string;
          two_factor_authentication_enabled?: boolean;
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/members/${identifier}`
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        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 383 days ago

  • nativets
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * Update Member
     * Modify an account member.
     */
    export async function main(
      auth: Cloudflare,
      identifier: string,
      account_identifier: string,
      body: {
        id: string;
        roles: {
          description: string;
          id: string;
          name: string;
          permissions: {
            analytics?: { read?: boolean; write?: boolean; [k: string]: unknown };
            billing?: { read?: boolean; write?: boolean; [k: string]: unknown };
            cache_purge?: { read?: boolean; write?: boolean; [k: string]: unknown };
            dns?: { read?: boolean; write?: boolean; [k: string]: unknown };
            dns_records?: { read?: boolean; write?: boolean; [k: string]: unknown };
            lb?: { read?: boolean; write?: boolean; [k: string]: unknown };
            logs?: { read?: boolean; write?: boolean; [k: string]: unknown };
            organization?: {
              read?: boolean;
              write?: boolean;
              [k: string]: unknown;
            };
            ssl?: { read?: boolean; write?: boolean; [k: string]: unknown };
            waf?: { read?: boolean; write?: boolean; [k: string]: unknown };
            zone_settings?: {
              read?: boolean;
              write?: boolean;
              [k: string]: unknown;
            };
            zones?: { read?: boolean; write?: boolean; [k: string]: unknown };
            [k: string]: unknown;
          } & { [k: string]: unknown };
          [k: string]: unknown;
        }[];
        status: { [k: string]: unknown };
        user: {
          email: string;
          first_name?: string;
          id?: string;
          last_name?: string;
          two_factor_authentication_enabled?: boolean;
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/members/${identifier}`
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        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 920 days ago