track-cli 3.0.0-rc
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/LICENSE +7 -0
- package/README.md +3 -0
- package/esm/_dnt.polyfills.d.ts +6 -0
- package/esm/_dnt.polyfills.js +1 -0
- package/esm/_dnt.shims.d.ts +19 -0
- package/esm/_dnt.shims.js +78 -0
- package/esm/deps/deno.land/std@0.170.0/fmt/colors.d.ts +270 -0
- package/esm/deps/deno.land/std@0.170.0/fmt/colors.js +473 -0
- package/esm/deps/deno.land/std@0.195.0/_util/os.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/_util/os.js +18 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assert.js +8 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.d.ts +4 -0
- package/esm/deps/deno.land/std@0.195.0/assert/assertion_error.js +12 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/_common.d.ts +50 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/_common.js +545 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/constants.d.ts +55 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/constants.js +57 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.d.ts +26 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/day_of_year.js +45 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/difference.d.ts +38 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/difference.js +93 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/format.d.ts +22 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/format.js +28 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.d.ts +49 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/is_leap.js +60 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/mod.d.ts +43 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/mod.js +45 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/parse.d.ts +21 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/parse.js +29 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.d.ts +17 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/to_imf.js +44 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.d.ts +13 -0
- package/esm/deps/deno.land/std@0.195.0/datetime/week_of_year.js +38 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/colors.d.ts +270 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/colors.js +474 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/duration.d.ts +15 -0
- package/esm/deps/deno.land/std@0.195.0/fmt/duration.js +96 -0
- package/esm/deps/deno.land/std@0.195.0/fs/_util.d.ts +35 -0
- package/esm/deps/deno.land/std@0.195.0/fs/_util.js +80 -0
- package/esm/deps/deno.land/std@0.195.0/fs/copy.d.ts +51 -0
- package/esm/deps/deno.land/std@0.195.0/fs/copy.js +244 -0
- package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.d.ts +31 -0
- package/esm/deps/deno.land/std@0.195.0/fs/empty_dir.js +74 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.d.ts +27 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_dir.js +55 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.d.ts +33 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_file.js +75 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.d.ts +31 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_link.js +43 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.d.ts +17 -0
- package/esm/deps/deno.land/std@0.195.0/fs/ensure_symlink.js +68 -0
- package/esm/deps/deno.land/std@0.195.0/fs/eol.d.ts +40 -0
- package/esm/deps/deno.land/std@0.195.0/fs/eol.js +53 -0
- package/esm/deps/deno.land/std@0.195.0/fs/exists.d.ts +102 -0
- package/esm/deps/deno.land/std@0.195.0/fs/exists.js +163 -0
- package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.d.ts +37 -0
- package/esm/deps/deno.land/std@0.195.0/fs/expand_glob.js +216 -0
- package/esm/deps/deno.land/std@0.195.0/fs/mod.d.ts +16 -0
- package/esm/deps/deno.land/std@0.195.0/fs/mod.js +17 -0
- package/esm/deps/deno.land/std@0.195.0/fs/move.d.ts +29 -0
- package/esm/deps/deno.land/std@0.195.0/fs/move.js +88 -0
- package/esm/deps/deno.land/std@0.195.0/fs/walk.d.ts +40 -0
- package/esm/deps/deno.land/std@0.195.0/fs/walk.js +158 -0
- package/esm/deps/deno.land/std@0.195.0/path/_constants.d.ts +39 -0
- package/esm/deps/deno.land/std@0.195.0/path/_constants.js +46 -0
- package/esm/deps/deno.land/std@0.195.0/path/_interface.d.ts +26 -0
- package/esm/deps/deno.land/std@0.195.0/path/_interface.js +3 -0
- package/esm/deps/deno.land/std@0.195.0/path/_util.d.ts +11 -0
- package/esm/deps/deno.land/std@0.195.0/path/_util.js +161 -0
- package/esm/deps/deno.land/std@0.195.0/path/common.d.ts +13 -0
- package/esm/deps/deno.land/std@0.195.0/path/common.js +36 -0
- package/esm/deps/deno.land/std@0.195.0/path/glob.d.ts +83 -0
- package/esm/deps/deno.land/std@0.195.0/path/glob.js +361 -0
- package/esm/deps/deno.land/std@0.195.0/path/mod.d.ts +9 -0
- package/esm/deps/deno.land/std@0.195.0/path/mod.js +33 -0
- package/esm/deps/deno.land/std@0.195.0/path/posix.d.ts +86 -0
- package/esm/deps/deno.land/std@0.195.0/path/posix.js +442 -0
- package/esm/deps/deno.land/std@0.195.0/path/separator.d.ts +2 -0
- package/esm/deps/deno.land/std@0.195.0/path/separator.js +5 -0
- package/esm/deps/deno.land/std@0.195.0/path/win32.d.ts +91 -0
- package/esm/deps/deno.land/std@0.195.0/path/win32.js +909 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/_utils/distance.js +26 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.d.ts +76 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_errors.js +154 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.d.ts +32 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/_utils.js +105 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.d.ts +831 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/command.js +1701 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.d.ts +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_bash_completions_generator.js +201 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_fish_completions_generator.js +141 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.d.ts +21 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/_zsh_completions_generator.js +285 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/bash.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.d.ts +8 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/complete.js +32 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/fish.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/mod.js +46 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/completions/zsh.js +38 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.d.ts +45 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deprecated.js +2 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/deps.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.d.ts +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/_help_generator.js +323 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/help/mod.js +34 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.d.ts +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/mod.js +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.d.ts +41 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/type.js +24 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/action_list.js +20 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/boolean.js +13 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.d.ts +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/child_command.js +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/command.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.d.ts +10 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/enum.js +29 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.d.ts +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/file.js +12 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/integer.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/number.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.d.ts +7 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types/string.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.d.ts +118 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/types.js +2 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.d.ts +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/mod.js +5 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/deno_land.js +46 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.d.ts +26 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/github.js +118 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.d.ts +14 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider/nest_land.js +55 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.d.ts +27 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/provider.js +102 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.d.ts +17 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/command/upgrade/upgrade_command.js +75 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.d.ts +60 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_errors.js +117 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.d.ts +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_utils.js +106 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.d.ts +10 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/_validate_flags.js +157 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.d.ts +24 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/deprecated.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.d.ts +33 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/flags.js +402 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/boolean.js +11 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/integer.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/number.js +9 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.d.ts +3 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types/string.js +4 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.d.ts +59 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/flags/types.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.d.ts +20 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/border.js +18 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.d.ts +78 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/cell.js +128 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.d.ts +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/deps.js +1 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.d.ts +99 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/layout.js +529 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.d.ts +49 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/row.js +74 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.d.ts +135 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/table.js +237 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.d.ts +13 -0
- package/esm/deps/deno.land/x/cliffy@v0.25.7/table/utils.js +60 -0
- package/esm/package.json +3 -0
- package/esm/src/action/add.d.ts +1 -0
- package/esm/src/action/add.js +57 -0
- package/esm/src/action/clone.d.ts +6 -0
- package/esm/src/action/clone.js +108 -0
- package/esm/src/action/lang.d.ts +1 -0
- package/esm/src/action/lang.js +40 -0
- package/esm/src/action/pull.d.ts +1 -0
- package/esm/src/action/pull.js +22 -0
- package/esm/src/action/remove.d.ts +4 -0
- package/esm/src/action/remove.js +67 -0
- package/esm/src/action/reset.d.ts +1 -0
- package/esm/src/action/reset.js +21 -0
- package/esm/src/action/run.d.ts +4 -0
- package/esm/src/action/run.js +163 -0
- package/esm/src/action/status.d.ts +1 -0
- package/esm/src/action/status.js +5 -0
- package/esm/src/main.d.ts +2 -0
- package/esm/src/main.js +96 -0
- package/esm/src/meta.d.ts +3 -0
- package/esm/src/meta.js +51 -0
- package/esm/src/orca/client.d.ts +20 -0
- package/esm/src/orca/client.js +152 -0
- package/esm/src/orca/types.d.ts +54 -0
- package/esm/src/orca/types.js +12 -0
- package/esm/src/shared/config.d.ts +24 -0
- package/esm/src/shared/config.js +24 -0
- package/esm/src/shared/errors.d.ts +82 -0
- package/esm/src/shared/errors.js +228 -0
- package/esm/src/shared/file.d.ts +30 -0
- package/esm/src/shared/file.js +110 -0
- package/esm/src/shared/mod.d.ts +40 -0
- package/esm/src/shared/mod.js +383 -0
- package/esm/src/shared/types.d.ts +12 -0
- package/esm/src/shared/types.js +1 -0
- package/esm/src/track/client.d.ts +60 -0
- package/esm/src/track/client.js +268 -0
- package/esm/src/track/types.d.ts +210 -0
- package/esm/src/track/types.js +40 -0
- package/package.json +35 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { VERSION } from "../meta.js";
|
|
2
|
+
import { HttpStatus } from "../shared/mod.js";
|
|
3
|
+
import { APIError, OtherError } from "../shared/errors.js";
|
|
4
|
+
// @ts-ignore: has no exported member
|
|
5
|
+
import { CookieJar, fetch } from "node-fetch-cookies";
|
|
6
|
+
import ProxyAgent from "proxy-agent";
|
|
7
|
+
export const FormType = {
|
|
8
|
+
URLEncoded: "urlencoded",
|
|
9
|
+
JSON: "json",
|
|
10
|
+
};
|
|
11
|
+
export class TrackClient {
|
|
12
|
+
constructor(scheme, hostname, basic, authData) {
|
|
13
|
+
Object.defineProperty(this, "baseUrl", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "headers", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(this, "cookies", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(this, "authData", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: void 0
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "cookieExpired", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: false
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(this, "agent", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
writable: true,
|
|
47
|
+
value: new ProxyAgent()
|
|
48
|
+
});
|
|
49
|
+
this.baseUrl = `${scheme}://${hostname}`;
|
|
50
|
+
this.headers = {};
|
|
51
|
+
this.headers["X-Requested-With"] = "codecheck";
|
|
52
|
+
this.headers["User-Agent"] = `track-cli-${VERSION}`;
|
|
53
|
+
if (basic) {
|
|
54
|
+
this.headers["Authorization"] = `Basic ${btoa(`${basic.username}:${basic.password}`)}`;
|
|
55
|
+
}
|
|
56
|
+
this.cookies = new CookieJar();
|
|
57
|
+
this.authData = authData;
|
|
58
|
+
}
|
|
59
|
+
getCookies() {
|
|
60
|
+
const cookies = {};
|
|
61
|
+
for (const cookie of this.cookies.cookiesAll()) {
|
|
62
|
+
if (cookie.name && cookie.value) {
|
|
63
|
+
cookies[cookie.name] = cookie.value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return cookies;
|
|
67
|
+
}
|
|
68
|
+
authCookieExpired() {
|
|
69
|
+
return this.cookieExpired;
|
|
70
|
+
}
|
|
71
|
+
static fromTrackConfig(config) {
|
|
72
|
+
const authData = {
|
|
73
|
+
examToken: config.examToken,
|
|
74
|
+
orgName: config.orgName,
|
|
75
|
+
};
|
|
76
|
+
const client = new TrackClient(config.scheme, config.host, config.basicAuth, authData);
|
|
77
|
+
if (config.cookies) {
|
|
78
|
+
for (const [name, value] of Object.entries(config.cookies)) {
|
|
79
|
+
client.cookies.addCookie(`${name}=${value}`, client.baseUrl);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return client;
|
|
83
|
+
}
|
|
84
|
+
async authenticate() {
|
|
85
|
+
this.cookies = new CookieJar();
|
|
86
|
+
if (this.authData) {
|
|
87
|
+
const authUrl = `${this.baseUrl}/${this.authData.orgName}/exams/${this.authData.examToken}`;
|
|
88
|
+
const res = await fetch(this.cookies, authUrl, {
|
|
89
|
+
headers: this.headers,
|
|
90
|
+
agent: this.agent,
|
|
91
|
+
});
|
|
92
|
+
if (!HttpStatus.isSuccess(res)) {
|
|
93
|
+
throw new OtherError(`Failed to authenticate: ${res.status}\n${await res.text()}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async _get(path, asText = false) {
|
|
98
|
+
const url = `${this.baseUrl}${path}`;
|
|
99
|
+
const response1 = await fetch(this.cookies, url, {
|
|
100
|
+
method: "GET",
|
|
101
|
+
headers: this.headers,
|
|
102
|
+
agent: this.agent,
|
|
103
|
+
});
|
|
104
|
+
if (response1.status !== HttpStatus.Unauthorized) {
|
|
105
|
+
return await this._result(response1, asText);
|
|
106
|
+
}
|
|
107
|
+
await this.authenticate();
|
|
108
|
+
this.cookieExpired = true;
|
|
109
|
+
const response2 = await fetch(this.cookies, url, {
|
|
110
|
+
method: "GET",
|
|
111
|
+
headers: this.headers,
|
|
112
|
+
agent: this.agent,
|
|
113
|
+
});
|
|
114
|
+
return await this._result(response2, asText);
|
|
115
|
+
}
|
|
116
|
+
async _post(path, formType, body) {
|
|
117
|
+
const url = `${this.baseUrl}${path}`;
|
|
118
|
+
const headers = Object.assign({}, this.headers);
|
|
119
|
+
let bodyData;
|
|
120
|
+
switch (formType) {
|
|
121
|
+
case FormType.URLEncoded:
|
|
122
|
+
bodyData = new URLSearchParams();
|
|
123
|
+
for (const [key, value] of Object.entries(body)) {
|
|
124
|
+
bodyData.append(key, value);
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
case FormType.JSON:
|
|
128
|
+
bodyData = JSON.stringify(body);
|
|
129
|
+
headers["Content-Type"] = "application/json";
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
const response1 = await fetch(this.cookies, url, {
|
|
133
|
+
method: "POST",
|
|
134
|
+
headers: headers,
|
|
135
|
+
body: bodyData,
|
|
136
|
+
agent: this.agent,
|
|
137
|
+
});
|
|
138
|
+
if (response1.status !== HttpStatus.Unauthorized) {
|
|
139
|
+
return await this._result(response1);
|
|
140
|
+
}
|
|
141
|
+
await this.authenticate();
|
|
142
|
+
this.cookieExpired = true;
|
|
143
|
+
const response2 = await fetch(this.cookies, url, {
|
|
144
|
+
method: "POST",
|
|
145
|
+
headers: headers,
|
|
146
|
+
body: bodyData,
|
|
147
|
+
agent: this.agent,
|
|
148
|
+
});
|
|
149
|
+
return await this._result(response2);
|
|
150
|
+
}
|
|
151
|
+
async _put(path, formType, body) {
|
|
152
|
+
const url = `${this.baseUrl}${path}`;
|
|
153
|
+
const headers = Object.assign({}, this.headers);
|
|
154
|
+
let bodyData;
|
|
155
|
+
switch (formType) {
|
|
156
|
+
case FormType.URLEncoded:
|
|
157
|
+
bodyData = new URLSearchParams();
|
|
158
|
+
for (const [key, value] of Object.entries(body)) {
|
|
159
|
+
bodyData.append(key, value);
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
case FormType.JSON:
|
|
163
|
+
bodyData = JSON.stringify(body);
|
|
164
|
+
headers["Content-Type"] = "application/json";
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
const response1 = await fetch(this.cookies, url, {
|
|
168
|
+
method: "PUT",
|
|
169
|
+
headers: headers,
|
|
170
|
+
body: bodyData,
|
|
171
|
+
agent: this.agent,
|
|
172
|
+
});
|
|
173
|
+
if (response1.status !== HttpStatus.Unauthorized) {
|
|
174
|
+
return await this._result(response1);
|
|
175
|
+
}
|
|
176
|
+
await this.authenticate();
|
|
177
|
+
this.cookieExpired = true;
|
|
178
|
+
const response2 = await fetch(this.cookies, url, {
|
|
179
|
+
method: "PUT",
|
|
180
|
+
headers: headers,
|
|
181
|
+
body: bodyData,
|
|
182
|
+
agent: this.agent,
|
|
183
|
+
});
|
|
184
|
+
return await this._result(response2);
|
|
185
|
+
}
|
|
186
|
+
async _result(response, asText = false) {
|
|
187
|
+
if (HttpStatus.isSuccess(response)) {
|
|
188
|
+
if (asText) {
|
|
189
|
+
return (await response.text());
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
const json = await response.json();
|
|
193
|
+
if (json.result) {
|
|
194
|
+
return json.result;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
throw APIError.serializationError(await response.text());
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
throw await APIError.fromResponse(response);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async getApplicantExamNoAuth(token) {
|
|
206
|
+
return await this._get(`/api/applicants/exams/${token}/min`);
|
|
207
|
+
}
|
|
208
|
+
async getExamSession(applicantExamId) {
|
|
209
|
+
return await this._get(`/api/applicants/exams/${applicantExamId}`);
|
|
210
|
+
}
|
|
211
|
+
async getProgrammingLanguages() {
|
|
212
|
+
return await this._get(`/api/enum/challenges/programminglanguages`);
|
|
213
|
+
}
|
|
214
|
+
async findProgrammingLanguage(programmingLanguage) {
|
|
215
|
+
return (await this.getProgrammingLanguages())
|
|
216
|
+
.find((pl, _) => pl.value === programmingLanguage);
|
|
217
|
+
}
|
|
218
|
+
async switchChallengeLanguage(applicantExamId, resultId, language) {
|
|
219
|
+
return await this._put(`/api/applicants/exams/${applicantExamId}/results/${resultId}/language`, FormType.URLEncoded, {
|
|
220
|
+
programmingLanguage: language,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
async startChallenge(applicantExamId, resultId) {
|
|
224
|
+
return await this._put(`/api/applicants/exams/${applicantExamId}/results/${resultId}/start`, FormType.URLEncoded, {
|
|
225
|
+
takenBy: 3, // 3 = LocalMachine
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
async prepareChallenge(applicantExamId, challengeId) {
|
|
229
|
+
return await this._post(`/api/applicants/exams/${applicantExamId}/results`, FormType.URLEncoded, {
|
|
230
|
+
challengeId: challengeId,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
async timeLeft(applicantExamId, resultId) {
|
|
234
|
+
return await this._get(`/api/applicants/exams/${applicantExamId}/results/${resultId}/timeleft`);
|
|
235
|
+
}
|
|
236
|
+
async getChallengeCodingContext(applicantExamId, resultId) {
|
|
237
|
+
return await this._get(`/api/applicants/exams/${applicantExamId}/results/${resultId}/context`);
|
|
238
|
+
}
|
|
239
|
+
async getPresignedUrls(applicantExamId, resultId, files) {
|
|
240
|
+
return await this._post(`/api/applicants/exams/${applicantExamId}/results/${resultId}/presigned`, FormType.JSON, {
|
|
241
|
+
files: files,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
async orcaToken(url) {
|
|
245
|
+
return await this._get(url);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Temporary code to retrieve the Orca host.
|
|
249
|
+
* Will be able to get from CodingContext in the future.
|
|
250
|
+
*/
|
|
251
|
+
async orcaHost() {
|
|
252
|
+
const asText = true;
|
|
253
|
+
const editorHtml = await this._get("/editor/1.0/coding", asText);
|
|
254
|
+
return (/data-orca-host="([^"]+)"/.exec(editorHtml) ||
|
|
255
|
+
["", "track-prod-frontend.orca.run"])[1];
|
|
256
|
+
}
|
|
257
|
+
async saveFiles(applicantExamId, resultId, saveFilesRequest) {
|
|
258
|
+
return await this._put(`/api/applicants/exams/${applicantExamId}/results/${resultId}/save`, FormType.JSON, saveFilesRequest);
|
|
259
|
+
}
|
|
260
|
+
async updateEditorScore(applicantExamId, resultId, editorScore) {
|
|
261
|
+
return await this._put(`/api/applicants/exams/${applicantExamId}/results/${resultId}/editorScore`, FormType.URLEncoded, {
|
|
262
|
+
editorScore: editorScore,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
async reset(applicantExamId, resultId) {
|
|
266
|
+
return await this._put(`/api/applicants/exams/${applicantExamId}/results/${resultId}/reset`, FormType.URLEncoded, {});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
export declare const ApplicantExamStatus: {
|
|
2
|
+
readonly Unread: 1;
|
|
3
|
+
readonly InProgress: 2;
|
|
4
|
+
readonly Submitted: 3;
|
|
5
|
+
readonly Expired: 4;
|
|
6
|
+
readonly Canceled: 5;
|
|
7
|
+
readonly Reviewed: 6;
|
|
8
|
+
};
|
|
9
|
+
export type ApplicantExamStatus = (typeof ApplicantExamStatus)[keyof typeof ApplicantExamStatus];
|
|
10
|
+
export declare const ChallengeStyle: {
|
|
11
|
+
readonly Quiz: 1;
|
|
12
|
+
readonly Development: 2;
|
|
13
|
+
readonly Algorithm: 3;
|
|
14
|
+
readonly Ai: 4;
|
|
15
|
+
};
|
|
16
|
+
export type ChallengeStyle = (typeof ChallengeStyle)[keyof typeof ChallengeStyle];
|
|
17
|
+
export declare const ChallengeResultStatus: {
|
|
18
|
+
readonly Prepared: 0;
|
|
19
|
+
readonly Started: 1;
|
|
20
|
+
readonly InProgress: 2;
|
|
21
|
+
readonly Finished: 3;
|
|
22
|
+
readonly NotModified: 4;
|
|
23
|
+
readonly CanRestart: 5;
|
|
24
|
+
readonly ScoringWaiting: 6;
|
|
25
|
+
};
|
|
26
|
+
export type ChallengeResultStatus = (typeof ChallengeResultStatus)[keyof typeof ChallengeResultStatus];
|
|
27
|
+
export declare const SpokenLanguage: {
|
|
28
|
+
readonly English: "en";
|
|
29
|
+
readonly Japanese: "ja";
|
|
30
|
+
};
|
|
31
|
+
export type SpokenLanguage = (typeof SpokenLanguage)[keyof typeof SpokenLanguage];
|
|
32
|
+
export type ProgrammingLanguage = number;
|
|
33
|
+
export interface ProgrammingLanguageInfo {
|
|
34
|
+
value: ProgrammingLanguage;
|
|
35
|
+
displayOrder: number;
|
|
36
|
+
messageKey: string;
|
|
37
|
+
displayString: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ApplicantExamForNoAuth {
|
|
40
|
+
id: number;
|
|
41
|
+
applicantId: number;
|
|
42
|
+
examId: number;
|
|
43
|
+
organizationId: number;
|
|
44
|
+
organizationImageUrl?: string;
|
|
45
|
+
organizationName: string;
|
|
46
|
+
examName: string;
|
|
47
|
+
urlToken: string;
|
|
48
|
+
status: ApplicantExamStatus;
|
|
49
|
+
openedAt?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface ApplicantExam {
|
|
52
|
+
id: number;
|
|
53
|
+
applicantId: number;
|
|
54
|
+
examId: number;
|
|
55
|
+
deliveryId: number;
|
|
56
|
+
deadline: string;
|
|
57
|
+
urlToken: string;
|
|
58
|
+
status: ApplicantExamStatus;
|
|
59
|
+
isTest: boolean;
|
|
60
|
+
createdAt: string;
|
|
61
|
+
updatedAt: string;
|
|
62
|
+
}
|
|
63
|
+
export interface Applicant {
|
|
64
|
+
id: number;
|
|
65
|
+
organizationId: number;
|
|
66
|
+
userId?: number;
|
|
67
|
+
email: string;
|
|
68
|
+
fullName?: string;
|
|
69
|
+
createdAt: string;
|
|
70
|
+
updatedAt: string;
|
|
71
|
+
}
|
|
72
|
+
export interface ChallengesSet {
|
|
73
|
+
challenges: ExamSessionChallenge[];
|
|
74
|
+
}
|
|
75
|
+
export interface ExamSession {
|
|
76
|
+
id: number;
|
|
77
|
+
deadline: string;
|
|
78
|
+
urlToken: string;
|
|
79
|
+
status: ApplicantExamStatus;
|
|
80
|
+
applicant: Applicant;
|
|
81
|
+
challengesSets: ChallengesSet[];
|
|
82
|
+
results: ChallengeResult[];
|
|
83
|
+
}
|
|
84
|
+
export interface ExamSessionChallenge {
|
|
85
|
+
id: number;
|
|
86
|
+
challengeVersionId: number;
|
|
87
|
+
style: ChallengeStyle;
|
|
88
|
+
title: string;
|
|
89
|
+
description?: string;
|
|
90
|
+
timeLimitMinutes?: number;
|
|
91
|
+
displayOrder: number;
|
|
92
|
+
weight: number;
|
|
93
|
+
localExamEnabled: boolean;
|
|
94
|
+
openTestcases?: number;
|
|
95
|
+
programmingLanguages: ProgrammingLanguage[];
|
|
96
|
+
}
|
|
97
|
+
export interface ChallengeResult {
|
|
98
|
+
id: number;
|
|
99
|
+
challengeId: number;
|
|
100
|
+
challengeVersionId: number;
|
|
101
|
+
applicantId: number;
|
|
102
|
+
applicantExamId: number;
|
|
103
|
+
dueDate?: string;
|
|
104
|
+
storageId: string;
|
|
105
|
+
status: ChallengeResultStatus;
|
|
106
|
+
openedAt?: string;
|
|
107
|
+
finishedAt?: string;
|
|
108
|
+
totalTestcases?: number;
|
|
109
|
+
successfulTestcases?: number;
|
|
110
|
+
editorScore?: number;
|
|
111
|
+
testOutput?: string;
|
|
112
|
+
lastScoredAt?: string;
|
|
113
|
+
programmingLanguage?: ProgrammingLanguage;
|
|
114
|
+
appealComment?: string;
|
|
115
|
+
createdAt: string;
|
|
116
|
+
updatedAt: string;
|
|
117
|
+
style?: ChallengeStyle;
|
|
118
|
+
weight?: number;
|
|
119
|
+
score?: number;
|
|
120
|
+
}
|
|
121
|
+
export interface CodingContext {
|
|
122
|
+
challengeId: number;
|
|
123
|
+
challengeVersionId: number;
|
|
124
|
+
challengeResultId: number;
|
|
125
|
+
title: string;
|
|
126
|
+
urlForPresign: string;
|
|
127
|
+
urlForOrcaToken?: string;
|
|
128
|
+
methodForPresign: string;
|
|
129
|
+
urlForSave?: string;
|
|
130
|
+
tarballUrl: string;
|
|
131
|
+
tarballUrls: string[];
|
|
132
|
+
allowSave: boolean;
|
|
133
|
+
allowEdit: boolean;
|
|
134
|
+
programmingLanguages: ProgrammingLanguage[];
|
|
135
|
+
selectedLanguage?: ProgrammingLanguage;
|
|
136
|
+
challengeLanguage: SpokenLanguage;
|
|
137
|
+
settings: ChallengeSettings;
|
|
138
|
+
answers: CodingAnswers;
|
|
139
|
+
}
|
|
140
|
+
export declare const FileListType: {
|
|
141
|
+
readonly All: 0;
|
|
142
|
+
readonly ReadOnlyChallengeFiles: 1;
|
|
143
|
+
readonly EditableChallengeFiles: 2;
|
|
144
|
+
readonly UserAddedFiles: 3;
|
|
145
|
+
readonly Editable: 4;
|
|
146
|
+
};
|
|
147
|
+
export type FileListType = (typeof FileListType)[keyof typeof FileListType];
|
|
148
|
+
export interface ChallengeSettings {
|
|
149
|
+
files: FileTree;
|
|
150
|
+
hiddenFiles: string[];
|
|
151
|
+
testExcludes: string[];
|
|
152
|
+
images: string[];
|
|
153
|
+
build: string[];
|
|
154
|
+
test: string;
|
|
155
|
+
mainFile?: string;
|
|
156
|
+
allowNewFile: boolean;
|
|
157
|
+
languages: string[];
|
|
158
|
+
sample?: string;
|
|
159
|
+
envConfig?: EnvSettings;
|
|
160
|
+
initialize: string[];
|
|
161
|
+
}
|
|
162
|
+
export type FileTree = {
|
|
163
|
+
[key: string]: FileTree | boolean;
|
|
164
|
+
};
|
|
165
|
+
export interface EnvSettings {
|
|
166
|
+
imageName: string;
|
|
167
|
+
workingDir?: string;
|
|
168
|
+
baseDir?: string;
|
|
169
|
+
username?: string;
|
|
170
|
+
variables?: Record<string, string>;
|
|
171
|
+
cacheDirs: string[];
|
|
172
|
+
}
|
|
173
|
+
export declare const EnvSettings: {
|
|
174
|
+
default: EnvSettings;
|
|
175
|
+
};
|
|
176
|
+
export interface TestCases {
|
|
177
|
+
open: number;
|
|
178
|
+
secret: number;
|
|
179
|
+
}
|
|
180
|
+
export interface CodingAnswers {
|
|
181
|
+
build?: string[];
|
|
182
|
+
appCommand?: string;
|
|
183
|
+
mainFile?: string;
|
|
184
|
+
addedFiles?: string[];
|
|
185
|
+
fileVersions: object;
|
|
186
|
+
envConfig?: EnvSettings;
|
|
187
|
+
}
|
|
188
|
+
export interface SaveFilesRequest {
|
|
189
|
+
versionId: number;
|
|
190
|
+
addedFiles: string[];
|
|
191
|
+
updatedFiles: Record<string, string>;
|
|
192
|
+
}
|
|
193
|
+
export interface ProgrammingLanguageInfo {
|
|
194
|
+
value: ProgrammingLanguage;
|
|
195
|
+
displayOrder: number;
|
|
196
|
+
messageKey: string;
|
|
197
|
+
displayString: string;
|
|
198
|
+
}
|
|
199
|
+
export interface ApplicationExamForNoAuth {
|
|
200
|
+
id: number;
|
|
201
|
+
applicantId: number;
|
|
202
|
+
examId: number;
|
|
203
|
+
organizationId: number;
|
|
204
|
+
organizationImageUrl?: string;
|
|
205
|
+
organizationName: string;
|
|
206
|
+
examName: string;
|
|
207
|
+
urlToken: string;
|
|
208
|
+
status: ApplicantExamStatus;
|
|
209
|
+
openedAt?: string;
|
|
210
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const ApplicantExamStatus = {
|
|
2
|
+
Unread: 1,
|
|
3
|
+
InProgress: 2,
|
|
4
|
+
Submitted: 3,
|
|
5
|
+
Expired: 4,
|
|
6
|
+
Canceled: 5,
|
|
7
|
+
Reviewed: 6,
|
|
8
|
+
};
|
|
9
|
+
export const ChallengeStyle = {
|
|
10
|
+
Quiz: 1,
|
|
11
|
+
Development: 2,
|
|
12
|
+
Algorithm: 3,
|
|
13
|
+
Ai: 4,
|
|
14
|
+
};
|
|
15
|
+
export const ChallengeResultStatus = {
|
|
16
|
+
Prepared: 0,
|
|
17
|
+
Started: 1,
|
|
18
|
+
InProgress: 2,
|
|
19
|
+
Finished: 3,
|
|
20
|
+
NotModified: 4,
|
|
21
|
+
CanRestart: 5,
|
|
22
|
+
ScoringWaiting: 6,
|
|
23
|
+
};
|
|
24
|
+
export const SpokenLanguage = {
|
|
25
|
+
English: "en",
|
|
26
|
+
Japanese: "ja",
|
|
27
|
+
};
|
|
28
|
+
export const FileListType = {
|
|
29
|
+
All: 0,
|
|
30
|
+
ReadOnlyChallengeFiles: 1,
|
|
31
|
+
EditableChallengeFiles: 2,
|
|
32
|
+
UserAddedFiles: 3,
|
|
33
|
+
Editable: 4,
|
|
34
|
+
};
|
|
35
|
+
export const EnvSettings = {
|
|
36
|
+
default: {
|
|
37
|
+
imageName: "givery/codecheck:latest",
|
|
38
|
+
cacheDirs: [],
|
|
39
|
+
},
|
|
40
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bin": {
|
|
3
|
+
"track": "./esm/src/main.js"
|
|
4
|
+
},
|
|
5
|
+
"name": "track-cli",
|
|
6
|
+
"version": "3.0.0-rc",
|
|
7
|
+
"description": "A CLI for interacting with tracks.run and running code tests on track's servers",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/givery-technology/track-cli.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/givery-technology/track-cli/issues"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "node test_runner.js"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@hazae41/foras": "*",
|
|
21
|
+
"eventemitter3": "5.0.1",
|
|
22
|
+
"node-fetch-cookies": "2.0.4",
|
|
23
|
+
"proxy-agent": "5.0.0",
|
|
24
|
+
"tar": "*",
|
|
25
|
+
"ws": "7.4.6",
|
|
26
|
+
"@deno/shim-deno": "~0.16.1",
|
|
27
|
+
"@deno/shim-crypto": "~0.3.1",
|
|
28
|
+
"@deno/shim-prompts": "~0.1.0",
|
|
29
|
+
"undici": "^5.21.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^18.11.9",
|
|
33
|
+
"picocolors": "^1.0.0"
|
|
34
|
+
}
|
|
35
|
+
}
|