arcadible 1.0.41 → 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.
Files changed (44) hide show
  1. package/dist/action/delete/tool.js +2 -2
  2. package/dist/action/deploy/tool.js +5 -5
  3. package/dist/action/function/logs.js +100 -30
  4. package/dist/action/function/tool.js +10 -8
  5. package/dist/action/game.js +15 -3
  6. package/dist/action/init/tool.js +26 -4
  7. package/dist/action/key/tool.js +21 -12
  8. package/dist/action/pack/tool.js +2 -2
  9. package/dist/action/predeploy/ac.js +4 -4
  10. package/dist/action/secret/tool.js +11 -9
  11. package/dist/action/serve/tool.js +3 -3
  12. package/dist/action/value/tool.js +14 -8
  13. package/dist/action/wire/tool.js +2 -2
  14. package/dist/api.js +2 -2
  15. package/dist/command/init.js +2 -2
  16. package/dist/command/open.js +1 -1
  17. package/dist/command/play.js +1 -1
  18. package/dist/config/code.js +29 -24
  19. package/dist/config/retry.js +105 -0
  20. package/dist/phrase/common.js +5 -2
  21. package/dist/phrase/deploy.js +2 -2
  22. package/dist/phrase/function.js +3 -3
  23. package/dist/phrase/game.js +1 -1
  24. package/dist/phrase/init.js +7 -1
  25. package/dist/phrase/pack.js +6 -1
  26. package/dist/phrase/server.js +1 -1
  27. package/dist/phrase/value.js +6 -0
  28. package/dist/runner/bundle.js +2 -2
  29. package/dist/runner/outbound.js +2 -0
  30. package/dist/schema/game.js +1 -1
  31. package/dist/serve/message.js +79 -0
  32. package/dist/serve/page.js +70 -60
  33. package/dist/serve/retry.js +4 -8
  34. package/dist/serve/runner.js +15 -6
  35. package/dist/serve/ticket.js +5 -5
  36. package/dist/serve/wires.js +10 -6
  37. package/dist/util/error.js +28 -8
  38. package/dist/util/http.js +6 -2
  39. package/dist/util/output.js +54 -16
  40. package/dist/util/request.js +2 -1
  41. package/dist/util/s3.js +1 -1
  42. package/dist/wires/room.js +30 -37
  43. package/npm-shrinkwrap.json +67 -67
  44. 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, GAME_UNAVAILABLE } from "../../config/code.js";
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(GAME_UNAVAILABLE, gameNotOwned(id), {
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, GAME_UNAVAILABLE } from "../../config/code.js";
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, gameUnavailable } from "../../phrase/index.js";
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
- // (403), and the same version deployed again within 5 minutes (429),
23
+ // (404), and the same version deployed again within 5 minutes (429),
24
24
  // each by its code.
25
- if (isRefused(err, GAME_UNAVAILABLE, 403)) {
26
- throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
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 { API_REFUSED, API_UNREACHABLE, ARGUMENT_INVALID, GAME_UNAVAILABLE, INTERNAL, } from "../../config/code.js";
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, functionLogsBusy, functionLogsRefused, functionLogsSinceInvalid, functionLogsVersionInvalid, gameNotOwned, unableToReach, } from "../../phrase/index.js";
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: Arcadible's side (a 5xx) is
85
- // internal, and anything else api_refused, never a 401 that would end the
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, code) {
88
- return new ArcError(status >= 500 ? INTERNAL : API_REFUSED, functionLogsRefused({ code, status }));
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
- // game_unavailable, as for the rest of `arc unstable function`.
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(GAME_UNAVAILABLE, gameNotOwned(id), { cause: err });
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
- async function pageOf(token, query) {
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 code = isTable(body) && typeof body["code"] === "string" ? body["code"] : null;
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
- throw refused(res.status, code);
172
+ }
173
+ throw refused(res.status, told);
129
174
  }
