arcadible 1.0.42 → 1.0.43
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 -5
- package/dist/action/function/logs.js +100 -30
- package/dist/action/function/tool.js +2 -2
- package/dist/action/game.js +3 -3
- package/dist/action/init/tool.js +26 -4
- package/dist/action/key/tool.js +5 -5
- package/dist/action/pack/tool.js +2 -2
- package/dist/action/predeploy/ac.js +4 -4
- package/dist/action/secret/tool.js +9 -8
- package/dist/action/serve/tool.js +3 -3
- package/dist/action/value/tool.js +6 -6
- package/dist/action/wire/tool.js +2 -2
- package/dist/api.js +2 -2
- package/dist/command/init.js +2 -2
- package/dist/config/code.js +22 -19
- package/dist/config/retry.js +105 -0
- package/dist/phrase/deploy.js +2 -2
- package/dist/phrase/function.js +2 -2
- package/dist/phrase/game.js +1 -1
- package/dist/phrase/init.js +7 -1
- package/dist/phrase/pack.js +6 -1
- package/dist/phrase/server.js +1 -1
- package/dist/runner/bundle.js +2 -2
- package/dist/runner/outbound.js +2 -0
- package/dist/schema/game.js +1 -1
- package/dist/serve/message.js +79 -0
- package/dist/serve/page.js +70 -60
- package/dist/serve/retry.js +4 -8
- package/dist/serve/runner.js +15 -6
- package/dist/serve/ticket.js +5 -5
- package/dist/serve/wires.js +10 -6
- package/dist/util/error.js +28 -8
- package/dist/util/http.js +6 -2
- package/dist/util/output.js +54 -16
- package/dist/util/request.js +2 -1
- package/dist/util/s3.js +1 -1
- package/dist/wires/room.js +30 -37
- package/npm-shrinkwrap.json +67 -67
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// for players at once, with every build, and it can't be undone. Nothing in
|
|
3
3
|
// the project changes.
|
|
4
4
|
import { deleteGame } from "../../api.js";
|
|
5
|
-
import { GAME_ID_MISSING,
|
|
5
|
+
import { GAME_ID_MISSING, GAME_NOT_FOUND } 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";
|
|
@@ -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(
|
|
41
|
+
throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), {
|
|
42
42
|
cause: err,
|
|
43
43
|
});
|
|
44
44
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// [import]
|
|
2
2
|
import { authed } from "../../account.js";
|
|
3
3
|
import { postUpload } from "../../api.js";
|
|
4
|
-
import { DEPLOY_RATE_LIMITED,
|
|
4
|
+
import { DEPLOY_RATE_LIMITED, GAME_NOT_FOUND } from "../../config/code.js";
|
|
5
5
|
import { ArcError } from "../../util/error.js";
|
|
6
6
|
import { releasing } from "../predeploy/game.js";
|
|
7
7
|
import { isRefused } from "../game.js";
|
|
8
|
-
import { deployRateLimited,
|
|
8
|
+
import { deployRateLimited, gameDeletedOrNotOwned, } from "../../phrase/index.js";
|
|
9
9
|
import { published } from "../../util/links.js";
|
|
10
10
|
import { upload as s3Upload } from "../../util/s3.js";
|
|
11
11
|
// [function]
|
|
@@ -20,10 +20,10 @@ function uploadBuild(current, artifact, { id, version }, onProgress) {
|
|
|
20
20
|
form.append("size", String(artifact.size));
|
|
21
21
|
return authed(current, (headers) => postUpload(form, null, headers)).then((upload) => s3Upload(upload.upload_url, artifact, onProgress).then(() => upload), (err) => {
|
|
22
22
|
// the API refuses a game that was deleted or is another account's
|
|
23
|
-
// (
|
|
23
|
+
// (404), and the same version deployed again within 5 minutes (429),
|
|
24
24
|
// each by its code.
|
|
25
|
-
if (isRefused(err,
|
|
26
|
-
throw new ArcError(
|
|
25
|
+
if (isRefused(err, GAME_NOT_FOUND, 404)) {
|
|
26
|
+
throw new ArcError(GAME_NOT_FOUND, gameDeletedOrNotOwned(id), {
|
|
27
27
|
cause: err,
|
|
28
28
|
});
|
|
29
29
|
}
|
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
// [import]
|
|
7
7
|
import { WebSocket } from "ws";
|
|
8
8
|
import { postGameFunctionLogsToken } from "../../api.js";
|
|
9
|
-
import {
|
|
10
|
-
import { ArcError } from "../../util/error.js";
|
|
9
|
+
import { API_UNREACHABLE, ARGUMENT_INVALID, FUNCTION_LOGS_FOLLOWS_FULL, GAME_NOT_FOUND, UNAVAILABLE, UNEXPECTED, } from "../../config/code.js";
|
|
10
|
+
import { ArcError, codeOf } from "../../util/error.js";
|
|
11
|
+
import { HttpError } from "../../util/http.js";
|
|
11
12
|
import { sleep } from "../../util/delay.js";
|
|
12
13
|
import { isTable } from "../../util/objs.js";
|
|
13
14
|
import { channelOf, gameOf, headersOf, isStatus } from "../game.js";
|
|
14
|
-
import { answerUnread,
|
|
15
|
+
import { answerUnread, functionLogsFull, functionLogsRefused, functionLogsSinceInvalid, functionLogsVersionInvalid, gameNotOwned, unableToReach, } from "../../phrase/index.js";
|
|
15
16
|
// [declare]
|
|
16
17
|
// the protocol a follow speaks, offered with the token beside it, and the
|
|
17
18
|
// code it's closed with at its hour (the logs Worker's src/logs.js and
|
|
@@ -81,29 +82,70 @@ function isEntry(value) {
|
|
|
81
82
|
typeof value["at"] === "number");
|
|
82
83
|
}
|
|
83
84
|
// [function]
|
|
84
|
-
// the Worker's refusal as the CLI's failure
|
|
85
|
-
//
|
|
85
|
+
// the Worker's refusal as the CLI's failure, read as the API's is (codeOf):
|
|
86
|
+
// its code where it's one of the CLI's, unavailable for a 5xx with none,
|
|
87
|
+
// and api_refused for anything else, never a 401 that would end the
|
|
86
88
|
// session, since the token isn't the session's.
|
|
87
|
-
function refused(status,
|
|
88
|
-
|
|
89
|
+
function refused(status, said) {
|
|
90
|
+
// the Worker's own code, retry, and status go with the failure, as its
|
|
91
|
+
// cause
|
|
92
|
+
const told = httpErrorOf(status, said);
|
|
93
|
+
const { code } = said;
|
|
94
|
+
return new ArcError(codeOf(told), functionLogsRefused({ code, status }), {
|
|
95
|
+
cause: told,
|
|
96
|
+
status,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// [function]
|
|
100
|
+
// a new token refused as expired too: Arcadible's own trouble with its own
|
|
101
|
+
// token, which getting another didn't mend, so it's unavailable (ERRORS.md,
|
|
102
|
+
// Passing a code on), carrying the refusal.
|
|
103
|
+
function tokenRefused(said) {
|
|
104
|
+
return new ArcError(UNAVAILABLE, functionLogsRefused({ code: "expired", status: 401 }), { cause: httpErrorOf(401, { ...said, code: "expired" }), status: 401 });
|
|
105
|
+
}
|
|
106
|
+
// [function]
|
|
107
|
+
// the Worker's refusal as an HttpError, with what it said.
|
|
108
|
+
function httpErrorOf(status, { code, retry }) {
|
|
109
|
+
return new HttpError(status, {
|
|
110
|
+
...(code === null ? {} : { code }),
|
|
111
|
+
...(retry === null ? {} : { retry }),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// [function]
|
|
115
|
+
// what a refusal's body said: its code and retry, each null when it said
|
|
116
|
+
// none, or the body isn't JSON.
|
|
117
|
+
function toldIn(body) {
|
|
118
|
+
const said = (key) => isTable(body) && typeof body[key] === "string" ? body[key] : null;
|
|
119
|
+
return { code: said("code"), retry: said("retry") };
|
|
120
|
+
}
|
|
121
|
+
// [function]
|
|
122
|
+
// what a refusal's text said, as toldIn.
|
|
123
|
+
function toldInText(text) {
|
|
124
|
+
try {
|
|
125
|
+
return toldIn(JSON.parse(text));
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return toldIn(null);
|
|
129
|
+
}
|
|
89
130
|
}
|
|
90
131
|
// [function]
|
|
91
132
|
// a token for the game's logs: the game is the caller's, or
|
|
92
|
-
//
|
|
133
|
+
// game_not_found, as for the rest of `arc unstable function`.
|
|
93
134
|
async function tokenOf(id, headers) {
|
|
94
135
|
try {
|
|
95
136
|
return await postGameFunctionLogsToken(id, null, headers);
|
|
96
137
|
}
|
|
97
138
|
catch (err) {
|
|
98
139
|
if (isStatus(err, 404)) {
|
|
99
|
-
throw new ArcError(
|
|
140
|
+
throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), { cause: err });
|
|
100
141
|
}
|
|
101
142
|
throw err;
|
|
102
143
|
}
|
|
103
144
|
}
|
|
104
145
|
// [function]
|
|
105
|
-
// the newest page, newest first, or null when the token had expired.
|
|
106
|
-
|
|
146
|
+
// the newest page, newest first, or null when the token had expired. A
|
|
147
|
+
// token that expired on the `last` try is unavailable (tokenRefused).
|
|
148
|
+
async function pageOf(token, query, last) {
|
|
107
149
|
let res;
|
|
108
150
|
try {
|
|
109
151
|
res = await fetch(query.size ? `${token.url}?${query.toString()}` : token.url, {
|
|
@@ -122,30 +164,32 @@ async function pageOf(token, query) {
|
|
|
122
164
|
}
|
|
123
165
|
}, () => null);
|
|
124
166
|
if (!res.ok) {
|
|
125
|
-
const
|
|
126
|
-
if (res.status === 401 && code === "expired")
|
|
167
|
+
const told = toldIn(body);
|
|
168
|
+
if (res.status === 401 && told.code === "expired") {
|
|
169
|
+
if (last)
|
|
170
|
+
throw tokenRefused(told);
|
|
127
171
|
return null;
|
|
128
|
-
|
|
172
|
+
}
|
|
173
|
+
throw refused(res.status, told);
|
|
129
174
|
}
|
|
130
175
|
if (!isPage(body)) {
|
|
131
|
-
throw new ArcError(
|
|
176
|
+
throw new ArcError(UNEXPECTED, answerUnread("a function's logs"));
|
|
132
177
|
}
|
|
133
178
|
return body.data;
|
|
134
179
|
}
|
|
135
180
|
// [function]
|
|
136
181
|
// the game's newest entries that match, at most 100, newest first. A token
|
|
137
|
-
// that ended on its way is asked for again, once
|
|
182
|
+
// that ended on its way is asked for again, once, and a second refused is
|
|
183
|
+
// unavailable.
|
|
138
184
|
export async function logs(current, { channel, ...conf }) {
|
|
139
185
|
const where = channelOf(channel);
|
|
140
186
|
const query = queryOf(conf, where);
|
|
141
187
|
const id = await gameOf(conf);
|
|
142
188
|
const headers = headersOf(current);
|
|
143
189
|
for (let tries = 0;; tries += 1) {
|
|
144
|
-
const page = await pageOf(await tokenOf(id, headers), query);
|
|
190
|
+
const page = await pageOf(await tokenOf(id, headers), query, tries > 0);
|
|
145
191
|
if (page)
|
|
146
192
|
return page;
|
|
147
|
-
if (tries)
|
|
148
|
-
throw refused(401, "expired");
|
|
149
193
|
}
|
|
150
194
|
}
|
|
151
195
|
// [function]
|
|
@@ -159,19 +203,31 @@ function followOnce(token, query, shown) {
|
|
|
159
203
|
let opened = false;
|
|
160
204
|
let done = false;
|
|
161
205
|
let pinging = null;
|
|
162
|
-
const end = (status) => {
|
|
206
|
+
const end = (status, told = toldIn(null)) => {
|
|
163
207
|
if (done)
|
|
164
208
|
return;
|
|
165
209
|
done = true;
|
|
166
210
|
if (pinging)
|
|
167
211
|
clearInterval(pinging);
|
|
168
|
-
resolve({ opened, status });
|
|
212
|
+
resolve({ ...told, opened, status });
|
|
169
213
|
};
|
|
170
214
|
const socket = new WebSocket(url.href, [PROTOCOL, token.token]);
|
|
215
|
+
// a refusal's body says its code and retry, read before the
|
|
216
|
+
// connection's dropped
|
|
171
217
|
socket.on("unexpected-response", (req, res) => {
|
|
172
|
-
|
|
173
|
-
res.
|
|
174
|
-
|
|
218
|
+
const chunks = [];
|
|
219
|
+
const status = res.statusCode ?? 500;
|
|
220
|
+
res.on("data", (chunk) => {
|
|
221
|
+
chunks.push(chunk);
|
|
222
|
+
});
|
|
223
|
+
res.on("end", () => {
|
|
224
|
+
req.destroy();
|
|
225
|
+
end(status, toldInText(Buffer.concat(chunks).toString("utf8")));
|
|
226
|
+
});
|
|
227
|
+
res.on("error", () => {
|
|
228
|
+
req.destroy();
|
|
229
|
+
end(status);
|
|
230
|
+
});
|
|
175
231
|
});
|
|
176
232
|
socket.on("open", () => {
|
|
177
233
|
opened = true;
|
|
@@ -202,8 +258,12 @@ function followOnce(token, query, shown) {
|
|
|
202
258
|
// the game's newest entries that match, then each new one as it comes,
|
|
203
259
|
// until the command is stopped: `shown` is given each once, oldest first.
|
|
204
260
|
// A follow closes at its hour, or when the connection drops, and is opened
|
|
205
|
-
// again with a new token
|
|
206
|
-
//
|
|
261
|
+
// again with a new token, as is one refused as expired or by Arcadible's
|
|
262
|
+
// side; one the Worker refuses otherwise ends the command, a sixth follow
|
|
263
|
+
// as function_logs_follows_full, and so does one that can't be opened five
|
|
264
|
+
// times in a row: unavailable when the last was a token refused as
|
|
265
|
+
// expired, as a page's second is, else as the last refusal it was told,
|
|
266
|
+
// carried, or api_unreachable when nothing answered.
|
|
207
267
|
export async function follow(current, { channel, ...conf }, shown) {
|
|
208
268
|
const where = channelOf(channel);
|
|
209
269
|
const query = queryOf(conf, where);
|
|
@@ -225,13 +285,23 @@ export async function follow(current, { channel, ...conf }, shown) {
|
|
|
225
285
|
query.delete("since");
|
|
226
286
|
for (let failed = 0;;) {
|
|
227
287
|
const closed = await followOnce(await tokenOf(id, headers), query, once);
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
288
|
+
const { code, status } = closed;
|
|
289
|
+
if (code === "full" || status === 507) {
|
|
290
|
+
throw new ArcError(FUNCTION_LOGS_FOLLOWS_FULL, functionLogsFull(), {
|
|
291
|
+
cause: httpErrorOf(status ?? 507, closed),
|
|
292
|
+
status: status ?? 507,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
const expired = status === 401 && (code === null || code === "expired");
|
|
296
|
+
if (status && status < 500 && !expired) {
|
|
297
|
+
throw refused(status, closed);
|
|
232
298
|
}
|
|
233
299
|
failed = closed.opened ? 0 : failed + 1;
|
|
234
300
|
if (failed >= TRIES) {
|
|
301
|
+
if (expired)
|
|
302
|
+
throw tokenRefused(closed);
|
|
303
|
+
if (status)
|
|
304
|
+
throw refused(status, closed);
|
|
235
305
|
throw new ArcError(API_UNREACHABLE, unableToReach());
|
|
236
306
|
}
|
|
237
307
|
// a follow that opened and closed is opened again after a second at
|
|
@@ -3,7 +3,7 @@
|
|
|
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 { FUNCTION_PAUSE_NOT_OWNED,
|
|
6
|
+
import { FUNCTION_PAUSE_NOT_OWNED, GAME_NOT_FOUND } from "../../config/code.js";
|
|
7
7
|
import { ArcError } from "../../util/error.js";
|
|
8
8
|
import { channelOf, CHANNELS, gameOf, headersOf, isStatus, needOf, ownedOf, } from "../game.js";
|
|
9
9
|
import { functionPauseNotOwned, gameNotOwned } from "../../phrase/index.js";
|
|
@@ -62,7 +62,7 @@ export async function pause(current, { channel, ...conf }) {
|
|
|
62
62
|
}
|
|
63
63
|
catch (err) {
|
|
64
64
|
if (isStatus(err, 404)) {
|
|
65
|
-
throw new ArcError(
|
|
65
|
+
throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), {
|
|
66
66
|
cause: err,
|
|
67
67
|
});
|
|
68
68
|
}
|
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, gameWireUsages } from "../api.js";
|
|
6
|
-
import { ALL, ARGUMENT_INVALID, GAME_ID_MISSING,
|
|
6
|
+
import { ALL, ARGUMENT_INVALID, GAME_ID_MISSING, GAME_NOT_FOUND, 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";
|
|
@@ -59,12 +59,12 @@ export function headersOf(current) {
|
|
|
59
59
|
// that the game is the caller's, asked before a read the API answers as
|
|
60
60
|
// none for another account's game (its keys, its function's secrets,
|
|
61
61
|
// pauses, and usage): its owner always reads today's wire usage for each
|
|
62
|
-
// channel, so none at all is a game that isn't theirs,
|
|
62
|
+
// channel, so none at all is a game that isn't theirs, game_not_found,
|
|
63
63
|
// as `arc unstable wire usage` says.
|
|
64
64
|
export async function ownedOf(id, headers) {
|
|
65
65
|
const rows = await gameWireUsages(id, null, headers);
|
|
66
66
|
if (!rows?.length) {
|
|
67
|
-
throw new ArcError(
|
|
67
|
+
throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id));
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
// [function]
|
package/dist/action/init/tool.js
CHANGED
|
@@ -4,9 +4,10 @@ import { createRequire } from "node:module";
|
|
|
4
4
|
import { join, resolve } from "node:path";
|
|
5
5
|
import fs from "fs-extra";
|
|
6
6
|
// [import]
|
|
7
|
-
import {
|
|
7
|
+
import { API_UNREACHABLE, TEMPLATE_NOT_FOUND } from "../../config/code.js";
|
|
8
8
|
import { ArcError } from "../../util/error.js";
|
|
9
|
-
import {
|
|
9
|
+
import { isTable } from "../../util/objs.js";
|
|
10
|
+
import { templateNotFound, templateUnreachable } from "../../phrase/index.js";
|
|
10
11
|
import { detectVersion, prepare } from "./manifest.js";
|
|
11
12
|
import { choices } from "../../config/template.js";
|
|
12
13
|
// [use]
|
|
@@ -24,10 +25,31 @@ function removeLicense(dest) {
|
|
|
24
25
|
return remove(join(dest, LICENSE));
|
|
25
26
|
}
|
|
26
27
|
// [function]
|
|
27
|
-
//
|
|
28
|
+
// whether degit's failure got no response from GitHub: `git ls-remote`
|
|
29
|
+
// unable to reach it (git says "unable to access" for any failure of the
|
|
30
|
+
// connection), or the archive's download failing as a system error
|
|
31
|
+
// (ENOTFOUND, ECONNRESET), not a status. A repository that isn't there, or
|
|
32
|
+
// isn't public, is git asking for a username, or a 404.
|
|
33
|
+
function unreached(ex) {
|
|
34
|
+
if (!isTable(ex) || !isTable(ex["original"]))
|
|
35
|
+
return false;
|
|
36
|
+
const original = ex["original"];
|
|
37
|
+
if (ex["code"] === "COULD_NOT_FETCH") {
|
|
38
|
+
const said = original["message"];
|
|
39
|
+
return typeof said === "string" && said.includes("unable to access");
|
|
40
|
+
}
|
|
41
|
+
return (ex["code"] === "COULD_NOT_DOWNLOAD" && typeof original["code"] === "string");
|
|
42
|
+
}
|
|
43
|
+
// [function]
|
|
44
|
+
// the template's download failed: api_unreachable where nothing answered,
|
|
45
|
+
// else template_not_found, whose starter's name on its own, such as
|
|
46
|
+
// `blank`, suggests the starter.
|
|
28
47
|
function unavailable(src, cause) {
|
|
48
|
+
if (unreached(cause)) {
|
|
49
|
+
return new ArcError(API_UNREACHABLE, templateUnreachable(src), { cause });
|
|
50
|
+
}
|
|
29
51
|
const starter = choices.find(({ value }) => value.split("/").pop() === src);
|
|
30
|
-
return new ArcError(
|
|
52
|
+
return new ArcError(TEMPLATE_NOT_FOUND, templateNotFound(src, starter?.value), { cause });
|
|
31
53
|
}
|
|
32
54
|
// [function]
|
|
33
55
|
// degit copies nothing, without failing, from a folder a repository doesn't
|
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 { ARGUMENT_INVALID,
|
|
5
|
+
import { ARGUMENT_INVALID, GAME_NOT_FOUND, KEY_QUOTA_FULL, KEY_NOT_FOUND, } from "../../config/code.js";
|
|
6
6
|
import { ArcError } from "../../util/error.js";
|
|
7
7
|
import { channelOf, gameOf, headersOf, isRefused, isStatus, needOf, ownedOf, } from "../game.js";
|
|
8
|
-
import { gameNotOwned,
|
|
8
|
+
import { gameNotOwned, keyQuotaFull, 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(
|
|
39
|
+
throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), {
|
|
40
40
|
cause: err,
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
if (isRefused(err,
|
|
44
|
-
throw new ArcError(
|
|
43
|
+
if (isRefused(err, KEY_QUOTA_FULL, 507)) {
|
|
44
|
+
throw new ArcError(KEY_QUOTA_FULL, keyQuotaFull(where), {
|
|
45
45
|
cause: err,
|
|
46
46
|
});
|
|
47
47
|
}
|
package/dist/action/pack/tool.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { pathExists } from "fs-extra";
|
|
5
5
|
// [import]
|
|
6
6
|
import { BUILT, PACKED } from "../../runner/bundle.js";
|
|
7
|
-
import { DEPLOY_DIR_MISSING, PACKAGE_INDEX_MISSING, PACKAGE_PATH_RESERVED, PACKAGE_TOO_LARGE, PATH_NOT_FOUND, } from "../../config/code.js";
|
|
7
|
+
import { DEPLOY_DIR_MISSING, FUNCTION_NOT_BUILT, PACKAGE_INDEX_MISSING, PACKAGE_PATH_RESERVED, PACKAGE_TOO_LARGE, PATH_NOT_FOUND, } from "../../config/code.js";
|
|
8
8
|
import { ArcError } from "../../util/error.js";
|
|
9
9
|
import { MEDIA, PACKAGED } from "../../config/file.js";
|
|
10
10
|
import { deployDirMissing, packageIndexMissing, packagePathReserved, packageTooLarge, runnerNotBuilt, unableToFind, } from "../../phrase/index.js";
|
|
@@ -142,7 +142,7 @@ function pack(name, game, { deployDir, icon, inputPath, mediaPath, onWarning, ou
|
|
|
142
142
|
// the runner's bundle, as `arc build` wrote it, in the folder every
|
|
143
143
|
// build's origin keeps for Arcadible's own files, which is never served
|
|
144
144
|
if (runner && !built) {
|
|
145
|
-
throw new ArcError(
|
|
145
|
+
throw new ArcError(FUNCTION_NOT_BUILT, runnerNotBuilt());
|
|
146
146
|
}
|
|
147
147
|
if (runner) {
|
|
148
148
|
zip.addFile(runner.built, PACKED);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// [import]
|
|
2
2
|
import { auth, discoverGame, gameBuild, gameHandle } from "../../api.js";
|
|
3
|
-
import { GAME_HANDLE_TAKEN,
|
|
3
|
+
import { GAME_HANDLE_TAKEN, GAME_NOT_FOUND, WARNING, } from "../../config/code.js";
|
|
4
4
|
import { ArcError } from "../../util/error.js";
|
|
5
5
|
import { HttpError } from "../../util/http.js";
|
|
6
|
-
import { gameHandleLapsed, gameHandleLimit, gameHandleTaken,
|
|
6
|
+
import { gameHandleLapsed, gameHandleLimit, gameHandleTaken, gameDeletedOrNotOwned, } from "../../phrase/index.js";
|
|
7
7
|
import { channel } from "../../util/links.js";
|
|
8
8
|
import { refuse } from "./published.js";
|
|
9
9
|
// [function]
|
|
@@ -22,7 +22,7 @@ function ensureOwned(current, id) {
|
|
|
22
22
|
// a token's account isn't known yet; the server checks ownership when
|
|
23
23
|
// it authorizes the upload.
|
|
24
24
|
if (!current?.token && game.account !== current?.user.id) {
|
|
25
|
-
throw new ArcError(
|
|
25
|
+
throw new ArcError(GAME_NOT_FOUND, gameDeletedOrNotOwned(id));
|
|
26
26
|
}
|
|
27
27
|
}, ignoreMissing);
|
|
28
28
|
}
|
|
@@ -46,7 +46,7 @@ function ensureHandle(current, { handle, id, version }, handler) {
|
|
|
46
46
|
throw new ArcError(GAME_HANDLE_TAKEN, gameHandleTaken(handle));
|
|
47
47
|
}
|
|
48
48
|
if (status === "limit") {
|
|
49
|
-
warn(WARNING.
|
|
49
|
+
warn(WARNING.GAME_HANDLE_QUOTA_FULL, gameHandleLimit(handle));
|
|
50
50
|
return true;
|
|
51
51
|
}
|
|
52
52
|
if (status === "lapsed") {
|
|
@@ -3,11 +3,11 @@
|
|
|
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 { ARGUMENT_INVALID,
|
|
6
|
+
import { ARGUMENT_INVALID, GAME_NOT_FOUND, SECRET_QUOTA_FULL, SECRET_NOT_FOUND, SECRET_TOO_LARGE, } from "../../config/code.js";
|
|
7
7
|
import { SECRET_NAME } from "../../config/limit.js";
|
|
8
8
|
import { ArcError } from "../../util/error.js";
|
|
9
9
|
import { channelOf, gameOf, headersOf, isRefused, isStatus, needOf, ownedOf, } from "../game.js";
|
|
10
|
-
import { gameNotOwned,
|
|
10
|
+
import { gameNotOwned, secretQuotaFull, secretNameInvalid, secretNotFound, secretValueInvalid, } from "../../phrase/index.js";
|
|
11
11
|
// [declare]
|
|
12
12
|
const VALUE_MAX = 4096;
|
|
13
13
|
// [function]
|
|
@@ -27,11 +27,12 @@ export async function set(current, { channel, name, value, ...conf }) {
|
|
|
27
27
|
const id = await gameOf(conf);
|
|
28
28
|
const headers = headersOf(current);
|
|
29
29
|
const secret = await value();
|
|
30
|
-
if (typeof secret !== "string" ||
|
|
31
|
-
secret === "" ||
|
|
32
|
-
Buffer.byteLength(secret) > VALUE_MAX) {
|
|
30
|
+
if (typeof secret !== "string" || secret === "") {
|
|
33
31
|
throw new ArcError(ARGUMENT_INVALID, secretValueInvalid());
|
|
34
32
|
}
|
|
33
|
+
if (Buffer.byteLength(secret) > VALUE_MAX) {
|
|
34
|
+
throw new ArcError(SECRET_TOO_LARGE, secretValueInvalid());
|
|
35
|
+
}
|
|
35
36
|
const form = new FormData();
|
|
36
37
|
form.append("value", secret);
|
|
37
38
|
try {
|
|
@@ -40,12 +41,12 @@ export async function set(current, { channel, name, value, ...conf }) {
|
|
|
40
41
|
}
|
|
41
42
|
catch (err) {
|
|
42
43
|
if (isStatus(err, 404)) {
|
|
43
|
-
throw new ArcError(
|
|
44
|
+
throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), {
|
|
44
45
|
cause: err,
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
|
-
if (isRefused(err,
|
|
48
|
-
throw new ArcError(
|
|
48
|
+
if (isRefused(err, SECRET_QUOTA_FULL, 507)) {
|
|
49
|
+
throw new ArcError(SECRET_QUOTA_FULL, secretQuotaFull(where), {
|
|
49
50
|
cause: err,
|
|
50
51
|
});
|
|
51
52
|
}
|
|
@@ -9,7 +9,7 @@ import { setTimeout as sleep } from "node:timers/promises";
|
|
|
9
9
|
// [import]
|
|
10
10
|
import { pathExists } from "fs-extra";
|
|
11
11
|
// [import]
|
|
12
|
-
import { ARGUMENT_INVALID, DEPLOY_DIR_MISSING, PORT_IN_USE, } from "../../config/code.js";
|
|
12
|
+
import { ARGUMENT_INVALID, DEPLOY_DIR_MISSING, PORT_IN_USE, VALIDATION_FAILED, } from "../../config/code.js";
|
|
13
13
|
import { clientNames } from "../../schema/client.js";
|
|
14
14
|
import { buildCommand } from "../../util/command.js";
|
|
15
15
|
import { ArcError } from "../../util/error.js";
|
|
@@ -269,10 +269,10 @@ export async function serveTool(conf) {
|
|
|
269
269
|
};
|
|
270
270
|
}
|
|
271
271
|
// arc serve validates nothing, so a deploy_dir that isn't a path is said
|
|
272
|
-
// as
|
|
272
|
+
// here, as the rule arc validate holds it to
|
|
273
273
|
const dir = project.workflow.deploy_dir;
|
|
274
274
|
if (typeof dir !== "string") {
|
|
275
|
-
throw new ArcError(
|
|
275
|
+
throw new ArcError(VALIDATION_FAILED, phrase.deployDirNotPath(textOf(dir) || "deploy_dir"));
|
|
276
276
|
}
|
|
277
277
|
const built = conf.build !== false && Boolean(buildCommand(project.workflow.build));
|
|
278
278
|
if (built) {
|
|
@@ -6,7 +6,7 @@
|
|
|
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 { ARGUMENT_INVALID,
|
|
9
|
+
import { ARGUMENT_INVALID, GAME_NOT_FOUND, LIMIT_REACHED, PARSE_FAILED, PATH_NOT_FOUND, VALUE_NOT_FOUND, VALUE_STORAGE_QUOTA_FULL, VALUE_TOO_LARGE, } from "../../config/code.js";
|
|
10
10
|
import { ArcError } from "../../util/error.js";
|
|
11
11
|
import { HttpError } from "../../util/http.js";
|
|
12
12
|
import { gameOf, headersOf, isStatus, needOf } from "../game.js";
|
|
@@ -36,7 +36,7 @@ function parsed(text, source) {
|
|
|
36
36
|
return JSON.parse(text);
|
|
37
37
|
}
|
|
38
38
|
catch (err) {
|
|
39
|
-
throw new ArcError(
|
|
39
|
+
throw new ArcError(PARSE_FAILED, valueNotJson(source), { cause: err });
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
// [function]
|
|
@@ -45,7 +45,7 @@ function fileOf(file) {
|
|
|
45
45
|
return fs.readFileSync(file, "utf8");
|
|
46
46
|
}
|
|
47
47
|
catch (err) {
|
|
48
|
-
throw new ArcError(
|
|
48
|
+
throw new ArcError(PATH_NOT_FOUND, valueFileUnread(file), { cause: err });
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
// [function]
|
|
@@ -57,7 +57,7 @@ function folderOf(dir) {
|
|
|
57
57
|
names = fs.readdirSync(dir, { recursive: true });
|
|
58
58
|
}
|
|
59
59
|
catch (err) {
|
|
60
|
-
throw new ArcError(
|
|
60
|
+
throw new ArcError(PATH_NOT_FOUND, valueFileUnread(dir), { cause: err });
|
|
61
61
|
}
|
|
62
62
|
const items = names
|
|
63
63
|
.filter((name) => name.endsWith(FILE))
|
|
@@ -112,12 +112,12 @@ async function holds(id, channel, headers) {
|
|
|
112
112
|
function refused(id, channel, headers) {
|
|
113
113
|
return async (err) => {
|
|
114
114
|
if (isStatus(err, 404)) {
|
|
115
|
-
throw new ArcError(
|
|
115
|
+
throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), {
|
|
116
116
|
cause: err,
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
if (isStatus(err, 507)) {
|
|
120
|
-
throw new ArcError(
|
|
120
|
+
throw new ArcError(VALUE_STORAGE_QUOTA_FULL, valueFull(channel, await holds(id, channel, headers)), { cause: err });
|
|
121
121
|
}
|
|
122
122
|
if (err instanceof HttpError && err.code === LIMIT_REACHED) {
|
|
123
123
|
throw new ArcError(LIMIT_REACHED, valueCallsSpent(), { cause: err });
|
package/dist/action/wire/tool.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// players. What its owner sees of them is their usage: wires keep nothing,
|
|
3
3
|
// and nothing about one is set from here.
|
|
4
4
|
import { gameWireUsages } from "../../api.js";
|
|
5
|
-
import {
|
|
5
|
+
import { GAME_NOT_FOUND } from "../../config/code.js";
|
|
6
6
|
import { ArcError } from "../../util/error.js";
|
|
7
7
|
import { channelOf, CHANNELS, gameOf, headersOf, } from "../game.js";
|
|
8
8
|
import { gameNotOwned } from "../../phrase/index.js";
|
|
@@ -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(
|
|
19
|
+
throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id));
|
|
20
20
|
}
|
|
21
21
|
const today = new Date().toISOString().slice(0, 10);
|
|
22
22
|
const sum = (of) => ({
|
package/dist/api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// [import]
|
|
2
|
-
import {
|
|
2
|
+
import { UNEXPECTED } from "./config/code.js";
|
|
3
3
|
import { ArcError } from "./util/error.js";
|
|
4
4
|
import { answerUnread } from "./phrase/index.js";
|
|
5
5
|
import { del, get, post, postJson, put } from "./util/request.js";
|
|
@@ -144,7 +144,7 @@ const isUsage = shaped({
|
|
|
144
144
|
function answer(is, what, data) {
|
|
145
145
|
return data.then((value) => {
|
|
146
146
|
if (!is(value)) {
|
|
147
|
-
throw new ArcError(
|
|
147
|
+
throw new ArcError(UNEXPECTED, answerUnread(what));
|
|
148
148
|
}
|
|
149
149
|
return value;
|
|
150
150
|
});
|
package/dist/command/init.js
CHANGED
|
@@ -3,7 +3,7 @@ import { resolve } from "node:path";
|
|
|
3
3
|
// [import]
|
|
4
4
|
import fs from "fs-extra";
|
|
5
5
|
// [import]
|
|
6
|
-
import {
|
|
6
|
+
import { ARGUMENT_INVALID } from "../config/code.js";
|
|
7
7
|
import { defineCommand } from "../cli/command.js";
|
|
8
8
|
import { ArcError } from "../util/error.js";
|
|
9
9
|
import { initialized, initializedNoStarter, templateMissing, } from "../phrase/index.js";
|
|
@@ -39,7 +39,7 @@ async function prompt({ cwd, project, template, yes, }) {
|
|
|
39
39
|
if (!template) {
|
|
40
40
|
// without a terminal, the prompt would read end-of-input and exit.
|
|
41
41
|
if (!process.stdin.isTTY) {
|
|
42
|
-
throw new ArcError(
|
|
42
|
+
throw new ArcError(ARGUMENT_INVALID, templateMissing());
|
|
43
43
|
}
|
|
44
44
|
const answer = await select({
|
|
45
45
|
choices,
|