drej 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/package.json +1 -1
- package/src/client.ts +27 -1
- package/src/index.ts +2 -2
- package/tsconfig.json +12 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# drej
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c3fe034: Add `DrejClient.run(code)` method and `SandboxRunResult` type for submitting code to the sandbox execution endpoint.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 3316570: Add `DrejError` class with HTTP status code — errors from API calls now throw `DrejError` instead of a generic `Error`.
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
+
export class DrejError extends Error {
|
|
2
|
+
constructor(
|
|
3
|
+
message: string,
|
|
4
|
+
public readonly status: number,
|
|
5
|
+
) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "DrejError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
export interface DrejClientOptions {
|
|
2
12
|
baseUrl?: string;
|
|
3
13
|
}
|
|
4
14
|
|
|
15
|
+
export interface SandboxRunResult {
|
|
16
|
+
id: string;
|
|
17
|
+
code: string;
|
|
18
|
+
status: "queued";
|
|
19
|
+
}
|
|
20
|
+
|
|
5
21
|
export class DrejClient {
|
|
6
22
|
private baseUrl: string;
|
|
7
23
|
|
|
@@ -11,7 +27,17 @@ export class DrejClient {
|
|
|
11
27
|
|
|
12
28
|
async health(): Promise<{ healthy: boolean }> {
|
|
13
29
|
const res = await fetch(`${this.baseUrl}/health`);
|
|
14
|
-
if (!res.ok) throw new
|
|
30
|
+
if (!res.ok) throw new DrejError(`drej API error`, res.status);
|
|
31
|
+
return res.json();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async run(code: string): Promise<SandboxRunResult> {
|
|
35
|
+
const res = await fetch(`${this.baseUrl}/sandbox/run`, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: { "Content-Type": "application/json" },
|
|
38
|
+
body: JSON.stringify({ code }),
|
|
39
|
+
});
|
|
40
|
+
if (!res.ok) throw new DrejError(`drej API error`, res.status);
|
|
15
41
|
return res.json();
|
|
16
42
|
}
|
|
17
43
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { DrejClient } from "./client";
|
|
2
|
-
export type { DrejClientOptions } from "./client";
|
|
1
|
+
export { DrejClient, DrejError } from "./client";
|
|
2
|
+
export type { DrejClientOptions, SandboxRunResult } from "./client";
|