arcadible 1.0.23 → 1.0.25
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/README.md +1 -0
- package/bin/arc.js +1 -85
- package/dist/account.js +197 -0
- package/dist/action/build/tool.js +61 -0
- package/dist/action/delete/tool.js +47 -0
- package/dist/action/deploy/rebuilt.js +25 -0
- package/dist/action/deploy/result.js +36 -0
- package/dist/action/deploy/timeout.js +18 -0
- package/dist/action/deploy/tool-git.js +49 -0
- package/dist/action/deploy/tool.js +49 -0
- package/dist/action/deploy/wait.js +104 -0
- package/dist/action/function/tool.js +127 -0
- package/dist/action/game.js +62 -0
- package/dist/action/init/manifest.js +64 -0
- package/dist/action/init/tool-patch.js +15 -0
- package/dist/action/init/tool.js +64 -0
- package/dist/action/inspect/tool.js +13 -0
- package/dist/action/key/tool.js +88 -0
- package/dist/action/login/flow.js +69 -0
- package/dist/action/login/tool.js +8 -0
- package/dist/action/logout/tool.js +8 -0
- package/dist/action/open/tool.js +30 -0
- package/dist/action/pack/limits.js +46 -0
- package/dist/action/pack/tool.js +148 -0
- package/dist/action/pack/unsound.js +51 -0
- package/dist/action/play/tool.js +84 -0
- package/dist/action/predeploy/ac.js +75 -0
- package/dist/action/predeploy/game.js +6 -0
- package/dist/action/predeploy/git.js +151 -0
- package/dist/action/predeploy/pm.js +20 -0
- package/dist/action/predeploy/published.js +54 -0
- package/dist/action/predeploy/secrets.js +35 -0
- package/dist/action/predeploy/tool-git.js +103 -0
- package/dist/action/predeploy/tool.js +14 -0
- package/dist/action/secret/tool.js +91 -0
- package/dist/action/serve/tool.js +270 -0
- package/dist/action/validate/checked.js +28 -0
- package/dist/action/validate/tool.js +56 -0
- package/dist/action/validate/unknown.js +58 -0
- package/dist/action/validate/unsound.js +99 -0
- package/dist/action/value/tool.js +216 -0
- package/dist/action/whoami/tool.js +7 -0
- package/dist/api.js +312 -0
- package/dist/arc.js +41 -0
- package/dist/cli/argv.js +61 -0
- package/dist/cli/channel.js +29 -0
- package/dist/cli/command.js +163 -0
- package/dist/cli/confirm.js +39 -0
- package/dist/cli/options.js +62 -0
- package/dist/cli/rc.js +103 -0
- package/dist/cli/yargs.js +40 -0
- package/dist/command/build.js +68 -0
- package/dist/command/delete.js +66 -0
- package/dist/command/deploy.js +308 -0
- package/dist/command/function/index.js +17 -0
- package/dist/command/function/pause.js +18 -0
- package/dist/command/function/resume.js +18 -0
- package/dist/command/function/run.js +41 -0
- package/dist/command/function/secret/index.js +15 -0
- package/dist/command/function/secret/list.js +27 -0
- package/dist/command/function/secret/name.js +8 -0
- package/dist/command/function/secret/remove.js +26 -0
- package/dist/command/function/secret/run.js +52 -0
- package/dist/command/function/secret/set.js +48 -0
- package/dist/command/function/status.js +40 -0
- package/dist/command/init.js +128 -0
- package/dist/command/inspect.js +39 -0
- package/dist/command/login.js +108 -0
- package/dist/command/logout.js +24 -0
- package/dist/command/open.js +49 -0
- package/dist/command/pack.js +90 -0
- package/dist/command/play.js +81 -0
- package/dist/command/serve.js +177 -0
- package/dist/command/server/index.js +17 -0
- package/dist/command/server/key/create.js +36 -0
- package/dist/command/server/key/index.js +15 -0
- package/dist/command/server/key/list.js +34 -0
- package/dist/command/server/key/revoke.js +24 -0
- package/dist/command/server/key/run.js +54 -0
- package/dist/command/validate.js +47 -0
- package/dist/command/value/get.js +21 -0
- package/dist/command/value/index.js +19 -0
- package/dist/command/value/key.js +8 -0
- package/dist/command/value/list.js +41 -0
- package/dist/command/value/remove.js +26 -0
- package/dist/command/value/set.js +62 -0
- package/dist/command/value/usage.js +69 -0
- package/dist/command/whoami.js +55 -0
- package/dist/commands.js +100 -0
- package/dist/config/ai.js +2 -0
- package/dist/config/art.js +13 -0
- package/dist/config/audience.js +2 -0
- package/dist/config/code.js +129 -0
- package/dist/config/file.js +13 -0
- package/dist/config/genre.js +19 -0
- package/{src → dist}/config/html.js +2 -7
- package/dist/config/image.js +5 -0
- package/dist/config/input.js +11 -0
- package/dist/config/json.js +23 -0
- package/dist/config/limit.js +14 -0
- package/dist/config/orientation.js +11 -0
- package/dist/config/package.js +8 -0
- package/dist/config/product.js +14 -0
- package/dist/config/template.js +37 -0
- package/dist/config/uri.js +18 -0
- package/dist/config/url.js +11 -0
- package/dist/config/video.js +5 -0
- package/dist/config/visibility.js +2 -0
- package/dist/config/workflow.js +7 -0
- package/dist/parser/env.js +61 -0
- package/dist/parser/given.js +8 -0
- package/dist/parser/manifest.js +45 -0
- package/dist/parser/media.js +57 -0
- package/dist/parser/project.js +129 -0
- package/dist/parser/readme-file.js +44 -0
- package/dist/parser/readme.js +70 -0
- package/dist/parser/sections.js +92 -0
- package/dist/parser/self.js +16 -0
- package/dist/phrase/account.js +35 -0
- package/dist/phrase/common.js +139 -0
- package/dist/phrase/deploy.js +192 -0
- package/dist/phrase/function.js +139 -0
- package/dist/phrase/game.js +27 -0
- package/dist/phrase/index.js +16 -0
- package/dist/phrase/init.js +53 -0
- package/dist/phrase/internal.js +61 -0
- package/dist/phrase/manifest.js +120 -0
- package/dist/phrase/media.js +90 -0
- package/dist/phrase/pack.js +69 -0
- package/dist/phrase/serve.js +84 -0
- package/dist/phrase/server.js +38 -0
- package/dist/phrase/value.js +55 -0
- package/dist/runner/bundle.js +45 -0
- package/dist/runner/entry.js +57 -0
- package/dist/runner/outbound.js +69 -0
- package/dist/schema/check/game.js +29 -0
- package/dist/schema/check/workflow.js +57 -0
- package/dist/schema/game.js +462 -0
- package/dist/schema/message.js +61 -0
- package/dist/schema/readme.js +27 -0
- package/dist/schema/runner.js +43 -0
- package/dist/schema/server.js +91 -0
- package/dist/schema/workflow.js +99 -0
- package/dist/serve/files.js +39 -0
- package/dist/serve/game.js +172 -0
- package/dist/serve/page.js +689 -0
- package/dist/serve/reload.js +55 -0
- package/dist/serve/remote.js +114 -0
- package/dist/serve/runner.js +303 -0
- package/dist/serve/server.js +169 -0
- package/dist/serve/ticket.js +232 -0
- package/dist/serve/values.js +317 -0
- package/dist/util/bytes.js +16 -0
- package/dist/util/chars.js +19 -0
- package/dist/util/command.js +11 -0
- package/dist/util/delay.js +36 -0
- package/dist/util/doc.js +59 -0
- package/dist/util/error.js +35 -0
- package/dist/util/http.js +13 -0
- package/dist/util/image.js +64 -0
- package/dist/util/links.js +45 -0
- package/dist/util/lockfile.js +17 -0
- package/dist/util/log.js +101 -0
- package/dist/util/md.js +37 -0
- package/dist/util/media.js +27 -0
- package/dist/util/objs.js +46 -0
- package/dist/util/os.js +13 -0
- package/dist/util/output.js +133 -0
- package/dist/util/paths.js +8 -0
- package/dist/util/progress.js +57 -0
- package/dist/util/promise.js +18 -0
- package/dist/util/request.js +103 -0
- package/dist/util/s3.js +67 -0
- package/dist/util/schema.js +151 -0
- package/dist/util/screenshot.js +24 -0
- package/dist/util/shape.js +49 -0
- package/dist/util/shell.js +64 -0
- package/dist/util/size.js +32 -0
- package/dist/util/spinner.js +35 -0
- package/dist/util/strs.js +46 -0
- package/dist/util/table.js +18 -0
- package/dist/util/term.js +21 -0
- package/dist/util/time.js +16 -0
- package/dist/util/toml.js +28 -0
- package/{src → dist}/util/uris.js +8 -14
- package/dist/util/video.js +113 -0
- package/dist/util/zip.js +62 -0
- package/npm-shrinkwrap.json +3256 -0
- package/package.json +41 -39
- package/bin/arc-build.js +0 -139
- package/bin/arc-default.js +0 -65
- package/bin/arc-deploy.js +0 -456
- package/bin/arc-init.js +0 -187
- package/bin/arc-inspect.js +0 -97
- package/bin/arc-login.js +0 -165
- package/bin/arc-logout.js +0 -75
- package/bin/arc-open.js +0 -104
- package/bin/arc-pack.js +0 -146
- package/bin/arc-play.js +0 -140
- package/bin/arc-serve.js +0 -214
- package/bin/arc-validate.js +0 -112
- package/bin/arc-whoami.js +0 -119
- package/src/account.js +0 -249
- package/src/action/build/tool.js +0 -80
- package/src/action/deploy/tool-git.js +0 -90
- package/src/action/deploy/tool.js +0 -88
- package/src/action/deploy/wait.js +0 -151
- package/src/action/init/manifest.js +0 -83
- package/src/action/init/tool-patch.js +0 -32
- package/src/action/init/tool.js +0 -97
- package/src/action/inspect/tool.js +0 -26
- package/src/action/login/flow.js +0 -101
- package/src/action/login/tool.js +0 -16
- package/src/action/logout/tool.js +0 -15
- package/src/action/open/tool.js +0 -38
- package/src/action/pack/limits.js +0 -51
- package/src/action/pack/tool.js +0 -171
- package/src/action/pack/unsound.js +0 -69
- package/src/action/play/tool.js +0 -109
- package/src/action/predeploy/ac.js +0 -112
- package/src/action/predeploy/git.js +0 -223
- package/src/action/predeploy/pm.js +0 -37
- package/src/action/predeploy/published.js +0 -82
- package/src/action/predeploy/tool-git.js +0 -154
- package/src/action/predeploy/tool.js +0 -29
- package/src/action/serve/tool.js +0 -209
- package/src/action/validate/checked.js +0 -37
- package/src/action/validate/tool.js +0 -67
- package/src/action/validate/unknown.js +0 -86
- package/src/action/validate/unsound.js +0 -138
- package/src/action/whoami/tool.js +0 -15
- package/src/api.js +0 -163
- package/src/cli/build.js +0 -15
- package/src/cli/deploy.js +0 -21
- package/src/cli/init.js +0 -17
- package/src/cli/inspect.js +0 -15
- package/src/cli/login.js +0 -15
- package/src/cli/logout.js +0 -15
- package/src/cli/open.js +0 -15
- package/src/cli/pack.js +0 -15
- package/src/cli/play.js +0 -15
- package/src/cli/predeploy.js +0 -21
- package/src/cli/serve.js +0 -15
- package/src/cli/validate.js +0 -15
- package/src/cli/whoami.js +0 -15
- package/src/config/ai.js +0 -5
- package/src/config/art.js +0 -16
- package/src/config/audience.js +0 -5
- package/src/config/code.js +0 -142
- package/src/config/file.js +0 -23
- package/src/config/genre.js +0 -22
- package/src/config/image.js +0 -7
- package/src/config/input.js +0 -14
- package/src/config/limit.js +0 -21
- package/src/config/orientation.js +0 -14
- package/src/config/package.js +0 -5
- package/src/config/product.js +0 -5
- package/src/config/template.js +0 -45
- package/src/config/uri.js +0 -27
- package/src/config/url.js +0 -20
- package/src/config/video.js +0 -7
- package/src/config/visibility.js +0 -5
- package/src/config/workflow.js +0 -18
- package/src/parser/env.js +0 -84
- package/src/parser/given.js +0 -17
- package/src/parser/manifest.js +0 -80
- package/src/parser/media.js +0 -90
- package/src/parser/project.js +0 -166
- package/src/parser/readme-file.js +0 -76
- package/src/parser/readme.js +0 -96
- package/src/parser/sections.js +0 -107
- package/src/parser/self.js +0 -27
- package/src/phrase.js +0 -1294
- package/src/schema/check/game.js +0 -61
- package/src/schema/check/workflow.js +0 -99
- package/src/schema/game.js +0 -649
- package/src/schema/message.js +0 -85
- package/src/schema/readme.js +0 -44
- package/src/schema/workflow.js +0 -150
- package/src/serve/files.js +0 -61
- package/src/serve/game.js +0 -191
- package/src/serve/page.js +0 -345
- package/src/serve/reload.js +0 -68
- package/src/serve/remote.js +0 -121
- package/src/serve/server.js +0 -128
- package/src/util/argv.js +0 -116
- package/src/util/bytes.js +0 -25
- package/src/util/chars.js +0 -30
- package/src/util/command.js +0 -18
- package/src/util/delay.js +0 -52
- package/src/util/doc.js +0 -72
- package/src/util/error.js +0 -50
- package/src/util/http.js +0 -25
- package/src/util/image.js +0 -93
- package/src/util/links.js +0 -78
- package/src/util/lockfile.js +0 -35
- package/src/util/log.js +0 -149
- package/src/util/md.js +0 -61
- package/src/util/media.js +0 -40
- package/src/util/objs.js +0 -45
- package/src/util/os.js +0 -27
- package/src/util/output.js +0 -174
- package/src/util/paths.js +0 -21
- package/src/util/progress.js +0 -85
- package/src/util/promise.js +0 -29
- package/src/util/rc.js +0 -144
- package/src/util/request.js +0 -89
- package/src/util/s3.js +0 -92
- package/src/util/schema.js +0 -189
- package/src/util/screenshot.js +0 -37
- package/src/util/shell.js +0 -84
- package/src/util/size.js +0 -53
- package/src/util/spinner.js +0 -52
- package/src/util/strs.js +0 -73
- package/src/util/term.js +0 -28
- package/src/util/time.js +0 -29
- package/src/util/toml.js +0 -14
- package/src/util/video.js +0 -157
- package/src/util/zip.js +0 -88
- /package/{src/serve → assets}/favicon.ico +0 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { ended } from "../../account.js";
|
|
3
|
+
import { auth, discoverGameReleases, release as apiRelease, } from "../../api.js";
|
|
4
|
+
import { sleep } from "../../util/delay.js";
|
|
5
|
+
import { git } from "../predeploy/git.js";
|
|
6
|
+
import { HttpError } from "../../util/http.js";
|
|
7
|
+
import { studioUrl } from "../../util/links.js";
|
|
8
|
+
import { m, s } from "../../util/time.js";
|
|
9
|
+
// [declare]
|
|
10
|
+
// how often a release is checked.
|
|
11
|
+
const INTERVAL = s(2);
|
|
12
|
+
const FINAL = new Set(["failed", "published"]);
|
|
13
|
+
const SELECT = "id,game,status,reason,message,build,source,version,channel,created_at";
|
|
14
|
+
// a git release is found by version among the newest few; one from before
|
|
15
|
+
// this deploy (a tag deleted and pushed again) is left out, allowing for
|
|
16
|
+
// the machine's clock being off.
|
|
17
|
+
const SKEW = m(10);
|
|
18
|
+
// [function]
|
|
19
|
+
// a failure worth retrying: the network, or the API having a moment.
|
|
20
|
+
function transient(err) {
|
|
21
|
+
return !(err instanceof HttpError) || !err.status || err.status >= 500;
|
|
22
|
+
}
|
|
23
|
+
// [function]
|
|
24
|
+
// the repository's GitHub Actions page, from origin's URL, or null when
|
|
25
|
+
// origin isn't on GitHub.
|
|
26
|
+
function actionsUrl(root) {
|
|
27
|
+
return git(root, ["remote", "get-url", "origin"]).then((stdout) => {
|
|
28
|
+
const match = /github\.com[:/]([^/\s]+)\/([^/\s]+?)(?:\.git)?\s*$/u.exec(stdout);
|
|
29
|
+
return match
|
|
30
|
+
? `https://github.com/${match[1]}/${match[2]}/actions`
|
|
31
|
+
: null;
|
|
32
|
+
}, () => null);
|
|
33
|
+
}
|
|
34
|
+
// [function]
|
|
35
|
+
// a direct deploy's release, by its upload's id.
|
|
36
|
+
function findDirect(id, headers) {
|
|
37
|
+
return () => apiRelease(id, { select: SELECT }, headers);
|
|
38
|
+
}
|
|
39
|
+
// [function]
|
|
40
|
+
// a git deploy's release: GitHub's, for this version, made since the tag was
|
|
41
|
+
// pushed. Null until GitHub Actions has built it. Looked for among the
|
|
42
|
+
// game's releases, which anyone can read, with no token: a git deploy asks
|
|
43
|
+
// what's true for whoever runs it. A release with no game (a repository that
|
|
44
|
+
// isn't connected, which the predeploy refuses first) isn't among them.
|
|
45
|
+
function findGit({ game, since, version, }) {
|
|
46
|
+
return () => discoverGameReleases(game, { limit: 10, select: SELECT, version }).then((rows) => (rows ?? []).find((r) => r.source === "github" &&
|
|
47
|
+
r.version === version &&
|
|
48
|
+
r.game === game &&
|
|
49
|
+
Date.parse(r.created_at ?? "") >= since - SKEW) ?? null);
|
|
50
|
+
}
|
|
51
|
+
// [function]
|
|
52
|
+
// checks the release until it's published or failed, or `timeout` seconds
|
|
53
|
+
// pass. Resolves { release, timedOut }; `release` is null when it was never
|
|
54
|
+
// found. `onRelease` hears each release it finds.
|
|
55
|
+
function pollRelease(find, timeout, onRelease) {
|
|
56
|
+
const deadline = Date.now() + timeout * 1000;
|
|
57
|
+
// one check, then the next, each after the last: `last` is the newest
|
|
58
|
+
// release found, kept through a check that fails for a moment.
|
|
59
|
+
const tick = async function (last) {
|
|
60
|
+
let release = last;
|
|
61
|
+
try {
|
|
62
|
+
release = (await find()) ?? last;
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
if (!transient(err)) {
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (release && onRelease) {
|
|
70
|
+
onRelease(release);
|
|
71
|
+
}
|
|
72
|
+
if (release && FINAL.has(release.status)) {
|
|
73
|
+
return { release, timedOut: false };
|
|
74
|
+
}
|
|
75
|
+
const left = deadline - Date.now();
|
|
76
|
+
if (left <= 0) {
|
|
77
|
+
return { release, timedOut: true };
|
|
78
|
+
}
|
|
79
|
+
await sleep(Math.min(INTERVAL, left));
|
|
80
|
+
return tick(release);
|
|
81
|
+
};
|
|
82
|
+
return tick(null);
|
|
83
|
+
}
|
|
84
|
+
// [function]
|
|
85
|
+
// waits on a deploy's release. `deployed` is what the deploy resolved: a
|
|
86
|
+
// direct deploy's has the release's id, and a git deploy's its game. A git
|
|
87
|
+
// deploy has no `current`: it never uses a login. Studio's link is for
|
|
88
|
+
// everyone, since Studio asks whoever opens it to log in.
|
|
89
|
+
export function wait(current, deployed, { git: isGit, root, since, timeout }, { onRelease } = {}) {
|
|
90
|
+
const game = deployed.game;
|
|
91
|
+
const find = isGit || !("release" in deployed)
|
|
92
|
+
? findGit({ game, since, version: deployed.version.to })
|
|
93
|
+
: findDirect(deployed.release, auth(current?.session.access_token));
|
|
94
|
+
return Promise.all([
|
|
95
|
+
pollRelease(find, timeout, onRelease),
|
|
96
|
+
isGit ? actionsUrl(root) : null,
|
|
97
|
+
])
|
|
98
|
+
.then(([polled, actions]) => ({
|
|
99
|
+
...polled,
|
|
100
|
+
actions,
|
|
101
|
+
studio: studioUrl(game, "builds"),
|
|
102
|
+
}))
|
|
103
|
+
.catch(ended(current));
|
|
104
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// a game's function, paused and resumed: stopped on a channel, every
|
|
2
|
+
// build's, without a release, by the game's owner. Arcadible can pause one
|
|
3
|
+
// too, and so can its allowance, spent: a pause has a reason, and an owner
|
|
4
|
+
// lifts only their own.
|
|
5
|
+
import { deleteGameFunctionPause, discoverGameBuilds, gameFunctionPauses, gameFunctionUsages, putGameFunctionPause, } from "../../api.js";
|
|
6
|
+
import { API_REFUSED, GAME_UNAVAILABLE } from "../../config/code.js";
|
|
7
|
+
import { ArcError } from "../../util/error.js";
|
|
8
|
+
import { channelOf, CHANNELS, gameOf, headersOf, isStatus, needOf, } from "../game.js";
|
|
9
|
+
import { functionNotPaused, gameUnavailable } from "../../phrase/index.js";
|
|
10
|
+
// [declare]
|
|
11
|
+
// the reasons a function is paused for, the one that holds longest first:
|
|
12
|
+
// what a status says when there's more than one.
|
|
13
|
+
const REASONS = ["arcadible", "limit", "owner"];
|
|
14
|
+
// [function]
|
|
15
|
+
// why a channel's function is paused, of the game's pauses: the reason that
|
|
16
|
+
// holds longest, or null for one that's running.
|
|
17
|
+
function pausedOf(pauses, channel) {
|
|
18
|
+
const reasons = (pauses ?? [])
|
|
19
|
+
.filter((pause) => pause.channel === channel)
|
|
20
|
+
.map((pause) => pause.reason);
|
|
21
|
+
return REASONS.find((reason) => reasons.includes(reason)) ?? null;
|
|
22
|
+
}
|
|
23
|
+
// [function]
|
|
24
|
+
// whether a channel's live build has a function: true, false, or null when
|
|
25
|
+
// that can't be read, which never stands in a pause's way.
|
|
26
|
+
async function hasFunction(id, channel) {
|
|
27
|
+
try {
|
|
28
|
+
const builds = await discoverGameBuilds(id, {
|
|
29
|
+
channel,
|
|
30
|
+
limit: 1,
|
|
31
|
+
select: "manifest,version",
|
|
32
|
+
});
|
|
33
|
+
const [live] = builds ?? [];
|
|
34
|
+
return live ? Boolean(live.manifest?.function) : false;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// [function]
|
|
41
|
+
// pauses the game's function on a channel, as `{ channel, function, paused
|
|
42
|
+
// }`. One that's paused already stays as it was. A channel whose live build
|
|
43
|
+
// has no function is paused all the same, since a stop is never refused,
|
|
44
|
+
// and `function` says so (false), so the answer doesn't read as if
|
|
45
|
+
// something was stopped.
|
|
46
|
+
export async function pause(current, { channel, ...conf }) {
|
|
47
|
+
const where = needOf(channel);
|
|
48
|
+
const id = await gameOf(conf);
|
|
49
|
+
const headers = headersOf(current);
|
|
50
|
+
try {
|
|
51
|
+
const kept = await putGameFunctionPause(id, where, null, headers);
|
|
52
|
+
return {
|
|
53
|
+
channel: kept.channel,
|
|
54
|
+
function: await hasFunction(id, where),
|
|
55
|
+
paused: kept.reason,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
if (isStatus(err, 404)) {
|
|
60
|
+
throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
|
|
61
|
+
cause: err,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// [function]
|
|
68
|
+
// resumes the game's function on a channel: lifts its owner's pause, and
|
|
69
|
+
// resolves with `{ channel, paused }`, `paused` the reason it's still paused
|
|
70
|
+
// for, or null. With no pause of the owner's to lift, it says why: one that
|
|
71
|
+
// is Arcadible's or its allowance's isn't theirs to lift.
|
|
72
|
+
export async function resume(current, { channel, ...conf }) {
|
|
73
|
+
const where = needOf(channel);
|
|
74
|
+
const id = await gameOf(conf);
|
|
75
|
+
const headers = headersOf(current);
|
|
76
|
+
let lifted = true;
|
|
77
|
+
try {
|
|
78
|
+
await deleteGameFunctionPause(id, where, null, headers);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (!isStatus(err, 404)) {
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
lifted = false;
|
|
85
|
+
}
|
|
86
|
+
const paused = pausedOf(await gameFunctionPauses(id, null, headers), where);
|
|
87
|
+
if (!lifted) {
|
|
88
|
+
throw new ArcError(API_REFUSED, functionNotPaused({ channel: where, paused }));
|
|
89
|
+
}
|
|
90
|
+
return { channel: where, paused };
|
|
91
|
+
}
|
|
92
|
+
// [function]
|
|
93
|
+
// the game's function on each channel, or on one: `{ channel, function,
|
|
94
|
+
// paused, requests }`, `function` whether the channel's live build has one
|
|
95
|
+
// (a pause and a usage are the channel's, so neither says), `paused` the
|
|
96
|
+
// reason it's paused for, or null for none, and `requests` what it answered
|
|
97
|
+
// this month. With them, the game's month: `{ allowance, requests }`, its
|
|
98
|
+
// channels together, whichever were asked for, since the allowance is the
|
|
99
|
+
// game's.
|
|
100
|
+
export async function status(current, { channel, ...conf }) {
|
|
101
|
+
const where = channelOf(channel);
|
|
102
|
+
const id = await gameOf(conf);
|
|
103
|
+
const headers = headersOf(current);
|
|
104
|
+
const [pauses, usages] = await Promise.all([
|
|
105
|
+
gameFunctionPauses(id, null, headers),
|
|
106
|
+
gameFunctionUsages(id, null, headers),
|
|
107
|
+
]);
|
|
108
|
+
const shown = CHANNELS.filter((each) => !where || each === where);
|
|
109
|
+
// asked once the owner's reads have answered, so another account's game
|
|
110
|
+
// is refused before anything else is asked about it.
|
|
111
|
+
const has = await Promise.all(shown.map((each) => hasFunction(id, each)));
|
|
112
|
+
const rows = usages ?? [];
|
|
113
|
+
const [first] = rows;
|
|
114
|
+
const sum = (of) => of.reduce((total, each) => total + Number(each.requests ?? 0), 0);
|
|
115
|
+
return {
|
|
116
|
+
channels: shown.map((each, i) => ({
|
|
117
|
+
channel: each,
|
|
118
|
+
function: has[i] ?? null,
|
|
119
|
+
paused: pausedOf(pauses, each),
|
|
120
|
+
requests: sum(rows.filter((row) => row.channel === each)),
|
|
121
|
+
})),
|
|
122
|
+
month: {
|
|
123
|
+
allowance: first ? Number(first.allowance) : null,
|
|
124
|
+
requests: sum(rows),
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// what the actions on a game's own things share (its function, its
|
|
2
|
+
// function's secrets, its server's keys): the project's game, the channel a
|
|
3
|
+
// command names, the session's headers, and telling the API's refusals
|
|
4
|
+
// apart.
|
|
5
|
+
import { auth } from "../api.js";
|
|
6
|
+
import { ARGUMENT_INVALID, GAME_ID_MISSING, NOT_LOGGED_IN, } from "../config/code.js";
|
|
7
|
+
import { ArcError } from "../util/error.js";
|
|
8
|
+
import { given } from "../parser/given.js";
|
|
9
|
+
import { HttpError } from "../util/http.js";
|
|
10
|
+
import { channelInvalid, gameIdMissing, notLoggedIn } from "../phrase/index.js";
|
|
11
|
+
import { textOf } from "../util/objs.js";
|
|
12
|
+
// [declare]
|
|
13
|
+
export const CHANNELS = ["production", "staging"];
|
|
14
|
+
// [function]
|
|
15
|
+
// the project's game's id, which it must have: a function, a secret, and a
|
|
16
|
+
// key are each a game's. Every action reads it before the session
|
|
17
|
+
// (`headersOf`), as `arc deploy` reads the project before it checks the
|
|
18
|
+
// login, so the same mistake has the same name whichever command makes it.
|
|
19
|
+
export function gameOf(conf) {
|
|
20
|
+
return given(conf).then(({ game }) => {
|
|
21
|
+
if (!game.id) {
|
|
22
|
+
throw new ArcError(GAME_ID_MISSING, gameIdMissing());
|
|
23
|
+
}
|
|
24
|
+
return textOf(game.id);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// [function]
|
|
28
|
+
// the channel a command names, or null for none; anything else is refused
|
|
29
|
+
// before the API is asked. A command that changes something needs one
|
|
30
|
+
// (`needOf`): the CLI asks for it by its flags (src/cli/channel.ts).
|
|
31
|
+
export function channelOf(channel) {
|
|
32
|
+
if ((channel ?? null) === null) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const where = CHANNELS.find((each) => each === channel);
|
|
36
|
+
if (!where) {
|
|
37
|
+
throw new ArcError(ARGUMENT_INVALID, channelInvalid());
|
|
38
|
+
}
|
|
39
|
+
return where;
|
|
40
|
+
}
|
|
41
|
+
// [function]
|
|
42
|
+
export function needOf(channel) {
|
|
43
|
+
const where = channelOf(channel);
|
|
44
|
+
if (!where) {
|
|
45
|
+
throw new ArcError(ARGUMENT_INVALID, channelInvalid());
|
|
46
|
+
}
|
|
47
|
+
return where;
|
|
48
|
+
}
|
|
49
|
+
// [function]
|
|
50
|
+
// the session's headers, or a failure when there's none: only a game's owner
|
|
51
|
+
// pauses its function, and has its secrets and its keys.
|
|
52
|
+
export function headersOf(current) {
|
|
53
|
+
if (!current) {
|
|
54
|
+
throw new ArcError(NOT_LOGGED_IN, notLoggedIn());
|
|
55
|
+
}
|
|
56
|
+
return auth(current.session.access_token);
|
|
57
|
+
}
|
|
58
|
+
// [function]
|
|
59
|
+
// whether a failure is the API's refusal with this status.
|
|
60
|
+
export function isStatus(err, status) {
|
|
61
|
+
return err instanceof HttpError && err.status === status;
|
|
62
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { writeFile } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
// [import]
|
|
6
|
+
import { PARSE_FAILED } from "../../config/code.js";
|
|
7
|
+
import { env } from "../../parser/env.js";
|
|
8
|
+
import { ArcError } from "../../util/error.js";
|
|
9
|
+
import { MANIFEST } from "../../config/file.js";
|
|
10
|
+
import { unableToParse } from "../../phrase/index.js";
|
|
11
|
+
import { read } from "../../parser/manifest.js";
|
|
12
|
+
import { isTable } from "../../util/objs.js";
|
|
13
|
+
import { stringify } from "../../util/toml.js";
|
|
14
|
+
// [function]
|
|
15
|
+
// the version the project's package.json gives, if any.
|
|
16
|
+
export function detectVersion(dest) {
|
|
17
|
+
return env(dest).then(({ game }) => game?.["version"] ?? null);
|
|
18
|
+
}
|
|
19
|
+
// [function]
|
|
20
|
+
function pickVersion(version, envVersion) {
|
|
21
|
+
if (version) {
|
|
22
|
+
return { version };
|
|
23
|
+
}
|
|
24
|
+
return envVersion ? {} : { version: "0.1.0-beta.1" };
|
|
25
|
+
}
|
|
26
|
+
// [function]
|
|
27
|
+
// a new project always gets its own id: a template's, such as an existing
|
|
28
|
+
// game's, belongs to that game.
|
|
29
|
+
function patchGame(envVersion, game = {}, { fresh = false } = {}) {
|
|
30
|
+
// `game` is the manifest's, as written: a table, or it's refused, and the
|
|
31
|
+
// file left as it is. Text read as the fields it has is a key a letter
|
|
32
|
+
// (`game = "abc"` written back as `0`, `1`, `2`).
|
|
33
|
+
if (!isTable(game)) {
|
|
34
|
+
throw new ArcError(PARSE_FAILED, unableToParse(MANIFEST, "`game` must be a table."));
|
|
35
|
+
}
|
|
36
|
+
const { id, version, ...rest } = game;
|
|
37
|
+
return {
|
|
38
|
+
id: fresh ? randomUUID() : (id ?? randomUUID()),
|
|
39
|
+
...pickVersion(version, envVersion),
|
|
40
|
+
...rest,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// [function]
|
|
44
|
+
// a field of the manifest's game, when it's a table.
|
|
45
|
+
function field(game, name) {
|
|
46
|
+
return isTable(game) ? game[name] : undefined;
|
|
47
|
+
}
|
|
48
|
+
// [function]
|
|
49
|
+
function shouldWrite(written, next) {
|
|
50
|
+
return (field(written["game"], "id") !== field(next["game"], "id") ||
|
|
51
|
+
field(written["game"], "version") !== field(next["game"], "version"));
|
|
52
|
+
}
|
|
53
|
+
// [function]
|
|
54
|
+
export function prepare(dest, envVersion, opts) {
|
|
55
|
+
const file = join(dest, MANIFEST);
|
|
56
|
+
return read(dest).then((written) => {
|
|
57
|
+
const { game, ...rest } = written;
|
|
58
|
+
const next = { game: patchGame(envVersion, game, opts), ...rest };
|
|
59
|
+
if (shouldWrite(written, next)) {
|
|
60
|
+
return writeFile(file, stringify(next), "utf8");
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
// [import]
|
|
4
|
+
import { detectVersion, prepare } from "./manifest.js";
|
|
5
|
+
// [function]
|
|
6
|
+
// an existing project: add a manifest, and copy nothing from the template.
|
|
7
|
+
export function initToolPatch({ project, root }, { onInitBegin }) {
|
|
8
|
+
const dest = resolve(root, project);
|
|
9
|
+
if (onInitBegin) {
|
|
10
|
+
onInitBegin({ dest });
|
|
11
|
+
}
|
|
12
|
+
return detectVersion(dest)
|
|
13
|
+
.then((version) => prepare(dest, version))
|
|
14
|
+
.then(() => ({ path: dest }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { readdir } from "node:fs/promises";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import fs from "fs-extra";
|
|
6
|
+
// [import]
|
|
7
|
+
import { TEMPLATE_UNAVAILABLE } from "../../config/code.js";
|
|
8
|
+
import { ArcError } from "../../util/error.js";
|
|
9
|
+
import { templateUnavailable } from "../../phrase/index.js";
|
|
10
|
+
import { detectVersion, prepare } from "./manifest.js";
|
|
11
|
+
import { choices } from "../../config/template.js";
|
|
12
|
+
// [use]
|
|
13
|
+
const remove = fs.remove;
|
|
14
|
+
// [declare]
|
|
15
|
+
const LICENSE = "LICENSE";
|
|
16
|
+
// [define]
|
|
17
|
+
// degit is required, not imported: it's a
|
|
18
|
+
// CommonJS module, and the tests' sandbox answers `require("degit")` with a
|
|
19
|
+
// fake that copies a local directory (test/support/preload.js), which an
|
|
20
|
+
// import would never reach.
|
|
21
|
+
const degit = createRequire(import.meta.url)("degit");
|
|
22
|
+
// [function]
|
|
23
|
+
function removeLicense(dest) {
|
|
24
|
+
return remove(join(dest, LICENSE));
|
|
25
|
+
}
|
|
26
|
+
// [function]
|
|
27
|
+
// a starter's name on its own, such as `blank`, suggests the starter.
|
|
28
|
+
function unavailable(src, cause) {
|
|
29
|
+
const starter = choices.find(({ value }) => value.split("/").pop() === src);
|
|
30
|
+
return new ArcError(TEMPLATE_UNAVAILABLE, templateUnavailable(src, starter?.value), { cause });
|
|
31
|
+
}
|
|
32
|
+
// [function]
|
|
33
|
+
// degit copies nothing, without failing, from a folder a repository doesn't
|
|
34
|
+
// have, so an empty project fails as a missing repository does.
|
|
35
|
+
async function ensureCopied(src, dest) {
|
|
36
|
+
const names = await readdir(dest).catch(() => []);
|
|
37
|
+
if (names.length === 0) {
|
|
38
|
+
await remove(dest);
|
|
39
|
+
throw unavailable(src);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// [function]
|
|
43
|
+
function scaffold(src, dest, { onInitBegin }) {
|
|
44
|
+
if (onInitBegin) {
|
|
45
|
+
onInitBegin({ dest, src });
|
|
46
|
+
}
|
|
47
|
+
// degit throws as it's made when it can't parse `src`.
|
|
48
|
+
return Promise.resolve()
|
|
49
|
+
.then(() => degit(src, { cache: false, force: true, verbose: false }).clone(dest))
|
|
50
|
+
.catch((ex) => {
|
|
51
|
+
throw unavailable(src, ex);
|
|
52
|
+
})
|
|
53
|
+
.then(() => ensureCopied(src, dest));
|
|
54
|
+
}
|
|
55
|
+
// [function]
|
|
56
|
+
// a new project: `arc init` runs tool-patch.ts when the directory exists.
|
|
57
|
+
export function initTool({ project, root, template, }, handler) {
|
|
58
|
+
const dest = resolve(root, project);
|
|
59
|
+
return scaffold(template, dest, handler)
|
|
60
|
+
.then(() => removeLicense(dest))
|
|
61
|
+
.then(() => detectVersion(dest))
|
|
62
|
+
.then((version) => prepare(dest, version, { fresh: true }))
|
|
63
|
+
.then(() => ({ path: dest, template }));
|
|
64
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import dotProp from "dot-prop";
|
|
3
|
+
// [import]
|
|
4
|
+
import { project } from "../../parser/project.js";
|
|
5
|
+
// [function]
|
|
6
|
+
function select(proj, key) {
|
|
7
|
+
return key ? dotProp.get(proj, key, null) : proj;
|
|
8
|
+
}
|
|
9
|
+
// [function]
|
|
10
|
+
// the project's resolved manifest, or the value at `selector` in it.
|
|
11
|
+
export function inspectTool({ root, selector, }) {
|
|
12
|
+
return project(root).then((data) => select(data, selector));
|
|
13
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// a game's keys: what its own server proves itself to Arcadible with. A key
|
|
2
|
+
// is for one game and one channel, made by the game's owner, shown once, and
|
|
3
|
+
// revoked at once. Nothing here keeps one.
|
|
4
|
+
import { deleteKey, gameKeys, postGameKey, } from "../../api.js";
|
|
5
|
+
import { API_REFUSED, ARGUMENT_INVALID, GAME_UNAVAILABLE, } from "../../config/code.js";
|
|
6
|
+
import { ArcError } from "../../util/error.js";
|
|
7
|
+
import { channelOf, gameOf, headersOf, isStatus, needOf } from "../game.js";
|
|
8
|
+
import { gameUnavailable, keyLimitReached, keyNameInvalid, keyNotFound, } from "../../phrase/index.js";
|
|
9
|
+
// [declare]
|
|
10
|
+
const NAME_MAX = 64;
|
|
11
|
+
// the name a key gets when none is given.
|
|
12
|
+
const NAME = "Server";
|
|
13
|
+
// [function]
|
|
14
|
+
// a new key, as `{ id, name, channel, key }`: the only time the key is had.
|
|
15
|
+
export async function create(current, { channel, name, ...conf }) {
|
|
16
|
+
const given = name ?? NAME;
|
|
17
|
+
// a name that isn't text (a number in a JSON `.arcrc`) is refused as any
|
|
18
|
+
// other that won't do.
|
|
19
|
+
const named = typeof given === "string" ? given.trim() : "";
|
|
20
|
+
if (named === "" || named.length > NAME_MAX) {
|
|
21
|
+
throw new ArcError(ARGUMENT_INVALID, keyNameInvalid());
|
|
22
|
+
}
|
|
23
|
+
const where = needOf(channel);
|
|
24
|
+
const id = await gameOf(conf);
|
|
25
|
+
const form = new FormData();
|
|
26
|
+
form.append("name", named);
|
|
27
|
+
form.append("channel", where);
|
|
28
|
+
try {
|
|
29
|
+
const made = await postGameKey(id, form, null, headersOf(current));
|
|
30
|
+
return {
|
|
31
|
+
channel: made.channel,
|
|
32
|
+
id: made.id,
|
|
33
|
+
key: made.key,
|
|
34
|
+
name: made.name,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
if (isStatus(err, 404)) {
|
|
39
|
+
throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
|
|
40
|
+
cause: err,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (isStatus(err, 409)) {
|
|
44
|
+
throw new ArcError(API_REFUSED, keyLimitReached(where), {
|
|
45
|
+
cause: err,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// [function]
|
|
52
|
+
// the game's live keys, newest first, of one channel or both: each as
|
|
53
|
+
// `{ id, name, channel, shown, created_at, used_at }`.
|
|
54
|
+
export async function list(current, { channel, ...conf }) {
|
|
55
|
+
const where = channelOf(channel);
|
|
56
|
+
const id = await gameOf(conf);
|
|
57
|
+
const keys = await gameKeys(id, null, headersOf(current));
|
|
58
|
+
return (keys ?? [])
|
|
59
|
+
.filter((key) => !where || key.channel === where)
|
|
60
|
+
.map((key) => ({
|
|
61
|
+
channel: key.channel,
|
|
62
|
+
created_at: key.created_at,
|
|
63
|
+
id: key.id,
|
|
64
|
+
name: key.name,
|
|
65
|
+
shown: key.shown,
|
|
66
|
+
used_at: key.used_at,
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
// [function]
|
|
70
|
+
// revokes the key with this id, and resolves with `{ id }`. One that's gone
|
|
71
|
+
// already, isn't the account's, or isn't an id at all is the same to its
|
|
72
|
+
// owner: not found. A key is addressed by its own id, so the project only
|
|
73
|
+
// has to name a game.
|
|
74
|
+
export async function revoke(current, { id, ...conf }) {
|
|
75
|
+
await gameOf(conf);
|
|
76
|
+
try {
|
|
77
|
+
const gone = await deleteKey(id, null, headersOf(current));
|
|
78
|
+
return { id: gone.id };
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (isStatus(err, 404) || isStatus(err, 400)) {
|
|
82
|
+
throw new ArcError(API_REFUSED, keyNotFound(id), {
|
|
83
|
+
cause: err,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
throw err;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
// [import]
|
|
4
|
+
import { auth, flow as apiFlow, postFlow as apiPostFlow, } from "../../api.js";
|
|
5
|
+
import { LOGIN_CODE_EXPIRED, LOGIN_FAILED } from "../../config/code.js";
|
|
6
|
+
import { poll } from "../../util/delay.js";
|
|
7
|
+
import { ArcError } from "../../util/error.js";
|
|
8
|
+
import { loginCodeExpired, loginFailed } from "../../phrase/index.js";
|
|
9
|
+
import { m, s } from "../../util/time.js";
|
|
10
|
+
import { LINK } from "../../config/url.js";
|
|
11
|
+
// [declare]
|
|
12
|
+
const POLL = {
|
|
13
|
+
delay: s(1.5),
|
|
14
|
+
factor: 1.5,
|
|
15
|
+
interval: s(15),
|
|
16
|
+
maxDelay: s(5),
|
|
17
|
+
timeoutError: () => new ArcError(LOGIN_CODE_EXPIRED, loginCodeExpired()),
|
|
18
|
+
};
|
|
19
|
+
// [function]
|
|
20
|
+
function postFlow({ expiresAt, secret, type }) {
|
|
21
|
+
const form = new FormData();
|
|
22
|
+
form.append("secret", secret);
|
|
23
|
+
form.append("type", type);
|
|
24
|
+
form.append("expires_at", expiresAt.toISOString());
|
|
25
|
+
return apiPostFlow(form);
|
|
26
|
+
}
|
|
27
|
+
// [function]
|
|
28
|
+
function getFlow({ id, secret: token }) {
|
|
29
|
+
return apiFlow(id, null, auth(token));
|
|
30
|
+
}
|
|
31
|
+
// [function]
|
|
32
|
+
function createFlow({ expiresAt, secret, type }, onLoginCreated) {
|
|
33
|
+
return postFlow({ expiresAt, secret, type }).then(({ code, id }) => {
|
|
34
|
+
if (onLoginCreated) {
|
|
35
|
+
onLoginCreated({ code, secret, url: LINK });
|
|
36
|
+
}
|
|
37
|
+
return { id };
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
// [function]
|
|
41
|
+
function pollFlow(value) {
|
|
42
|
+
return getFlow(value).then(({ data, status }) => {
|
|
43
|
+
switch (status) {
|
|
44
|
+
case "pending":
|
|
45
|
+
return null;
|
|
46
|
+
case "completed":
|
|
47
|
+
return data;
|
|
48
|
+
case "failed":
|
|
49
|
+
throw new ArcError(LOGIN_FAILED, loginFailed());
|
|
50
|
+
default:
|
|
51
|
+
throw new ArcError(LOGIN_CODE_EXPIRED, loginCodeExpired());
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// [function]
|
|
56
|
+
// the device flow: makes a login, tells `onLoginCreated` its code and link,
|
|
57
|
+
// and resolves with the account once it's completed at the link.
|
|
58
|
+
export function flow({ onLoginCreated, }) {
|
|
59
|
+
const expiresAt = new Date(Date.now() + m(10));
|
|
60
|
+
const secret = randomUUID();
|
|
61
|
+
return createFlow({
|
|
62
|
+
expiresAt,
|
|
63
|
+
secret,
|
|
64
|
+
type: "cli-login",
|
|
65
|
+
}, onLoginCreated).then(({ id }) => {
|
|
66
|
+
const timeout = Math.max(0, expiresAt.getTime() - Date.now() - s(15));
|
|
67
|
+
return poll(pollFlow, { id, secret }, { ...POLL, timeout });
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { storePage, storeUrl } from "../../util/links.js";
|
|
3
|
+
import { textOf } from "../../util/objs.js";
|
|
4
|
+
import { self } from "../../parser/self.js";
|
|
5
|
+
// [function]
|
|
6
|
+
// the store page's path, which the app opens, and its URL on the web. `id`
|
|
7
|
+
// is a handle or an id as it's written, in the manifest or on the command
|
|
8
|
+
// line.
|
|
9
|
+
function openUrl(id) {
|
|
10
|
+
if (!id) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const game = textOf(id);
|
|
14
|
+
return { page: storePage(game), url: storeUrl(game) };
|
|
15
|
+
}
|
|
16
|
+
// [function]
|
|
17
|
+
function open(id) {
|
|
18
|
+
return Promise.resolve(openUrl(id));
|
|
19
|
+
}
|
|
20
|
+
// [function]
|
|
21
|
+
function openSelf(root) {
|
|
22
|
+
return self(root).then((game) => openUrl(game?.handle ?? game?.id));
|
|
23
|
+
}
|
|
24
|
+
// [function]
|
|
25
|
+
export function openTool({ game: id, root, }) {
|
|
26
|
+
if (id === "self") {
|
|
27
|
+
return openSelf(root);
|
|
28
|
+
}
|
|
29
|
+
return open(id);
|
|
30
|
+
}
|