arcadible 1.0.34 → 1.0.35
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/dist/action/delete/tool.js +2 -2
- package/dist/action/deploy/tool.js +5 -4
- package/dist/action/function/tool.js +10 -9
- package/dist/action/game.js +12 -1
- package/dist/action/key/tool.js +7 -7
- package/dist/action/secret/tool.js +7 -7
- package/dist/action/serve/tool.js +2 -0
- package/dist/action/value/tool.js +9 -7
- package/dist/action/wire/tool.js +2 -2
- package/dist/command/serve.js +5 -0
- package/dist/config/code.js +16 -4
- package/dist/config/limit.js +2 -0
- package/dist/phrase/function.js +13 -4
- package/dist/phrase/game.js +5 -3
- package/dist/phrase/serve.js +6 -0
- package/dist/runner/bundle.js +10 -2
- package/dist/serve/page.js +25 -8
- package/dist/serve/runner.js +34 -14
- package/dist/serve/server.js +8 -4
- package/dist/serve/wires.js +10 -5
- package/dist/util/error.js +10 -7
- package/dist/util/http.js +6 -1
- package/dist/util/request.js +5 -3
- package/dist/wires/room.js +10 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ import { GAME_ID_MISSING, GAME_UNAVAILABLE } from "../../config/code.js";
|
|
|
6
6
|
import { ArcError } from "../../util/error.js";
|
|
7
7
|
import { headersOf, isStatus } from "../game.js";
|
|
8
8
|
import { given } from "../../parser/given.js";
|
|
9
|
-
import { gameIdMissing,
|
|
9
|
+
import { gameIdMissing, gameNotOwned } from "../../phrase/index.js";
|
|
10
10
|
import { textOf } from "../../util/objs.js";
|
|
11
11
|
// [function]
|
|
12
12
|
// a value of the manifest's as a name, when it's text with something in it.
|
|
@@ -38,7 +38,7 @@ export async function deleteTool(current, { id }) {
|
|
|
38
38
|
}
|
|
39
39
|
catch (err) {
|
|
40
40
|
if (isStatus(err, 404)) {
|
|
41
|
-
throw new ArcError(GAME_UNAVAILABLE,
|
|
41
|
+
throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
|
|
42
42
|
cause: err,
|
|
43
43
|
});
|
|
44
44
|
}
|
|
@@ -3,7 +3,7 @@ import { auth, postUpload } from "../../api.js";
|
|
|
3
3
|
import { DEPLOY_RATE_LIMITED, GAME_UNAVAILABLE } from "../../config/code.js";
|
|
4
4
|
import { ArcError } from "../../util/error.js";
|
|
5
5
|
import { releasing } from "../predeploy/game.js";
|
|
6
|
-
import {
|
|
6
|
+
import { isRefused } from "../game.js";
|
|
7
7
|
import { deployRateLimited, gameUnavailable } from "../../phrase/index.js";
|
|
8
8
|
import { published } from "../../util/links.js";
|
|
9
9
|
import { upload as s3Upload } from "../../util/s3.js";
|
|
@@ -18,13 +18,14 @@ function uploadBuild(current, artifact, { id, version }, onProgress) {
|
|
|
18
18
|
form.append("size", String(artifact.size));
|
|
19
19
|
return postUpload(form, null, auth(current?.session.access_token)).then((upload) => s3Upload(upload.upload_url, artifact, onProgress).then(() => upload), (err) => {
|
|
20
20
|
// the API refuses a game that was deleted or is another account's
|
|
21
|
-
// (403), and the same version deployed again within 5 minutes (429)
|
|
22
|
-
|
|
21
|
+
// (403), and the same version deployed again within 5 minutes (429),
|
|
22
|
+
// each by its code.
|
|
23
|
+
if (isRefused(err, GAME_UNAVAILABLE, 403)) {
|
|
23
24
|
throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
|
|
24
25
|
cause: err,
|
|
25
26
|
});
|
|
26
27
|
}
|
|
27
|
-
if (err
|
|
28
|
+
if (isRefused(err, DEPLOY_RATE_LIMITED, 429)) {
|
|
28
29
|
throw new ArcError(DEPLOY_RATE_LIMITED, deployRateLimited(version), {
|
|
29
30
|
cause: err,
|
|
30
31
|
});
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// too, and so can its allowance, spent: a pause has a reason, and an owner
|
|
4
4
|
// lifts only their own.
|
|
5
5
|
import { deleteGameFunctionPause, discoverGameBuilds, gameFunctionPauses, gameFunctionUsages, putGameFunctionPause, } from "../../api.js";
|
|
6
|
-
import {
|
|
6
|
+
import { FUNCTION_PAUSE_RESERVED, GAME_UNAVAILABLE, } from "../../config/code.js";
|
|
7
7
|
import { ArcError } from "../../util/error.js";
|
|
8
8
|
import { channelOf, CHANNELS, gameOf, headersOf, isStatus, needOf, } from "../game.js";
|
|
9
|
-
import {
|
|
9
|
+
import { functionPauseReserved, gameNotOwned } from "../../phrase/index.js";
|
|
10
10
|
// [declare]
|
|
11
11
|
// the reasons a function is paused for, the one that holds longest first:
|
|
12
12
|
// what a status says when there's more than one.
|
|
@@ -57,7 +57,7 @@ export async function pause(current, { channel, ...conf }) {
|
|
|
57
57
|
}
|
|
58
58
|
catch (err) {
|
|
59
59
|
if (isStatus(err, 404)) {
|
|
60
|
-
throw new ArcError(GAME_UNAVAILABLE,
|
|
60
|
+
throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
|
|
61
61
|
cause: err,
|
|
62
62
|
});
|
|
63
63
|
}
|
|
@@ -66,9 +66,10 @@ export async function pause(current, { channel, ...conf }) {
|
|
|
66
66
|
}
|
|
67
67
|
// [function]
|
|
68
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
|
|
70
|
-
// for, or null.
|
|
71
|
-
//
|
|
69
|
+
// resolves with `{ channel, lifted, paused }`, `paused` the reason it's
|
|
70
|
+
// still paused for, or null. One that isn't paused stays as it was, as `pause` leaves one
|
|
71
|
+
// that's paused already. A pause of Arcadible's, or its allowance's, isn't
|
|
72
|
+
// its owner's to lift: function_pause_reserved, saying who lifts it.
|
|
72
73
|
export async function resume(current, { channel, ...conf }) {
|
|
73
74
|
const where = needOf(channel);
|
|
74
75
|
const id = await gameOf(conf);
|
|
@@ -84,10 +85,10 @@ export async function resume(current, { channel, ...conf }) {
|
|
|
84
85
|
lifted = false;
|
|
85
86
|
}
|
|
86
87
|
const paused = pausedOf(await gameFunctionPauses(id, null, headers), where);
|
|
87
|
-
if (!lifted) {
|
|
88
|
-
throw new ArcError(
|
|
88
|
+
if (!lifted && paused) {
|
|
89
|
+
throw new ArcError(FUNCTION_PAUSE_RESERVED, functionPauseReserved({ channel: where, paused }));
|
|
89
90
|
}
|
|
90
|
-
return { channel: where, paused };
|
|
91
|
+
return { channel: where, lifted, paused };
|
|
91
92
|
}
|
|
92
93
|
// [function]
|
|
93
94
|
// the game's function on each channel, or on one: `{ channel, function,
|
package/dist/action/game.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// command names, the session's headers, and telling the API's refusals
|
|
4
4
|
// apart.
|
|
5
5
|
import { auth } from "../api.js";
|
|
6
|
-
import { ARGUMENT_INVALID, GAME_ID_MISSING, NOT_LOGGED_IN, } from "../config/code.js";
|
|
6
|
+
import { ALL, ARGUMENT_INVALID, GAME_ID_MISSING, NOT_LOGGED_IN, } from "../config/code.js";
|
|
7
7
|
import { ArcError } from "../util/error.js";
|
|
8
8
|
import { given } from "../parser/given.js";
|
|
9
9
|
import { HttpError } from "../util/http.js";
|
|
@@ -60,3 +60,14 @@ export function headersOf(current) {
|
|
|
60
60
|
export function isStatus(err, status) {
|
|
61
61
|
return err instanceof HttpError && err.status === status;
|
|
62
62
|
}
|
|
63
|
+
// [function]
|
|
64
|
+
// whether a failure is the API's refusal with this code, which the
|
|
65
|
+
// database names (ERRORS.md): read first, and, from an API that doesn't say
|
|
66
|
+
// one, its status.
|
|
67
|
+
export function isRefused(err, code, status) {
|
|
68
|
+
if (!(err instanceof HttpError))
|
|
69
|
+
return false;
|
|
70
|
+
if (err.code === code)
|
|
71
|
+
return true;
|
|
72
|
+
return (err.status === status && (err.code === undefined || !ALL.has(err.code)));
|
|
73
|
+
}
|
package/dist/action/key/tool.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// is for one game and one channel, made by the game's owner, shown once, and
|
|
3
3
|
// revoked at once. Nothing here keeps one.
|
|
4
4
|
import { deleteKey, gameKeys, postGameKey, } from "../../api.js";
|
|
5
|
-
import {
|
|
5
|
+
import { ARGUMENT_INVALID, GAME_UNAVAILABLE, KEY_LIMIT_REACHED, KEY_NOT_FOUND, } from "../../config/code.js";
|
|
6
6
|
import { ArcError } from "../../util/error.js";
|
|
7
|
-
import { channelOf, gameOf, headersOf, isStatus, needOf } from "../game.js";
|
|
8
|
-
import {
|
|
7
|
+
import { channelOf, gameOf, headersOf, isRefused, isStatus, needOf, } from "../game.js";
|
|
8
|
+
import { gameNotOwned, keyLimitReached, keyNameInvalid, keyNotFound, } from "../../phrase/index.js";
|
|
9
9
|
// [declare]
|
|
10
10
|
const NAME_MAX = 64;
|
|
11
11
|
// the name a key gets when none is given.
|
|
@@ -36,12 +36,12 @@ export async function create(current, { channel, name, ...conf }) {
|
|
|
36
36
|
}
|
|
37
37
|
catch (err) {
|
|
38
38
|
if (isStatus(err, 404)) {
|
|
39
|
-
throw new ArcError(GAME_UNAVAILABLE,
|
|
39
|
+
throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
|
|
40
40
|
cause: err,
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
if (
|
|
44
|
-
throw new ArcError(
|
|
43
|
+
if (isRefused(err, KEY_LIMIT_REACHED, 409)) {
|
|
44
|
+
throw new ArcError(KEY_LIMIT_REACHED, keyLimitReached(where), {
|
|
45
45
|
cause: err,
|
|
46
46
|
});
|
|
47
47
|
}
|
|
@@ -79,7 +79,7 @@ export async function revoke(current, { id, ...conf }) {
|
|
|
79
79
|
}
|
|
80
80
|
catch (err) {
|
|
81
81
|
if (isStatus(err, 404) || isStatus(err, 400)) {
|
|
82
|
-
throw new ArcError(
|
|
82
|
+
throw new ArcError(KEY_NOT_FOUND, keyNotFound(id), {
|
|
83
83
|
cause: err,
|
|
84
84
|
});
|
|
85
85
|
}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// channel, by the name the manifest declares (function.secrets), set by the
|
|
4
4
|
// game's owner, and never shown again. Nothing here keeps one.
|
|
5
5
|
import { deleteGameFunctionSecret, gameFunctionSecrets, putGameFunctionSecret, } from "../../api.js";
|
|
6
|
-
import {
|
|
6
|
+
import { ARGUMENT_INVALID, GAME_UNAVAILABLE, SECRET_LIMIT_REACHED, SECRET_NOT_FOUND, } from "../../config/code.js";
|
|
7
7
|
import { ArcError } from "../../util/error.js";
|
|
8
|
-
import { channelOf, gameOf, headersOf, isStatus, needOf } from "../game.js";
|
|
9
|
-
import {
|
|
8
|
+
import { channelOf, gameOf, headersOf, isRefused, isStatus, needOf, } from "../game.js";
|
|
9
|
+
import { gameNotOwned, secretLimitReached, secretNameInvalid, secretNotFound, secretValueInvalid, } from "../../phrase/index.js";
|
|
10
10
|
// [declare]
|
|
11
11
|
// a secret's name, as an environment variable is named; ARCADIBLE_ is kept
|
|
12
12
|
// for Arcadible's own.
|
|
@@ -42,12 +42,12 @@ export async function set(current, { channel, name, value, ...conf }) {
|
|
|
42
42
|
}
|
|
43
43
|
catch (err) {
|
|
44
44
|
if (isStatus(err, 404)) {
|
|
45
|
-
throw new ArcError(GAME_UNAVAILABLE,
|
|
45
|
+
throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
|
|
46
46
|
cause: err,
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
if (
|
|
50
|
-
throw new ArcError(
|
|
49
|
+
if (isRefused(err, SECRET_LIMIT_REACHED, 409)) {
|
|
50
|
+
throw new ArcError(SECRET_LIMIT_REACHED, secretLimitReached(where), {
|
|
51
51
|
cause: err,
|
|
52
52
|
});
|
|
53
53
|
}
|
|
@@ -84,7 +84,7 @@ export async function remove(current, { channel, name, ...conf }) {
|
|
|
84
84
|
}
|
|
85
85
|
catch (err) {
|
|
86
86
|
if (isStatus(err, 404)) {
|
|
87
|
-
throw new ArcError(
|
|
87
|
+
throw new ArcError(SECRET_NOT_FOUND, secretNotFound({ channel: where, name: named }), { cause: err });
|
|
88
88
|
}
|
|
89
89
|
throw err;
|
|
90
90
|
}
|
|
@@ -130,6 +130,7 @@ export async function serveTool(conf) {
|
|
|
130
130
|
const { port, root, url } = conf;
|
|
131
131
|
const handler = {
|
|
132
132
|
onBuild() { },
|
|
133
|
+
onLink() { },
|
|
133
134
|
onReload() { },
|
|
134
135
|
onRemote() { },
|
|
135
136
|
onRunnerError() { },
|
|
@@ -167,6 +168,7 @@ export async function serveTool(conf) {
|
|
|
167
168
|
},
|
|
168
169
|
// arc serve's own tickets, signed with a key kept beside the session
|
|
169
170
|
keyFile: join(configDir(), "ticket-key.json"),
|
|
171
|
+
onLink: (url) => handler.onLink(url),
|
|
170
172
|
onRemote: handler.onRemote,
|
|
171
173
|
player,
|
|
172
174
|
port,
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
import fs from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { gameValuesList, gameValuesRead, gameValuesRemove, gameValuesWrite, gameValueCalls, gameValueUsages, } from "../../api.js";
|
|
9
|
-
import {
|
|
9
|
+
import { ARGUMENT_INVALID, GAME_UNAVAILABLE, VALUE_NOT_FOUND, VALUE_STORAGE_FULL, VALUE_TOO_LARGE, } from "../../config/code.js";
|
|
10
10
|
import { ArcError } from "../../util/error.js";
|
|
11
11
|
import { gameOf, headersOf, isStatus, needOf } from "../game.js";
|
|
12
|
-
import {
|
|
12
|
+
import { gameNotOwned, valueDirEmpty, valueFileUnread, valueFull, valueKeyInvalid, valueNotFound, valueNotJson, valueSetWhat, valueTooLarge, } from "../../phrase/index.js";
|
|
13
13
|
// [declare]
|
|
14
14
|
// a key, as Arcadible takes one (db/function/game_value.sql, value_keys).
|
|
15
15
|
export const KEY = /^[A-Za-z0-9_./-]{1,128}$/u;
|
|
@@ -101,12 +101,14 @@ function batches(items) {
|
|
|
101
101
|
function refused(id, channel) {
|
|
102
102
|
return (err) => {
|
|
103
103
|
if (isStatus(err, 404)) {
|
|
104
|
-
throw new ArcError(GAME_UNAVAILABLE,
|
|
104
|
+
throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id), {
|
|
105
105
|
cause: err,
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
if (isStatus(err, 507)) {
|
|
109
|
-
throw new ArcError(
|
|
109
|
+
throw new ArcError(VALUE_STORAGE_FULL, valueFull(channel), {
|
|
110
|
+
cause: err,
|
|
111
|
+
});
|
|
110
112
|
}
|
|
111
113
|
throw err;
|
|
112
114
|
};
|
|
@@ -139,7 +141,7 @@ export async function set(current, { channel, dir, file, input, key, ...conf })
|
|
|
139
141
|
if (isStatus(err, 413)) {
|
|
140
142
|
// a batch is under what a call holds, so it's one value's own size
|
|
141
143
|
const [largest] = [...batch].sort((a, b) => JSON.stringify(b.value).length - JSON.stringify(a.value).length);
|
|
142
|
-
throw new ArcError(
|
|
144
|
+
throw new ArcError(VALUE_TOO_LARGE, valueTooLarge(largest?.key ?? ""), {
|
|
143
145
|
cause: err,
|
|
144
146
|
});
|
|
145
147
|
}
|
|
@@ -158,7 +160,7 @@ export async function get(current, { channel, key, ...conf }) {
|
|
|
158
160
|
const headers = headersOf(current);
|
|
159
161
|
const [value] = await gameValuesRead(id, where, [named], headers).catch(refused(id, where));
|
|
160
162
|
if (!value) {
|
|
161
|
-
throw new ArcError(
|
|
163
|
+
throw new ArcError(VALUE_NOT_FOUND, valueNotFound({ channel: where, key: named }));
|
|
162
164
|
}
|
|
163
165
|
return { channel: where, ...value };
|
|
164
166
|
}
|
|
@@ -193,7 +195,7 @@ export async function remove(current, { channel, key, ...conf }) {
|
|
|
193
195
|
const headers = headersOf(current);
|
|
194
196
|
const { removed } = await gameValuesRemove(id, where, [named], headers).catch(refused(id, where));
|
|
195
197
|
if (removed === 0) {
|
|
196
|
-
throw new ArcError(
|
|
198
|
+
throw new ArcError(VALUE_NOT_FOUND, valueNotFound({ channel: where, key: named }));
|
|
197
199
|
}
|
|
198
200
|
return { channel: where, keys: [named] };
|
|
199
201
|
}
|
package/dist/action/wire/tool.js
CHANGED
|
@@ -5,7 +5,7 @@ import { gameWireUsages } from "../../api.js";
|
|
|
5
5
|
import { GAME_UNAVAILABLE } from "../../config/code.js";
|
|
6
6
|
import { ArcError } from "../../util/error.js";
|
|
7
7
|
import { channelOf, CHANNELS, gameOf, headersOf, } from "../game.js";
|
|
8
|
-
import {
|
|
8
|
+
import { gameNotOwned } from "../../phrase/index.js";
|
|
9
9
|
// [function]
|
|
10
10
|
// what the game's wires carried on each channel, or on one: this month's,
|
|
11
11
|
// and today's of it.
|
|
@@ -16,7 +16,7 @@ export async function usage(current, { channel, ...conf }) {
|
|
|
16
16
|
// its owner always reads today's row for each channel: no rows at all is
|
|
17
17
|
// a game that isn't the caller's
|
|
18
18
|
if (rows.length === 0) {
|
|
19
|
-
throw new ArcError(GAME_UNAVAILABLE,
|
|
19
|
+
throw new ArcError(GAME_UNAVAILABLE, gameNotOwned(id));
|
|
20
20
|
}
|
|
21
21
|
const today = new Date().toISOString().slice(0, 10);
|
|
22
22
|
const sum = (of) => ({
|
package/dist/command/serve.js
CHANGED
package/dist/config/code.js
CHANGED
|
@@ -11,6 +11,7 @@ const CLI = {
|
|
|
11
11
|
BUILD_FAILED: "build_failed",
|
|
12
12
|
DEPLOY_DIR_MISSING: "deploy_dir_missing",
|
|
13
13
|
DEPLOY_RATE_LIMITED: "deploy_rate_limited",
|
|
14
|
+
FUNCTION_PAUSE_RESERVED: "function_pause_reserved",
|
|
14
15
|
GAME_HANDLE_TAKEN: "game_handle_taken",
|
|
15
16
|
GAME_ID_MISSING: "game_id_missing",
|
|
16
17
|
GAME_NOT_DEPLOYED: "game_not_deployed",
|
|
@@ -22,6 +23,8 @@ const CLI = {
|
|
|
22
23
|
GIT_TAG_EXISTS: "git_tag_exists",
|
|
23
24
|
GIT_TAG_PUSH_FAILED: "git_tag_push_failed",
|
|
24
25
|
GIT_UNCOMMITTED: "git_uncommitted",
|
|
26
|
+
KEY_LIMIT_REACHED: "key_limit_reached",
|
|
27
|
+
KEY_NOT_FOUND: "key_not_found",
|
|
25
28
|
LOCKFILE_MISSING: "lockfile_missing",
|
|
26
29
|
LOGIN_CODE_EXPIRED: "login_code_expired",
|
|
27
30
|
LOGIN_FAILED: "login_failed",
|
|
@@ -37,19 +40,28 @@ const CLI = {
|
|
|
37
40
|
PATH_NOT_FOUND: "path_not_found",
|
|
38
41
|
PORT_IN_USE: "port_in_use",
|
|
39
42
|
PROJECT_NOT_REPO_ROOT: "project_not_repo_root",
|
|
43
|
+
SECRET_LIMIT_REACHED: "secret_limit_reached",
|
|
44
|
+
SECRET_NOT_FOUND: "secret_not_found",
|
|
40
45
|
SESSION_EXPIRED: "session_expired",
|
|
41
46
|
TEMPLATE_MISSING: "template_missing",
|
|
42
47
|
TEMPLATE_UNAVAILABLE: "template_unavailable",
|
|
48
|
+
UNEXPECTED: "unexpected",
|
|
43
49
|
UPLOAD_FAILED: "upload_failed",
|
|
44
50
|
VALIDATION_FAILED: "validation_failed",
|
|
51
|
+
VALUE_NOT_FOUND: "value_not_found",
|
|
52
|
+
VALUE_STORAGE_FULL: "value_storage_full",
|
|
53
|
+
VALUE_TOO_LARGE: "value_too_large",
|
|
45
54
|
WAIT_TIMED_OUT: "wait_timed_out",
|
|
46
55
|
};
|
|
47
56
|
// a release's reasons, from the pipeline (the API's
|
|
48
57
|
// db/type/release_reason.sql). The CLI shares them, so a name means the same
|
|
49
|
-
// thing wherever it appears:
|
|
50
|
-
// as well as REPO_NOT_CONNECTED and
|
|
58
|
+
// thing wherever it appears: FUNCTION_TOO_LARGE, GAME_HANDLE_CHANGED,
|
|
59
|
+
// GAME_UNAVAILABLE, INTERNAL, as well as REPO_NOT_CONNECTED and
|
|
60
|
+
// VERSION_EXISTS, are the CLI's too.
|
|
51
61
|
export const RELEASE = {
|
|
52
62
|
BUILD_RATE_LIMITED: "build_rate_limited",
|
|
63
|
+
FUNCTION_INVALID: "function_invalid",
|
|
64
|
+
FUNCTION_TOO_LARGE: "function_too_large",
|
|
53
65
|
GAME_HANDLE_CHANGED: "game_handle_changed",
|
|
54
66
|
GAME_LIMIT_REACHED: "game_limit_reached",
|
|
55
67
|
GAME_MISMATCH: "game_mismatch",
|
|
@@ -124,6 +136,6 @@ export const ISSUES = new Set(Object.values(ISSUE));
|
|
|
124
136
|
export const WARNINGS = new Set(Object.values(WARNING));
|
|
125
137
|
// [declare]
|
|
126
138
|
// each error code by its own name too: `cfgcode.NOT_LOGGED_IN`.
|
|
127
|
-
export const { API_REFUSED, API_UNREACHABLE, ARGUMENT_INVALID, BUILD_FAILED, DEPLOY_DIR_MISSING, DEPLOY_RATE_LIMITED, GAME_HANDLE_TAKEN, GAME_ID_MISSING, GAME_NOT_DEPLOYED, GAME_NOT_FOUND, GIT_REMOTE_MISSING, GIT_REMOTE_UNREACHABLE, GIT_REPO_MISSING, GIT_TAG_CREATE_FAILED, GIT_TAG_EXISTS, GIT_TAG_PUSH_FAILED, GIT_UNCOMMITTED, LOCKFILE_MISSING, LOGIN_CODE_EXPIRED, LOGIN_FAILED, MANIFEST_MISSING, NOT_LOGGED_IN, PACKAGE_FILE_TOO_LARGE, PACKAGE_INDEX_MISSING, PACKAGE_PATH_RESERVED, PACKAGE_TOO_LARGE, PACKAGE_TOO_MANY_FILES, PACKAGE_UNCOMPRESSED_TOO_LARGE, PARSE_FAILED, PATH_NOT_FOUND, PORT_IN_USE, PROJECT_NOT_REPO_ROOT, SESSION_EXPIRED, TEMPLATE_MISSING, TEMPLATE_UNAVAILABLE, UPLOAD_FAILED, VALIDATION_FAILED, WAIT_TIMED_OUT, } = CLI;
|
|
128
|
-
export const { BUILD_RATE_LIMITED, GAME_HANDLE_CHANGED, GAME_LIMIT_REACHED, GAME_MISMATCH, GAME_UNAVAILABLE, GITHUB_APP_NOT_INSTALLED, INTERNAL, MANIFEST_INVALID, RELEASE_EXPIRED, REPO_NOT_CONNECTED, VERSION_EXISTS, VERSION_MISMATCH, ZIP_INVALID, ZIP_MISSING, ZIP_TOO_LARGE, } = RELEASE;
|
|
139
|
+
export const { API_REFUSED, API_UNREACHABLE, ARGUMENT_INVALID, BUILD_FAILED, DEPLOY_DIR_MISSING, DEPLOY_RATE_LIMITED, FUNCTION_PAUSE_RESERVED, GAME_HANDLE_TAKEN, GAME_ID_MISSING, GAME_NOT_DEPLOYED, GAME_NOT_FOUND, GIT_REMOTE_MISSING, GIT_REMOTE_UNREACHABLE, GIT_REPO_MISSING, GIT_TAG_CREATE_FAILED, GIT_TAG_EXISTS, GIT_TAG_PUSH_FAILED, GIT_UNCOMMITTED, KEY_LIMIT_REACHED, KEY_NOT_FOUND, LOCKFILE_MISSING, LOGIN_CODE_EXPIRED, LOGIN_FAILED, MANIFEST_MISSING, NOT_LOGGED_IN, PACKAGE_FILE_TOO_LARGE, PACKAGE_INDEX_MISSING, PACKAGE_PATH_RESERVED, PACKAGE_TOO_LARGE, PACKAGE_TOO_MANY_FILES, PACKAGE_UNCOMPRESSED_TOO_LARGE, PARSE_FAILED, PATH_NOT_FOUND, PORT_IN_USE, PROJECT_NOT_REPO_ROOT, SECRET_LIMIT_REACHED, SECRET_NOT_FOUND, SESSION_EXPIRED, TEMPLATE_MISSING, TEMPLATE_UNAVAILABLE, UNEXPECTED, UPLOAD_FAILED, VALIDATION_FAILED, VALUE_NOT_FOUND, VALUE_STORAGE_FULL, VALUE_TOO_LARGE, WAIT_TIMED_OUT, } = CLI;
|
|
140
|
+
export const { BUILD_RATE_LIMITED, FUNCTION_INVALID, FUNCTION_TOO_LARGE, GAME_HANDLE_CHANGED, GAME_LIMIT_REACHED, GAME_MISMATCH, GAME_UNAVAILABLE, GITHUB_APP_NOT_INSTALLED, INTERNAL, MANIFEST_INVALID, RELEASE_EXPIRED, REPO_NOT_CONNECTED, VERSION_EXISTS, VERSION_MISMATCH, ZIP_INVALID, ZIP_MISSING, ZIP_TOO_LARGE, } = RELEASE;
|
|
129
141
|
export const { GIT_TAG_INVALID, WORKFLOW_MISSING } = GITHUB;
|
package/dist/config/limit.js
CHANGED
|
@@ -12,3 +12,5 @@ export const FILE_SIZE = 64 * MB;
|
|
|
12
12
|
export const TOTAL_SIZE = 256 * MB;
|
|
13
13
|
// the zip of deploy_dir alone, compressed.
|
|
14
14
|
export const ZIP_SIZE = 64 * MB;
|
|
15
|
+
// a function's bundle, as Arcadible runs it (the subscriber's RUNNER_MAX).
|
|
16
|
+
export const FUNCTION_SIZE = 1 * MB;
|
package/dist/phrase/function.js
CHANGED
|
@@ -44,7 +44,10 @@ export function functionState({ function: has, paused, }) {
|
|
|
44
44
|
}
|
|
45
45
|
// [function]
|
|
46
46
|
// a resumed function, with any pause that isn't its owner's still on it.
|
|
47
|
-
export function functionResumed({ channel, paused, }) {
|
|
47
|
+
export function functionResumed({ channel, lifted, paused, }) {
|
|
48
|
+
if (!lifted) {
|
|
49
|
+
return `The game's function isn't paused on ${channel}.`;
|
|
50
|
+
}
|
|
48
51
|
if (paused) {
|
|
49
52
|
return blocks(`Lifted your pause on ${channel}.`, `The game's function stays paused: ${functionPause(paused)}.`);
|
|
50
53
|
}
|
|
@@ -58,15 +61,16 @@ export function functionMonth({ allowance, requests, }) {
|
|
|
58
61
|
: `${requests} of ${allowance} requests this month, both channels together.`;
|
|
59
62
|
}
|
|
60
63
|
// [function]
|
|
61
|
-
// a resume with no pause of the owner's to lift
|
|
62
|
-
|
|
64
|
+
// a resume with no pause of the owner's to lift, and one of another's: who
|
|
65
|
+
// lifts it.
|
|
66
|
+
export function functionPauseReserved({ channel, paused, }) {
|
|
63
67
|
if (paused === "arcadible") {
|
|
64
68
|
return blocks(`The game's function is paused by Arcadible on ${channel}.`, "Only Arcadible can resume it.");
|
|
65
69
|
}
|
|
66
70
|
if (paused === "limit") {
|
|
67
71
|
return blocks(`The game's function has spent its allowance on ${channel}.`, "It resumes by itself when the allowance renews.");
|
|
68
72
|
}
|
|
69
|
-
return `The game's function
|
|
73
|
+
return `The game's function is paused on ${channel}, and not by you.`;
|
|
70
74
|
}
|
|
71
75
|
// [function]
|
|
72
76
|
export function secretSet({ channel, name, }) {
|
|
@@ -122,6 +126,11 @@ export function runnerBuildFailed(message) {
|
|
|
122
126
|
return `The function didn't build:\n${message}`;
|
|
123
127
|
}
|
|
124
128
|
// [function]
|
|
129
|
+
// a function's bundle past what Arcadible runs.
|
|
130
|
+
export function functionTooLarge(size) {
|
|
131
|
+
return blocks(`The function's bundle is ${Math.ceil(size / 1024).toLocaleString("en-US")} KB, over 1 MB.`, "Import less into it: keep large data out of its code, in values or the game's files.");
|
|
132
|
+
}
|
|
133
|
+
// [function]
|
|
125
134
|
// a package asked for before the runner it carries was built.
|
|
126
135
|
export function runnerNotBuilt() {
|
|
127
136
|
return blocks("The function isn't built.", "Run `arc build` first.");
|
package/dist/phrase/game.js
CHANGED
|
@@ -20,8 +20,10 @@ export function gameDeletedProject() {
|
|
|
20
20
|
];
|
|
21
21
|
}
|
|
22
22
|
// [function]
|
|
23
|
-
// a game the API won't
|
|
24
|
-
//
|
|
25
|
-
|
|
23
|
+
// a game the API won't let its owner's commands reach (delete it, its
|
|
24
|
+
// values, keys, secrets, function, and wires): to anyone but its owner, one
|
|
25
|
+
// that isn't on Arcadible, one that's deleted already, and another account's
|
|
26
|
+
// are the same.
|
|
27
|
+
export function gameNotOwned(id) {
|
|
26
28
|
return blocks(`Game unavailable: ${id}\nIt was never deployed, was deleted, or belongs to another account.`, `${cmdWhoami()} shows the account you're logged in to.`);
|
|
27
29
|
}
|
package/dist/phrase/serve.js
CHANGED
|
@@ -29,6 +29,12 @@ export function remoteUnreachable(name) {
|
|
|
29
29
|
return `Unable to reach ${TITLE}, and ${remoteName(name)} isn't saved.\nThe game runs without it until ${TITLE} is back.`;
|
|
30
30
|
}
|
|
31
31
|
// [function]
|
|
32
|
+
// a link the game made, to open in another window as another player
|
|
33
|
+
// (`&player=<name>`).
|
|
34
|
+
export function linkMade(url) {
|
|
35
|
+
return `Link made: ${url}`;
|
|
36
|
+
}
|
|
37
|
+
// [function]
|
|
32
38
|
export function reloaded() {
|
|
33
39
|
return `Reloaded at ${new Date().toTimeString().slice(0, 8)}.`;
|
|
34
40
|
}
|
package/dist/runner/bundle.js
CHANGED
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
// the pipeline as a build is released, and by arc serve (./entry.ts), so no
|
|
6
6
|
// build carries an entry of the day its `arc` was installed.
|
|
7
7
|
// [import]
|
|
8
|
+
import { stat } from "node:fs/promises";
|
|
8
9
|
import { join } from "node:path";
|
|
9
10
|
// [import]
|
|
10
11
|
import { build } from "esbuild";
|
|
11
12
|
import { pathExists } from "fs-extra";
|
|
12
13
|
// [import]
|
|
13
|
-
import { BUILD_FAILED } from "../config/code.js";
|
|
14
|
+
import { BUILD_FAILED, FUNCTION_TOO_LARGE } from "../config/code.js";
|
|
15
|
+
import { FUNCTION_SIZE } from "../config/limit.js";
|
|
14
16
|
import * as phrase from "../phrase/index.js";
|
|
15
17
|
import { ArcError } from "../util/error.js";
|
|
16
18
|
// [declare]
|
|
@@ -29,7 +31,9 @@ export const WRONG = {
|
|
|
29
31
|
};
|
|
30
32
|
// [function]
|
|
31
33
|
// bundles the runner whose code is at `main`, a full path, into `outfile`;
|
|
32
|
-
// code that isn't there, or doesn't build, fails as a build does
|
|
34
|
+
// code that isn't there, or doesn't build, fails as a build does, and a
|
|
35
|
+
// bundle past what Arcadible runs fails as the release would
|
|
36
|
+
// (function_too_large), before it's ever uploaded.
|
|
33
37
|
//
|
|
34
38
|
// `onPackages`, when given, hears the `@arcadible/` packages the bundle took
|
|
35
39
|
// in, by name, each once, so a build can say when a function imports one
|
|
@@ -59,6 +63,10 @@ export async function bundle({ main, onPackages, outfile, }) {
|
|
|
59
63
|
catch (ex) {
|
|
60
64
|
throw new ArcError(BUILD_FAILED, phrase.runnerBuildFailed(ex instanceof Error ? ex.message : String(ex)), { cause: ex });
|
|
61
65
|
}
|
|
66
|
+
const { size } = await stat(outfile);
|
|
67
|
+
if (size > FUNCTION_SIZE) {
|
|
68
|
+
throw new ArcError(FUNCTION_TOO_LARGE, phrase.functionTooLarge(size));
|
|
69
|
+
}
|
|
62
70
|
onPackages?.(packagesOf(inputs));
|
|
63
71
|
return outfile;
|
|
64
72
|
}
|
package/dist/serve/page.js
CHANGED
|
@@ -78,6 +78,17 @@ const VALUES_BODY_MAX = 512 * 1024;
|
|
|
78
78
|
const VALUE_WRITES = ["game", "player", "server"];
|
|
79
79
|
// what the API says of a request it refuses (app/lib/python/offst/error.py),
|
|
80
80
|
// in an error's `data`, with its status as `code`.
|
|
81
|
+
// each refusal's code, the status's word, as the API's own (its
|
|
82
|
+
// app/result.py's CODES; ERRORS.md).
|
|
83
|
+
const REFUSAL_CODES = {
|
|
84
|
+
400: "invalid",
|
|
85
|
+
403: "denied",
|
|
86
|
+
404: "not_found",
|
|
87
|
+
405: "method_not_allowed",
|
|
88
|
+
409: "conflict",
|
|
89
|
+
413: "too_large",
|
|
90
|
+
507: "full",
|
|
91
|
+
};
|
|
81
92
|
const REFUSALS = {
|
|
82
93
|
400: [
|
|
83
94
|
"Bad Request",
|
|
@@ -262,7 +273,11 @@ export function html(game, pictures = { art: false, icon: false }, opened, link)
|
|
|
262
273
|
`;
|
|
263
274
|
}
|
|
264
275
|
// [function]
|
|
265
|
-
//
|
|
276
|
+
// what `readJson` resolves with for a body larger than it takes, which a
|
|
277
|
+
// values call answers `413`, as the API does.
|
|
278
|
+
const OVERSIZE = Symbol("oversize");
|
|
279
|
+
// [function]
|
|
280
|
+
// a request's body as JSON; OVERSIZE, larger than `max`; or null, not JSON.
|
|
266
281
|
function readJson(req, max = BODY_MAX) {
|
|
267
282
|
return new Promise((resolve) => {
|
|
268
283
|
const chunks = [];
|
|
@@ -276,7 +291,7 @@ function readJson(req, max = BODY_MAX) {
|
|
|
276
291
|
req.on("error", () => resolve(null));
|
|
277
292
|
req.on("end", () => {
|
|
278
293
|
try {
|
|
279
|
-
resolve(size > max ?
|
|
294
|
+
resolve(size > max ? OVERSIZE : JSON.parse(Buffer.concat(chunks).toString()));
|
|
280
295
|
}
|
|
281
296
|
catch {
|
|
282
297
|
resolve(null);
|
|
@@ -292,7 +307,7 @@ function readJson(req, max = BODY_MAX) {
|
|
|
292
307
|
// ticket. 400 a body that isn't an object; 403 no one to make it; 413 data
|
|
293
308
|
// past 1 KB as JSON. None of Arcadible's rate is kept, nor its 30 days: a
|
|
294
309
|
// link lasts until arc serve stops.
|
|
295
|
-
async function sendLink(req, res, { links, playing }) {
|
|
310
|
+
async function sendLink(req, res, { links, onLink, origin, playing, }) {
|
|
296
311
|
const type = ((req.headers["content-type"] ?? "").split(";")[0] ?? "").trim();
|
|
297
312
|
const asked = type.toLowerCase() === "application/json" ? await readJson(req) : null;
|
|
298
313
|
if (!isTable(asked)) {
|
|
@@ -319,6 +334,7 @@ async function sendLink(req, res, { links, playing }) {
|
|
|
319
334
|
id += LINK_ALPHABET.charAt(crypto.randomInt(LINK_ALPHABET.length));
|
|
320
335
|
}
|
|
321
336
|
links.set(id, { by, data, id });
|
|
337
|
+
onLink(`${origin}/?l=${id}`);
|
|
322
338
|
res.writeHead(200, {
|
|
323
339
|
...HEADERS,
|
|
324
340
|
"content-type": "application/json; charset=utf-8",
|
|
@@ -534,7 +550,7 @@ async function sendGameValues(req, res, verb, { player, values }) {
|
|
|
534
550
|
? await readJson(req, VALUES_BODY_MAX)
|
|
535
551
|
: null;
|
|
536
552
|
if (!isTable(body)) {
|
|
537
|
-
refuse(400);
|
|
553
|
+
refuse(body === OVERSIZE ? 413 : 400);
|
|
538
554
|
return;
|
|
539
555
|
}
|
|
540
556
|
const write = verb === "write" || verb === "remove";
|
|
@@ -667,8 +683,9 @@ function windowOf(pathname, named) {
|
|
|
667
683
|
function sendRefusal(req, res, status, conflicts) {
|
|
668
684
|
const [title, message] = REFUSALS[status] ?? ["", ""];
|
|
669
685
|
sendData(req, res, status, {
|
|
670
|
-
code: status,
|
|
686
|
+
code: REFUSAL_CODES[status] ?? "invalid",
|
|
671
687
|
message,
|
|
688
|
+
status,
|
|
672
689
|
title,
|
|
673
690
|
type: "HttpError",
|
|
674
691
|
...(conflicts ? { conflicts } : {}),
|
|
@@ -684,7 +701,7 @@ function sendRefusal(req, res, status, conflicts) {
|
|
|
684
701
|
async function sendValues(req, res, verb, values) {
|
|
685
702
|
const body = await readJson(req, VALUES_BODY_MAX);
|
|
686
703
|
if (!values || !isTable(body)) {
|
|
687
|
-
sendRefusal(req, res, values ?
|
|
704
|
+
sendRefusal(req, res, !values ? 404 : body === OVERSIZE ? 413 : 400);
|
|
688
705
|
return;
|
|
689
706
|
}
|
|
690
707
|
// whether the call names one scope for all its keys; a list's does
|
|
@@ -835,7 +852,7 @@ async function sendServer(req, res, route, { game, tickets, values, wires, }) {
|
|
|
835
852
|
// `tickets` mints the game's, and publishes their key, and `playerOf(name)`
|
|
836
853
|
// is a local player by name (./ticket.js). `faviconFile` is the play page's
|
|
837
854
|
// favicon.ico, the package's own unless a test names another.
|
|
838
|
-
export function pageHandler({ art = () => Promise.resolve(null), faviconFile = FAVICON, game, hostFile = null, icon = () => Promise.resolve(null), onRemote = () => null, playerOf = () => null, reloads, remote, tickets = null, values = null, wires = null, }) {
|
|
855
|
+
export function pageHandler({ art = () => Promise.resolve(null), faviconFile = FAVICON, game, hostFile = null, icon = () => Promise.resolve(null), onLink = () => undefined, onRemote = () => null, origin = "http://localhost", playerOf = () => null, reloads, remote, tickets = null, values = null, wires = null, }) {
|
|
839
856
|
// the play page's favicon.ico, read once, or null when it can't be read,
|
|
840
857
|
// which is tried again on the next request.
|
|
841
858
|
let favicon = null;
|
|
@@ -900,7 +917,7 @@ export function pageHandler({ art = () => Promise.resolve(null), faviconFile = F
|
|
|
900
917
|
res.writeHead(405, { ...HEADERS, allow: "POST" }).end();
|
|
901
918
|
return Promise.resolve();
|
|
902
919
|
}
|
|
903
|
-
return sendLink(req, res, { links, playing });
|
|
920
|
+
return sendLink(req, res, { links, onLink, origin, playing });
|
|
904
921
|
}
|
|
905
922
|
if (opened) {
|
|
906
923
|
// only the page's own API is under a window's path
|
package/dist/serve/runner.js
CHANGED
|
@@ -93,6 +93,28 @@ const CORS = {
|
|
|
93
93
|
"access-control-max-age": "600",
|
|
94
94
|
};
|
|
95
95
|
// [function]
|
|
96
|
+
// Arcadible's own answer, marked as the dispatcher marks it: a status, and
|
|
97
|
+
// a code the SDK's `functions.fetch` rejects with.
|
|
98
|
+
function refuse(res, status, code) {
|
|
99
|
+
res.writeHead(status, {
|
|
100
|
+
...CORS,
|
|
101
|
+
"content-type": "application/json",
|
|
102
|
+
[REFUSAL]: code,
|
|
103
|
+
});
|
|
104
|
+
res.end(JSON.stringify({ code }));
|
|
105
|
+
}
|
|
106
|
+
// [function]
|
|
107
|
+
/**
|
|
108
|
+
* The answer under PREFIX for a project with no function, as the
|
|
109
|
+
* dispatcher's for a build with none: `404`, `no_function`.
|
|
110
|
+
*/
|
|
111
|
+
export const noFunction = function (req, res) {
|
|
112
|
+
if (req.method === "OPTIONS")
|
|
113
|
+
res.writeHead(204, CORS).end();
|
|
114
|
+
else
|
|
115
|
+
refuse(res, 404, "no_function");
|
|
116
|
+
return Promise.resolve();
|
|
117
|
+
};
|
|
96
118
|
// a port nothing listens on, on this machine.
|
|
97
119
|
function freePort() {
|
|
98
120
|
return new Promise((resolve, reject) => {
|
|
@@ -302,24 +324,22 @@ export async function runner({ dir, handler, hosts = [], main, origin, secrets =
|
|
|
302
324
|
? await tickets.check(ticket, origin)
|
|
303
325
|
: { data: { code: "invalid" }, status: 422 };
|
|
304
326
|
if (checked.status !== 200) {
|
|
305
|
-
res
|
|
306
|
-
...CORS,
|
|
307
|
-
"content-type": "application/json",
|
|
308
|
-
[REFUSAL]: checked.data.code,
|
|
309
|
-
});
|
|
310
|
-
res.end(JSON.stringify({ code: checked.data.code }));
|
|
327
|
+
refuse(res, 401, checked.data.code);
|
|
311
328
|
return;
|
|
312
329
|
}
|
|
313
330
|
// a body past what a function may be sent, said or streamed, as the
|
|
314
|
-
// dispatcher refuses it: a streamed one is read here, to hold it
|
|
315
|
-
|
|
331
|
+
// dispatcher refuses it: a streamed one is read here, to hold it. One
|
|
332
|
+
// that couldn't be read is `invalid`, as there.
|
|
333
|
+
let body;
|
|
334
|
+
try {
|
|
335
|
+
body = await bodyOf(req);
|
|
336
|
+
}
|
|
337
|
+
catch {
|
|
338
|
+
refuse(res, 400, "invalid");
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
316
341
|
if (body === null) {
|
|
317
|
-
res
|
|
318
|
-
...CORS,
|
|
319
|
-
"content-type": "application/json",
|
|
320
|
-
[REFUSAL]: TOO_LARGE,
|
|
321
|
-
});
|
|
322
|
-
res.end(JSON.stringify({ code: TOO_LARGE }));
|
|
342
|
+
refuse(res, 413, TOO_LARGE);
|
|
323
343
|
return;
|
|
324
344
|
}
|
|
325
345
|
// the game's answer when its function failed, as the dispatcher's: why
|
package/dist/serve/server.js
CHANGED
|
@@ -8,7 +8,7 @@ import http, {} from "node:http";
|
|
|
8
8
|
import { gameHandler, pathOf } from "./game.js";
|
|
9
9
|
import { pageHandler } from "./page.js";
|
|
10
10
|
import { reloader } from "./reload.js";
|
|
11
|
-
import { PREFIX as RUNNER, runner as startRunner, } from "./runner.js";
|
|
11
|
+
import { noFunction, PREFIX as RUNNER, runner as startRunner, } from "./runner.js";
|
|
12
12
|
import { playerOf, tickets as ticketsFor } from "./ticket.js";
|
|
13
13
|
import { values as valuesFor } from "./values.js";
|
|
14
14
|
import { PREFIX as WIRES, wires as wiresFor } from "./wires.js";
|
|
@@ -40,7 +40,7 @@ function listen(handler, port, address) {
|
|
|
40
40
|
// or a guest. Resolves with
|
|
41
41
|
// `{ page, game, reload(), close() }`: the page's origin, the game's URL,
|
|
42
42
|
// and the controls.
|
|
43
|
-
export async function serve({ art, files, hostFile = null, icon, info, keyFile, onRemote, player = null, port, remote, root, runner: runs = null, servers = [], connect = [], src, wiresDrop = null, }) {
|
|
43
|
+
export async function serve({ art, files, hostFile = null, icon, info, keyFile, onLink, onRemote, player = null, port, remote, root, runner: runs = null, servers = [], connect = [], src, wiresDrop = null, }) {
|
|
44
44
|
const origins = {
|
|
45
45
|
game: `http://127.0.0.1:${port}`,
|
|
46
46
|
page: `http://localhost:${port}`,
|
|
@@ -98,7 +98,9 @@ export async function serve({ art, files, hostFile = null, icon, info, keyFile,
|
|
|
98
98
|
},
|
|
99
99
|
hostFile,
|
|
100
100
|
icon,
|
|
101
|
+
onLink,
|
|
101
102
|
onRemote,
|
|
103
|
+
origin: origins.page,
|
|
102
104
|
playerOf: (name) => playerOf(info.id, name),
|
|
103
105
|
reloads,
|
|
104
106
|
remote,
|
|
@@ -121,8 +123,10 @@ export async function serve({ art, files, hostFile = null, icon, info, keyFile,
|
|
|
121
123
|
// what's under the runner's folder, as Arcadible's edge sends it on:
|
|
122
124
|
// /arcadible/runner itself, like /arcadible/runnerx, is a file of
|
|
123
125
|
// Arcadible's, like any other there, and isn't found.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
+
// A project with no function is answered as Arcadible answers a build
|
|
127
|
+
// with none.
|
|
128
|
+
const forRunner = onGame && pathname !== null && pathname.startsWith(`${RUNNER}/`)
|
|
129
|
+
? (runner?.handle ?? noFunction)
|
|
126
130
|
: null;
|
|
127
131
|
// a game opens a wire at Arcadible's path on its own origin, whether
|
|
128
132
|
// its files are served here or framed from another server (--url)
|
package/dist/serve/wires.js
CHANGED
|
@@ -10,7 +10,7 @@ import crypto from "node:crypto";
|
|
|
10
10
|
// [import]
|
|
11
11
|
import { WebSocketServer } from "ws";
|
|
12
12
|
// [import]
|
|
13
|
-
import { CLOSED, createRoom, LIMITS, PING, PONG, PROTOCOL, } from "../wires/room.js";
|
|
13
|
+
import { CLOSED, createRoom, LIMITS, PING, PONG, PROTOCOL, ticketClose, } from "../wires/room.js";
|
|
14
14
|
import { CHANNEL } from "./ticket.js";
|
|
15
15
|
// [declare]
|
|
16
16
|
// where wires answer on a build's own origin, as on Arcadible
|
|
@@ -31,8 +31,10 @@ const CORS = {
|
|
|
31
31
|
"access-control-expose-headers": REFUSAL,
|
|
32
32
|
"access-control-max-age": "600",
|
|
33
33
|
};
|
|
34
|
-
// the largest frame a connection may send: a message
|
|
35
|
-
|
|
34
|
+
// the largest frame a connection may send, Cloudflare's: a larger message
|
|
35
|
+
// than a wire takes is refused as `too_large`, the connection kept, as on
|
|
36
|
+
// Arcadible.
|
|
37
|
+
const FRAME_MAX = 1024 * 1024;
|
|
36
38
|
// [function]
|
|
37
39
|
// arc serve's wires for `game`, on its own `origin`, where a ticket for a
|
|
38
40
|
// wire is for. `tickets` are arc serve's own (./ticket.ts), which say who's
|
|
@@ -183,7 +185,7 @@ export function wires({ drop = null, game, origin, tickets, }) {
|
|
|
183
185
|
}
|
|
184
186
|
void memberOf(ticket).then((who) => {
|
|
185
187
|
if ("code" in who) {
|
|
186
|
-
|
|
188
|
+
ws.close(ticketClose(who.code), who.code);
|
|
187
189
|
return;
|
|
188
190
|
}
|
|
189
191
|
const { on, room } = wire(id);
|
|
@@ -205,8 +207,11 @@ export function wires({ drop = null, game, origin, tickets, }) {
|
|
|
205
207
|
on.set(key, mine);
|
|
206
208
|
ws.on("message", (data, isBinary) => {
|
|
207
209
|
mine.heard = Date.now();
|
|
208
|
-
|
|
210
|
+
// a wire carries text: JSON, a frame each
|
|
211
|
+
if (isBinary) {
|
|
212
|
+
room.said(key, "");
|
|
209
213
|
return;
|
|
214
|
+
}
|
|
210
215
|
const text = data.toString();
|
|
211
216
|
if (text === PING)
|
|
212
217
|
ws.send(PONG);
|
package/dist/util/error.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// [import]
|
|
2
|
-
import { ALL, API_REFUSED, INTERNAL } from "../config/code.js";
|
|
2
|
+
import { ALL, API_REFUSED, INTERNAL, UNEXPECTED } from "../config/code.js";
|
|
3
3
|
import { HttpError } from "./http.js";
|
|
4
4
|
// [class]
|
|
5
5
|
// a failure with its code (config/code.js), which scripts match on while the
|
|
@@ -21,15 +21,18 @@ export class ArcError extends Error {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
// [function]
|
|
24
|
-
// the code a failure reports: its own,
|
|
25
|
-
//
|
|
26
|
-
//
|
|
24
|
+
// the code a failure reports: its own; the API's, when it names one of the
|
|
25
|
+
// CLI's (ERRORS.md); api_refused for any other request the API refused;
|
|
26
|
+
// internal for a failure on Arcadible's side (a 5xx), worth trying again;
|
|
27
|
+
// and unexpected for anything else, a bug in the CLI, which isn't.
|
|
27
28
|
export function codeOf(ex) {
|
|
28
29
|
if (ex instanceof ArcError) {
|
|
29
30
|
return ex.code;
|
|
30
31
|
}
|
|
31
|
-
if (ex instanceof HttpError
|
|
32
|
-
|
|
32
|
+
if (ex instanceof HttpError) {
|
|
33
|
+
if (ex.status >= 500)
|
|
34
|
+
return INTERNAL;
|
|
35
|
+
return ex.code !== undefined && ALL.has(ex.code) ? ex.code : API_REFUSED;
|
|
33
36
|
}
|
|
34
|
-
return
|
|
37
|
+
return UNEXPECTED;
|
|
35
38
|
}
|
package/dist/util/http.js
CHANGED
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
import { httpError } from "../phrase/index.js";
|
|
3
3
|
// [class]
|
|
4
4
|
export class HttpError extends Error {
|
|
5
|
+
// the API's code for the refusal, which a client reads before its status:
|
|
6
|
+
// the database's own (`game_unavailable`), or the status's word
|
|
7
|
+
// (`denied`); undefined when the answer has none.
|
|
8
|
+
code;
|
|
5
9
|
status;
|
|
6
10
|
// [constructor]
|
|
7
|
-
constructor(status, { message, title } = {}) {
|
|
11
|
+
constructor(status, { code, message, title } = {}) {
|
|
8
12
|
super(message);
|
|
13
|
+
this.code = code;
|
|
9
14
|
this.status = status;
|
|
10
15
|
this.name = title || "HTTP Error";
|
|
11
16
|
this.message = httpError(this.name, this.status, message);
|
package/dist/util/request.js
CHANGED
|
@@ -28,15 +28,17 @@ function dataOf(body) {
|
|
|
28
28
|
return (isTable(body) ? body["data"] : null) ?? null;
|
|
29
29
|
}
|
|
30
30
|
// [function]
|
|
31
|
-
// an error's title and message, from the response's status text and
|
|
32
|
-
// API's own `{ title, message }`, which takes precedence when it's
|
|
31
|
+
// an error's code, title, and message, from the response's status text and
|
|
32
|
+
// the API's own `{ code, title, message }`, which takes precedence when it's
|
|
33
|
+
// there. A code is a string; an API from before its codes said the status.
|
|
33
34
|
function errorOf(statusText, data) {
|
|
34
35
|
const all = {
|
|
35
36
|
title: statusText,
|
|
36
37
|
...(isTable(data) ? data : {}),
|
|
37
38
|
};
|
|
38
|
-
const { message, title } = all;
|
|
39
|
+
const { code, message, title } = all;
|
|
39
40
|
return {
|
|
41
|
+
code: typeof code === "string" ? code : undefined,
|
|
40
42
|
message: typeof message === "string" ? message : undefined,
|
|
41
43
|
title: typeof title === "string" ? title : undefined,
|
|
42
44
|
};
|
package/dist/wires/room.js
CHANGED
|
@@ -42,6 +42,16 @@ export const CLOSED = {
|
|
|
42
42
|
/** A connection that went unheard: closed, and free to come back. */
|
|
43
43
|
export const IDLE = 4408;
|
|
44
44
|
// [function]
|
|
45
|
+
/**
|
|
46
|
+
* The close for a ticket a wire didn't take, by why: `4401` for one that ran
|
|
47
|
+
* out or was refused, as HTTP's `401` is for both, so the game asks for a
|
|
48
|
+
* new one and tries once more; a guest with no id `4403`; one that couldn't
|
|
49
|
+
* be checked `4503`. The close's reason says which.
|
|
50
|
+
*/
|
|
51
|
+
export function ticketClose(code) {
|
|
52
|
+
return code === "invalid" ? CLOSED.expired : CLOSED[code];
|
|
53
|
+
}
|
|
54
|
+
// [function]
|
|
45
55
|
// tokens that refill at `rate` a second, up to `burst`: whether one is
|
|
46
56
|
// there to take, at `at`.
|
|
47
57
|
function bucket(rate, burst) {
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"license": "Apache-2.0",
|
|
46
46
|
"name": "arcadible",
|
|
47
|
-
"version": "1.0.
|
|
47
|
+
"version": "1.0.35"
|
|
48
48
|
},
|
|
49
49
|
"node_modules/@asamuzakjp/css-color": {
|
|
50
50
|
"dependencies": {
|
|
@@ -3267,5 +3267,5 @@
|
|
|
3267
3267
|
}
|
|
3268
3268
|
},
|
|
3269
3269
|
"requires": true,
|
|
3270
|
-
"version": "1.0.
|
|
3270
|
+
"version": "1.0.35"
|
|
3271
3271
|
}
|
package/package.json
CHANGED