arcadible 1.0.45 → 1.0.47

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.
@@ -1,24 +1,34 @@
1
1
  // [import]
2
2
  import { authed, ended } from "../../account.js";
3
- import { discoverGameReleases, release as apiRelease, } from "../../api.js";
3
+ import { discoverReleases, release as apiRelease, } from "../../api.js";
4
4
  import { sleep } from "../../util/delay.js";
5
5
  import { git } from "../predeploy/git.js";
6
6
  import { HttpError } from "../../util/http.js";
7
+ import { isRetry } from "../../config/retry.js";
7
8
  import { studioUrl } from "../../util/links.js";
8
9
  import { m, s } from "../../util/time.js";
9
10
  // [declare]
10
11
  // how often a release is checked.
11
12
  const INTERVAL = s(2);
12
13
  const FINAL = new Set(["failed", "published"]);
14
+ // `reason` brings its `retry` with it: the API answers one beside each
15
+ // (its app/release.py).
13
16
  const SELECT = "id,game,status,reason,message,build,source,version,channel,created_at";
14
17
  // a git release is found by version among the newest few; one from before
15
18
  // this deploy (a tag deleted and pushed again) is left out, allowing for
16
19
  // the machine's clock being off.
17
20
  const SKEW = m(10);
18
21
  // [function]
19
- // a failure worth retrying: the network, or the API having a moment.
22
+ // a failure worth waiting through: the network, or a refusal Arcadible says
23
+ // to try again after a moment, by its retry (`yes`: `unavailable`,
24
+ // `internal`, `busy`), whatever its status; an answer that says none isn't
25
+ // Arcadible's own (a front end's page), and is waited through for a 5xx
26
+ // (ERRORS.md, Passing a code on). Anything else ends the wait.
20
27
  function transient(err) {
21
- return !(err instanceof HttpError) || !err.status || err.status >= 500;
28
+ if (!(err instanceof HttpError)) {
29
+ return true;
30
+ }
31
+ return isRetry(err.retry) ? err.retry === "yes" : err.status >= 500;
22
32
  }
23
33
  // [function]
24
34
  // the repository's GitHub Actions page, from origin's URL, or null when
