0
create script
One script reply has been approved by the moderators Verified
Created by admin 198 days ago Viewed 78 times
0
Submitted by admin Typescript (fetch-only)
Verified 198 days ago
1
/**
2
 * create script
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  body: {
8
    path: string;
9
    parent_hash?: string;
10
    summary: string;
11
    description: string;
12
    content: string;
13
    schema?: { [k: string]: unknown };
14
    is_template?: boolean;
15
    lock?: string[];
16
    language:
17
      | "python3"
18
      | "deno"
19
      | "go"
20
      | "bash"
21
      | "powershell"
22
      | "postgresql"
23
      | "mysql"
24
      | "bigquery"
25
      | "snowflake"
26
      | "graphql"
27
      | "nativets"
28
      | "bun";
29
    kind?: "script" | "failure" | "trigger" | "command" | "approval";
30
    tag?: string;
31
    draft_only?: boolean;
32
    envs?: string[];
33
    concurrent_limit?: number;
34
    concurrency_time_window_s?: number;
35
    cache_ttl?: number;
36
    dedicated_worker?: boolean;
37
    ws_error_handler_muted?: boolean;
38
    priority?: number;
39
    [k: string]: unknown;
40
  }
41
) {
42
  const url = new URL(`${BASE_URL}/api/w/${workspace}/scripts/create`);
43

44
  const response = await fetch(url, {
45
    method: "POST",
46
    headers: {
47
      "Content-Type": "application/json",
48
      Authorization: "Bearer " + WM_TOKEN,
49
    },
50
    body: JSON.stringify(body),
51
  });
52
  if (!response.ok) {
53
    const text = await response.text();
54
    throw new Error(`${response.status} ${text}`);
55
  }
56
  return await response.text();
57
}
58