0
create script
One script reply has been approved by the moderators Verified
Created by admin 251 days ago Viewed 4252 times
0
Submitted by admin Typescript (fetch-only)
Verified 251 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
      | "mssql"
27
      | "graphql"
28
      | "nativets"
29
      | "bun";
30
    kind?: "script" | "failure" | "trigger" | "command" | "approval";
31
    tag?: string;
32
    draft_only?: boolean;
33
    envs?: string[];
34
    concurrent_limit?: number;
35
    concurrency_time_window_s?: number;
36
    cache_ttl?: number;
37
    dedicated_worker?: boolean;
38
    ws_error_handler_muted?: boolean;
39
    priority?: number;
40
    restart_unless_cancelled?: boolean;
41
    timeout?: number;
42
    delete_after_use?: boolean;
43
    deployment_message?: string;
44
    concurrency_key?: string;
45
    [k: string]: unknown;
46
  }
47
) {
48
  const url = new URL(`${BASE_URL}/api/w/${workspace}/scripts/create`);
49

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