@@ -45,7 +55,7 @@ function findDirect(id, current) {
45
55
  // what's true for whoever runs it. A release with no game (a repository that
46
56
  // isn't connected, which the predeploy refuses first) isn't among them.
47
57
  function findGit({ game, since, version, }) {
48
- return () => discoverGameReleases(game, { limit: 10, select: SELECT, version }).then((rows) => (rows ?? []).find((r) => r.source === "github" &&
58
+ return () => discoverReleases(game, { limit: 10, select: SELECT, version }).then((rows) => (rows ?? []).find((r) => r.source === "github" &&
49
59
  r.version === version &&
50
60
  r.game === game &&
51
61
  Date.parse(r.created_at ?? "") >= since - SKEW) ?? null);
@@ -9,6 +9,7 @@ import { postGameFunctionLogsToken } from "../../api.js";
9
9
  import { API_UNREACHABLE, ARGUMENT_INVALID, FUNCTION_LOGS_FOLLOWS_FULL, GAME_NOT_FOUND, UNAVAILABLE, UNEXPECTED, } from "../../config/code.js";
10
10
  import { ArcError, codeOf } from "../../util/error.js";
11
11
  import { HttpError } from "../../util/http.js";
12
+ import { isRetry } from "../../config/retry.js";
12
13
  import { sleep } from "../../util/delay.js";
13
14
  import { isTable } from "../../util/objs.js";
14
15
  import { channelOf, gameOf, headersOf, isRefused, REFUSED } from "../game.js";
@@ -285,9 +286,12 @@ export async function follow(current, { channel, ...conf }, shown) {
285
286
  query.delete("since");
286
287
  for (let failed = 0;;) {
287
288
  const closed = await followOnce(await tokenOf(id, headers), query, once);
288
- const { code, status } = closed;
289
- // read by the Worker's code alone, as a page is (`pageOf`): a bare 401
290
- // is refused as any other 4xx, and a bare 507 tried again as a 5xx
289
+ const { code, retry, status } = closed;
290
+ // read by the Worker's code and its retry, as a page is (`pageOf`) and
291
+ // as Studio's follow is (ui's `isFinal`): a sixth follow has its own
292
+ // code, and any other refusal ends the follow only when its retry is
293
+ // No. One that says no retry isn't the Worker's own (a front end's): it
294
+ // ends the follow for a 4xx, and is tried again for a 5xx
291
295
  if (code === "full") {
292
296
  throw new ArcError(FUNCTION_LOGS_FOLLOWS_FULL, functionLogsFull(), {
293
297
  cause: httpErrorOf(status ?? 507, closed),
@@ -295,7 +299,7 @@ export async function follow(current, { channel, ...conf }, shown) {
295
299
  });
296
300
  }
297
301
  const expired = code === "expired";
298
- if (status && status < 500 && !expired) {
302
+ if (status && (isRetry(retry) ? retry === "no" : status < 500)) {
299
303
  throw refused(status, closed);
300
304
  }
301
305
  failed = closed.opened ? 0 : failed + 1;
@@ -5,7 +5,7 @@
5
5
  import { deleteGameFunctionPause, discoverGameBuilds, gameFunctionPauses, gameFunctionUsages, putGameFunctionPause, } from "../../api.js";
6
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, isRefused, REFUSED, needOf, ownedOf, } from "../game.js";
8
+ import { channelOf, CHANNELS, gameOf, headersOf, isRefused, REFUSED, needOf, ownedRead, } from "../game.js";
9
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:
@@ -79,7 +79,6 @@ 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);
83
82
  let lifted = true;
84
83
  try {
85
84
  await deleteGameFunctionPause(id, where, null, headers);
@@ -90,7 +89,8 @@ export async function resume(current, { channel, ...conf }) {
90
89
  }
91
90
  lifted = false;
92
91
  }
93
- const paused = pausedOf(await gameFunctionPauses(id, null, headers), where);
92
+ // a 404 here, after the delete's, is a game that isn't the caller's
93
+ const paused = pausedOf(await ownedRead(id, gameFunctionPauses(id, null, headers)), where);
94
94
  if (!lifted && paused) {
95
95
  throw new ArcError(FUNCTION_PAUSE_NOT_OWNED, functionPauseNotOwned({ channel: where, paused }));
96
96
  }
@@ -108,10 +108,9 @@ export async function status(current, { channel, ...conf }) {
108
108
  const where = channelOf(channel);
109
109
  const id = await gameOf(conf);
110
110
  const headers = headersOf(current);
111
- await ownedOf(id, headers);
112
111
  const [pauses, usages] = await Promise.all([
113
- gameFunctionPauses(id, null, headers),
114
- gameFunctionUsages(id, null, headers),
112
+ ownedRead(id, gameFunctionPauses(id, null, headers)),
113
+ ownedRead(id, gameFunctionUsages(id, null, headers)),
115
114
  ]);
116
115
  const shown = CHANNELS.filter((each) => !where || each === where);
117
116
  // asked once the game is known to be the caller's, so another account's
@@ -2,7 +2,7 @@
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, gameWireUsages } from "../api.js";
5
+ import { auth } from "../api.js";
6
6
  import { 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";
@@ -55,18 +55,6 @@ export function headersOf(current) {
55
55
  }
56
56
  return auth(current.session.access_token);
57
57
  }
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
58
  // [declare]
71
59
  // the API's own words for a refusal the CLI reads (ERRORS.md, The
72
60
  // vocabulary), each said by a command in one of its own codes.
@@ -87,3 +75,18 @@ export const REFUSED = {
87
75
  export function isRefused(err, code) {
88
76
  return err instanceof HttpError && err.code === code;
89
77
  }
78
+ // [function]
79
+ // a read of the game's own things (its keys, its function's secrets,
80
+ // pauses, and usage, its wires' usage), whose `not_found` is the game:
81
+ // never deployed, deleted, or another account's, game_not_found.
82
+ export async function ownedRead(id, read) {
83
+ try {
84
+ return await read;
85
+ }
86
+ catch (err) {
87
+ if (isRefused(err, REFUSED.NOT_FOUND)) {
88
+ throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id), { cause: err });
89
+ }
90
+ throw err;
91
+ }
92
+ }
@@ -4,7 +4,7 @@
4
4
  import { deleteKey, gameKeys, postGameKey, } from "../../api.js";
5
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, REFUSED, needOf, ownedOf, } from "../game.js";
7
+ import { channelOf, gameOf, headersOf, isRefused, REFUSED, needOf, ownedRead, } from "../game.js";
8
8
  import { gameNotOwned, keyQuotaFull, keyNameInvalid, keyNotFound, } from "../../phrase/index.js";
9
9
  // [declare]
10
10
  const NAME_MAX = 64;
@@ -55,8 +55,7 @@ export async function list(current, { channel, ...conf }) {
55
55
  const where = channelOf(channel);
56
56
  const id = await gameOf(conf);
57
57
  const headers = headersOf(current);
58
- await ownedOf(id, headers);
59
- const keys = await gameKeys(id, null, headers);
58
+ const keys = await ownedRead(id, gameKeys(id, null, headers));
60
59
  return (keys ?? [])
61
60
  .filter((key) => !where || key.channel === where)
62
61
  .map((key) => ({
@@ -77,8 +76,7 @@ export async function list(current, { channel, ...conf }) {
77
76
  export async function revoke(current, { id, ...conf }) {
78
77
  const game = await gameOf(conf);
79
78
  const headers = headersOf(current);
80
- await ownedOf(game, headers);
81
- const keys = await gameKeys(game, null, headers);
79
+ const keys = await ownedRead(game, gameKeys(game, null, headers));
82
80
  if (!(keys ?? []).some((key) => key.id === id)) {
83
81
  throw new ArcError(KEY_NOT_FOUND, keyNotFound(id));
84
82
  }
@@ -2,14 +2,16 @@
2
2
  import { auth, discoverGame, gameBuild, gameHandle } from "../../api.js";
3
3
  import { GAME_HANDLE_TAKEN, GAME_NOT_FOUND, WARNING, } from "../../config/code.js";
4
4
  import { ArcError } from "../../util/error.js";
5
- import { HttpError } from "../../util/http.js";
5
+ import { isRefused, REFUSED } from "../game.js";
6
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]
10
- // a lookup's failure, passed over when it's a 404: nothing there to refuse.
10
+ // a lookup's failure, passed over when the API says there's nothing there
11
+ // (`not_found`, by its code): nothing to refuse. An answer that names no
12
+ // code isn't the API's, and stands as the failure it is.
11
13
  function ignoreMissing(err) {
12
- if (!(err instanceof HttpError) || err.status !== 404) {
14
+ if (!isRefused(err, REFUSED.NOT_FOUND)) {
13
15
  throw err;
14
16
  }
15
17
  }
@@ -6,7 +6,7 @@ import { deleteGameFunctionSecret, gameFunctionSecrets, putGameFunctionSecret, }
6
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, REFUSED, needOf, ownedOf, } from "../game.js";
9
+ import { channelOf, gameOf, headersOf, isRefused, REFUSED, needOf, ownedRead, } from "../game.js";
10
10
  import { gameNotOwned, secretQuotaFull, secretNameInvalid, secretNotFound, secretTooLarge, secretValueInvalid, } from "../../phrase/index.js";
11
11
  // [declare]
12
12
  const VALUE_MAX = 4096;
@@ -60,8 +60,7 @@ export async function list(current, { channel, ...conf }) {
60
60
  const where = channelOf(channel);
61
61
  const id = await gameOf(conf);
62
62
  const headers = headersOf(current);
63
- await ownedOf(id, headers);
64
- const secrets = await gameFunctionSecrets(id, null, headers);
63
+ const secrets = await ownedRead(id, gameFunctionSecrets(id, null, headers));
65
64
  return (secrets ?? [])
66
65
  .filter((secret) => !where || secret.channel === where)
67
66
  .map((secret) => ({
@@ -2,22 +2,14 @@
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 { GAME_NOT_FOUND } from "../../config/code.js";
6
- import { ArcError } from "../../util/error.js";
7
- import { channelOf, CHANNELS, gameOf, headersOf, } from "../game.js";
8
- import { gameNotOwned } from "../../phrase/index.js";
5
+ import { channelOf, CHANNELS, gameOf, headersOf, ownedRead, } from "../game.js";
9
6
  // [function]
10
7
  // what the game's wires carried on each channel, or on one: this month's,
11
8
  // and today's of it.
12
9
  export async function usage(current, { channel, ...conf }) {
13
10
  const where = channelOf(channel);
14
11
  const id = await gameOf(conf);
15
- const rows = (await gameWireUsages(id, null, headersOf(current))) ?? [];
16
- // its owner always reads today's row for each channel: no rows at all is
17
- // a game that isn't the caller's
18
- if (rows.length === 0) {
19
- throw new ArcError(GAME_NOT_FOUND, gameNotOwned(id));
20
- }
12
+ const rows = (await ownedRead(id, gameWireUsages(id, null, headersOf(current)))) ?? [];
21
13
  const today = new Date().toISOString().slice(0, 10);
22
14
  const sum = (of) => ({
23
15
  connections: of.reduce((total, each) => total + Number(each.connections ?? 0), 0),
package/dist/api.js CHANGED
@@ -42,6 +42,7 @@ const isRelease = shaped({
42
42
  id: opt(str),
43
43
  message: opt(nul(str)),
44
44
  reason: opt(nul(str)),
45
+ retry: opt(nul(str)),
45
46
  source: opt(str),
46
47
  status: opt(str),
47
48
  version: opt(str),
@@ -209,8 +210,10 @@ export function discoverGameBuild(id, version, params, headers) {
209
210
  }
210
211
  // [function]
211
212
  // a game's releases, which anyone can read: what each says about itself.
212
- export function discoverGameReleases(id, params, headers) {
213
- return answer(listed(isRelease), "a game's releases", get(endpoint(pathOf `/discover/games/${id}/releases`, params), headers));
213
+ // The game is a filter, not a path (`?game=`): a release comes before its
214
+ // game, which its first release makes.
215
+ export function discoverReleases(game, params, headers) {
216
+ return answer(listed(isRelease), "a game's releases", get(endpoint("/discover/releases", { ...params, game }), headers));
214
217
  }
215
218
  // [function]
216
219
  // the game's connected repository, if it's `owner/name`; otherwise 404.
@@ -120,6 +120,8 @@ export async function waitAndReport(current, deployed, result, { git, json, quie
120
120
  code: release.reason ?? INTERNAL,
121
121
  data,
122
122
  json,
123
+ // the API's own retry for the reason, said beside it
124
+ retry: release.reason ? release.retry : null,
123
125
  sw,
124
126
  });
125
127
  return;
@@ -72,9 +72,11 @@ export function exit(code) {
72
72
  // only where the code is a catch-all's (`api_refused`, `unavailable`,
73
73
  // `internal`) and what it caught was another code does that go with it as
74
74
  // `cause`, the code and the retry it was told, so the condition isn't lost
75
- // (ERRORS.md, Passing a code on). `code` is a failed release's reason,
76
- // whose retry is its own.
77
- export function errorOf(ex, code) {
75
+ // (ERRORS.md, Passing a code on). `code` is a failed release's reason, and
76
+ // `retry` what the API said beside it, which is passed on as it came, so a
77
+ // reason added since this CLI was built still says its own next step; a
78
+ // release read without one says the reason's own (config/retry.ts).
79
+ export function errorOf(ex, code, retry) {
78
80
  const shown = code ?? codeOf(ex);
79
81
  const told = toldOf(ex);
80
82
  const cause = !code &&
@@ -83,9 +85,11 @@ export function errorOf(ex, code) {
83
85
  told.code !== shown
84
86
  ? told
85
87
  : null;
86
- const said = !code && (told?.code === shown || shown === API_REFUSED)
87
- ? told?.retry
88
- : undefined;
88
+ let said = retry;
89
+ if (!code) {
90
+ said =
91
+ told?.code === shown || shown === API_REFUSED ? told?.retry : undefined;
92
+ }
89
93
  return {
90
94
  ...(cause
91
95
  ? {
@@ -110,11 +114,11 @@ export function errorOf(ex, code) {
110
114
  // release that failed. `nl` puts a blank line before the heading, after
111
115
  // output the command has already printed, such as arc login's link.
112
116
  // `code` is a failed release's reason, which the API may add to, so it isn't
113
- // checked.
114
- export function abort(heading, ex, { code, data, json = false, nl = false, pb, sw } = {}) {
117
+ // checked, and `retry` the API's own word beside it.
118
+ export function abort(heading, ex, { code, data, json = false, nl = false, pb, retry, sw } = {}) {
115
119
  const shown = code ?? codeOf(ex);
116
120
  if (json) {
117
- print({ ...ex.data, ...data, error: errorOf(ex, code) });
121
+ print({ ...ex.data, ...data, error: errorOf(ex, code, retry) });
118
122
  }
119
123
  else {
120
124
  if (pb) {
@@ -28,9 +28,10 @@ function dataOf(body) {
28
28
  return (isTable(body) ? body["data"] : null) ?? null;
29
29
  }
30
30
  // [function]
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.
31
+ // an error's code, retry, title, and message, from the response's status
32
+ // text and the API's own `{ code, message, retry, title }`, which takes
33
+ // precedence when it's there. Each is a string, or left out: an answer that
34
+ // isn't the API's own (a proxy's page) has none.
34
35
  function errorOf(statusText, data) {
35
36
  const all = {
36
37
  title: statusText,
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@eslint/js": "10.0.1",
35
- "@types/node": "25.9.9",
35
+ "@types/node": "25.9.12",
36
36
  "eslint": "10.15.0",
37
37
  "typescript": "5.9.3",
38
38
  "typescript-eslint": "8.74.0"
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "license": "Apache-2.0",
44
44
  "name": "arcadible",
45
- "version": "1.0.45"
45
+ "version": "1.0.47"
46
46
  },
47
47
  "node_modules/@cacheable/memory": {
48
48
  "dependencies": {
@@ -735,10 +735,10 @@
735
735
  "undici-types": ">=7.24.0 <7.24.7"
736
736
  },
737
737
  "dev": true,
738
- "integrity": "sha512-b4e2xxj/yMeT2hNlD6x7zNFiQK2Dlmkb9CQ6v3/1G2RezKN4YS2lcEv8lzGm1mhs4f2lM4yNAMI/zUDBZBBt7w==",
738
+ "integrity": "sha512-49uWGmIcvfuuEnFIm83Pn7MGcDvdY8UQ3v3DF4O0ouWbElWTaT/HudacSntQwFrnLAgiMoKtXEVV5dFC+DZ2cQ==",
739
739
  "license": "MIT",
740
- "resolved": "https://registry.npmjs.org/@types/node/-/node-25.9.9.tgz",
741
- "version": "25.9.9"
740
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-25.9.12.tgz",
741
+ "version": "25.9.12"
742
742
  },
743
743
  "node_modules/@typescript-eslint/eslint-plugin": {
744
744
  "dependencies": {
@@ -2433,5 +2433,5 @@
2433
2433
  }
2434
2434
  },
2435
2435
  "requires": true,
2436
- "version": "1.0.45"
2436
+ "version": "1.0.47"
2437
2437
  }
package/package.json CHANGED
@@ -30,7 +30,7 @@
30
30
  "description": "Create, validate, package, and publish games on Arcadible.",
31
31
  "devDependencies": {
32
32
  "@eslint/js": "10.0.1",
33
- "@types/node": "25.9.9",
33
+ "@types/node": "25.9.12",
34
34
  "eslint": "10.15.0",
35
35
  "typescript": "5.9.3",
36
36
  "typescript-eslint": "8.74.0"
@@ -66,5 +66,5 @@
66
66
  "test": "tsc && npm run lint && node --test \"test/**/*.test.js\" \"test/**/*.test.mjs\""
67
67
  },
68
68
  "type": "module",
69
- "version": "1.0.45"
69
+ "version": "1.0.47"
70
70
  }