0

List Regulations from Source

by
Published Oct 17, 2025

Lists all Source-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 Regulations from Source
8
 * Lists all Source-scoped regulations.
9
 */
10
export async function main(
11
  auth: Segment,
12
  sourceId: string,
13
  status:
14
    | "FAILED"
15
    | "FINISHED"
16
    | "INITIALIZED"
17
    | "INVALID"
18
    | "NOT_SUPPORTED"
19
    | "PARTIAL_SUCCESS"
20
    | "RUNNING"
21
    | undefined,
22
  regulationTypes: string | undefined,
23
  pagination: string | undefined,
24
) {
25
  const url = new URL(
26
    `${auth.baseUrl}/regulations/sources/${sourceId}`,
27
  );
28
  for (const [k, v] of [
29
    ["status", status],
30
    ["regulationTypes", regulationTypes],
31
    ["pagination", pagination],
32
  ]) {
33
    if (v !== undefined && v !== "" && k !== undefined) {
34
      url.searchParams.append(k, v);
35
    }
36
  }
37
  const response = await fetch(url, {
38
    method: "GET",
39
    headers: {
40
      Authorization: "Bearer " + auth.token,
41
    },
42
    body: undefined,
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50