0

List Workspace Regulations

by
Published Oct 17, 2025

Lists all Workspace-scoped regulations.

Script segment Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Segment = {
3
  token: string;
4
  baseUrl: string;
5
};
6
/**
7
 * List Workspace Regulations
8
 * Lists all Workspace-scoped regulations.
9
 */
10
export async function main(
11
  auth: Segment,
12
  status:
13
    | "FAILED"
14
    | "FINISHED"
15
    | "INITIALIZED"
16
    | "INVALID"
17
    | "NOT_SUPPORTED"
18
    | "PARTIAL_SUCCESS"
19
    | "RUNNING"
20
    | undefined,
21
  regulationTypes: string | undefined,
22
  pagination: string | undefined,
23
) {
24
  const url = new URL(`${auth.baseUrl}/regulations`);
25
  for (const [k, v] of [
26
    ["status", status],
27
    ["regulationTypes", regulationTypes],
28
    ["pagination", pagination],
29
  ]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "GET",
36
    headers: {
37
      Authorization: "Bearer " + auth.token,
38
    },
39
    body: undefined,
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47