130
175
  if (!isPage(body)) {
131
- throw new ArcError(INTERNAL, answerUnread("a function's logs"));
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
- req.destroy();
173
- res.resume();
174
- end(res.statusCode ?? 500);
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; one the Worker refuses ends the command, and so
206
- // does one that can't be opened five times in a row.
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
- if (closed.status === 429)
229
- throw new ArcError(API_REFUSED, functionLogsBusy());
230
- if (closed.status && closed.status < 500 && closed.status !== 401) {
231
- throw refused(closed.status, null);
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,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 { FUNCTION_PAUSE_RESERVED, GAME_UNAVAILABLE, } from "../../config/code.js";
6
+ import { FUNCTION_PAUSE_NOT_OWNED, GAME_NOT_FOUND } from "../../config/code.js";
7
7
  import { ArcError } from "../../util/error.js";
8
- import { channelOf, CHANNELS, gameOf, headersOf, isStatus, needOf, } from "../game.js";
9
- import { functionPauseReserved, gameNotOwned } from "../../phrase/index.js";
8
+ import { channelOf, CHANNELS, gameOf, headersOf, isStatus, needOf, ownedOf, } from "../game.js";
9
+ import { functionPauseNotOwned, 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.
@@ -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(GAME_UNAVAILABLE, gameNotOwned(id), {
65
+ throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), {
66
66
  cause: err,
67
67
  });
68
68
  }
@@ -74,11 +74,12 @@ export async function pause(current, { channel, ...conf }) {
74
74
  // resolves with `{ channel, lifted, paused }`, `paused` the reason it's
75
75
  // still paused for, or null. One that isn't paused stays as it was, as `pause` leaves one
76
76
  // that's paused already. A pause of Arcadible's, or a limit's, isn't
77
- // its owner's to lift: function_pause_reserved, saying who lifts it.
77
+ // its owner's to lift: function_pause_not_owned, saying who lifts it.
78
78
  export async function resume(current, { channel, ...conf }) {
79
79
  const where = needOf(channel);
80
80
  const id = await gameOf(conf);
81
81
  const headers = headersOf(current);
82
+ await ownedOf(id, headers);
82
83
  let lifted = true;
83
84
  try {
84
85
  await deleteGameFunctionPause(id, where, null, headers);
@@ -91,7 +92,7 @@ export async function resume(current, { channel, ...conf }) {
91
92
  }
92
93
  const paused = pausedOf(await gameFunctionPauses(id, null, headers), where);
93
94
  if (!lifted && paused) {
94
- throw new ArcError(FUNCTION_PAUSE_RESERVED, functionPauseReserved({ channel: where, paused }));
95
+ throw new ArcError(FUNCTION_PAUSE_NOT_OWNED, functionPauseNotOwned({ channel: where, paused }));
95
96
  }
96
97
  return { channel: where, lifted, paused };
97
98
  }
@@ -107,13 +108,14 @@ export async function status(current, { channel, ...conf }) {
107
108
  const where = channelOf(channel);
108
109
  const id = await gameOf(conf);
109
110
  const headers = headersOf(current);
111
+ await ownedOf(id, headers);
110
112
  const [pauses, usages] = await Promise.all([
111
113
  gameFunctionPauses(id, null, headers),
112
114
  gameFunctionUsages(id, null, headers),
113
115
  ]);
114
116
  const shown = CHANNELS.filter((each) => !where || each === where);
115
- // asked once the owner's reads have answered, so another account's game
116
- // is refused before anything else is asked about it.
117
+ // asked once the game is known to be the caller's, so another account's
118
+ // game is refused before anything else is asked about it.
117
119
  const has = await Promise.all(shown.map((each) => hasFunction(id, each)));
118
120
  const rows = usages ?? [];
119
121
  const [first] = rows;
@@ -2,12 +2,12 @@
2
2
  // function's secrets, its server's keys): the project's game, the channel a
3
3
  // command names, the session's headers, and telling the API's refusals
4
4
  // apart.
5
- import { auth } from "../api.js";
6
- import { ALL, ARGUMENT_INVALID, GAME_ID_MISSING, NOT_LOGGED_IN, } from "../config/code.js";
5
+ import { auth, gameWireUsages } from "../api.js";
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";
10
- import { channelInvalid, gameIdMissing, notLoggedIn } from "../phrase/index.js";
10
+ import { channelInvalid, gameIdMissing, gameNotOwned, notLoggedIn, } from "../phrase/index.js";
11
11
  import { textOf } from "../util/objs.js";
12
12
  // [declare]
13
13
  export const CHANNELS = ["production", "staging"];
@@ -56,6 +56,18 @@ export function headersOf(current) {
56
56
  return auth(current.session.access_token);
57
57
  }
58
58
  // [function]
59
+ // that the game is the caller's, asked before a read the API answers as
60
+ // none for another account's game (its keys, its function's secrets,
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, game_not_found,
63
+ // as `arc unstable wire usage` says.
64
+ export async function ownedOf(id, headers) {
65
+ const rows = await gameWireUsages(id, null, headers);
66
+ if (!rows?.length) {
67
+ throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id));
68
+ }
69
+ }
70
+ // [function]
59
71
  // whether a failure is the API's refusal with this status.
60
72
  export function isStatus(err, status) {
61
73
  return err instanceof HttpError && err.status === status;
@@ -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 { TEMPLATE_UNAVAILABLE } from "../../config/code.js";
7
+ import { API_UNREACHABLE, TEMPLATE_NOT_FOUND } from "../../config/code.js";
8
8
  import { ArcError } from "../../util/error.js";
9
- import { templateUnavailable } from "../../phrase/index.js";
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
- // a starter's name on its own, such as `blank`, suggests the starter.
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(TEMPLATE_UNAVAILABLE, templateUnavailable(src, starter?.value), { cause });
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
@@ -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, GAME_UNAVAILABLE, KEY_LIMIT_REACHED, KEY_NOT_FOUND, } from "../../config/code.js";
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
- import { channelOf, gameOf, headersOf, isRefused, isStatus, needOf, } from "../game.js";
8
- import { gameNotOwned, keyLimitReached, keyNameInvalid, keyNotFound, } from "../../phrase/index.js";
7
+ import { channelOf, gameOf, headersOf, isRefused, isStatus, needOf, ownedOf, } from "../game.js";
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(GAME_UNAVAILABLE, gameNotOwned(id), {
39
+ throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), {
40
40
  cause: err,
41
41
  });
42
42
  }
43
- if (isRefused(err, KEY_LIMIT_REACHED, 409)) {
44
- throw new ArcError(KEY_LIMIT_REACHED, keyLimitReached(where), {
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
  }
@@ -54,7 +54,9 @@ export async function create(current, { channel, name, ...conf }) {
54
54
  export async function list(current, { channel, ...conf }) {
55
55
  const where = channelOf(channel);
56
56
  const id = await gameOf(conf);
57
- const keys = await gameKeys(id, null, headersOf(current));
57
+ const headers = headersOf(current);
58
+ await ownedOf(id, headers);
59
+ const keys = await gameKeys(id, null, headers);
58
60
  return (keys ?? [])
59
61
  .filter((key) => !where || key.channel === where)
60
62
  .map((key) => ({
@@ -68,13 +70,20 @@ export async function list(current, { channel, ...conf }) {
68
70
  }
69
71
  // [function]
70
72
  // 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.
73
+ // already, isn't the project's game's, or isn't an id at all is the same to
74
+ // its owner: not found. A key is addressed by its own id, which the API
75
+ // checks is the account's, so it's looked for among the game's live keys
76
+ // first: another of the account's games keeps its own.
74
77
  export async function revoke(current, { id, ...conf }) {
75
- await gameOf(conf);
78
+ const game = await gameOf(conf);
79
+ const headers = headersOf(current);
80
+ await ownedOf(game, headers);
81
+ const keys = await gameKeys(game, null, headers);
82
+ if (!(keys ?? []).some((key) => key.id === id)) {
83
+ throw new ArcError(KEY_NOT_FOUND, keyNotFound(id));
84
+ }
76
85
  try {
77
- const gone = await deleteKey(id, null, headersOf(current));
86
+ const gone = await deleteKey(id, null, headers);
78
87
  return { id: gone.id };
79
88
  }
80
89
  catch (err) {
@@ -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(PATH_NOT_FOUND, runnerNotBuilt());
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, GAME_UNAVAILABLE, WARNING, } from "../../config/code.js";
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, gameUnavailable, } from "../../phrase/index.js";
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(GAME_UNAVAILABLE, gameUnavailable(id));
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.GAME_HANDLE_LIMIT_REACHED, gameHandleLimit(handle));
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, GAME_UNAVAILABLE, SECRET_LIMIT_REACHED, SECRET_NOT_FOUND, } from "../../config/code.js";
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
- import { channelOf, gameOf, headersOf, isRefused, isStatus, needOf, } from "../game.js";
10
- import { gameNotOwned, secretLimitReached, secretNameInvalid, secretNotFound, secretValueInvalid, } from "../../phrase/index.js";
9
+ import { channelOf, gameOf, headersOf, isRefused, isStatus, needOf, ownedOf, } from "../game.js";
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(GAME_UNAVAILABLE, gameNotOwned(id), {
44
+ throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), {
44
45
  cause: err,
45
46
  });
46
47
  }
47
- if (isRefused(err, SECRET_LIMIT_REACHED, 409)) {
48
- throw new ArcError(SECRET_LIMIT_REACHED, secretLimitReached(where), {
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
  }
@@ -59,6 +60,7 @@ export async function list(current, { channel, ...conf }) {
59
60
  const where = channelOf(channel);
60
61
  const id = await gameOf(conf);
61
62
  const headers = headersOf(current);
63
+ await ownedOf(id, headers);
62
64
  const secrets = await gameFunctionSecrets(id, null, headers);
63
65
  return (secrets ?? [])
64
66
  .filter((secret) => !where || secret.channel === where)
@@ -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 what it is, a folder that isn't there
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(DEPLOY_DIR_MISSING, phrase.deployDirMissing(textOf(dir) || "deploy_dir"));
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) {