Update waiting room

Updates a configured waiting room.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Update waiting room
8
 * Updates a configured waiting room.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  waiting_room_id: string,
13
  zone_identifier: string,
14
  body: {
15
    additional_routes?: {
16
      host?: string;
17
      path?: string;
18
      [k: string]: unknown;
19
    }[];
20
    cookie_attributes?: {
21
      samesite?: "auto" | "lax" | "none" | "strict";
22
      secure?: "auto" | "always" | "never";
23
      [k: string]: unknown;
24
    };
25
    cookie_suffix?: string;
26
    custom_page_html?: string;
27
    default_template_language?:
28
      | "en-US"
29
      | "es-ES"
30
      | "de-DE"
31
      | "fr-FR"
32
      | "it-IT"
33
      | "ja-JP"
34
      | "ko-KR"
35
      | "pt-BR"
36
      | "zh-CN"
37
      | "zh-TW"
38
      | "nl-NL"
39
      | "pl-PL"
40
      | "id-ID"
41
      | "tr-TR"
42
      | "ar-EG"
43
      | "ru-RU"
44
      | "fa-IR";
45
    description?: string;
46
    disable_session_renewal?: boolean;
47
    host: string;
48
    json_response_enabled?: boolean;
49
    name: string;
50
    new_users_per_minute: number;
51
    path?: string;
52
    queue_all?: boolean;
53
    queueing_method?: "fifo" | "random" | "passthrough" | "reject";
54
    queueing_status_code?: 200 | 202 | 429;
55
    session_duration?: number;
56
    suspended?: boolean;
57
    total_active_users: number;
58
    [k: string]: unknown;
59
  }
60
) {
61
  const url = new URL(
62
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/waiting_rooms/${waiting_room_id}`
63
  );
64

65
  const response = await fetch(url, {
66
    method: "PUT",
67
    headers: {
68
      "X-AUTH-EMAIL": auth.email,
69
      "X-AUTH-KEY": auth.key,
70
      "Content-Type": "application/json",
71
      Authorization: "Bearer " + auth.token,
72
    },
73
    body: JSON.stringify(body),
74
  });
75
  if (!response.ok) {
76
    const text = await response.text();
77
    throw new Error(`${response.status} ${text}`);
78
  }
79
  return await response.json();
80
}
81