arcadible 1.0.23 → 1.0.24

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 (308) hide show
  1. package/README.md +1 -0
  2. package/bin/arc.js +1 -85
  3. package/dist/account.js +197 -0
  4. package/dist/action/build/tool.js +65 -0
  5. package/dist/action/delete/tool.js +46 -0
  6. package/dist/action/deploy/rebuilt.js +25 -0
  7. package/dist/action/deploy/result.js +36 -0
  8. package/dist/action/deploy/timeout.js +18 -0
  9. package/dist/action/deploy/tool-git.js +54 -0
  10. package/dist/action/deploy/tool.js +54 -0
  11. package/dist/action/deploy/wait.js +104 -0
  12. package/dist/action/function/tool.js +127 -0
  13. package/dist/action/game.js +61 -0
  14. package/dist/action/init/manifest.js +64 -0
  15. package/dist/action/init/tool-patch.js +15 -0
  16. package/dist/action/init/tool.js +64 -0
  17. package/dist/action/inspect/tool.js +13 -0
  18. package/dist/action/key/tool.js +87 -0
  19. package/dist/action/login/flow.js +69 -0
  20. package/dist/action/login/tool.js +8 -0
  21. package/dist/action/logout/tool.js +8 -0
  22. package/dist/action/open/tool.js +29 -0
  23. package/dist/action/pack/limits.js +46 -0
  24. package/dist/action/pack/tool.js +150 -0
  25. package/dist/action/pack/unsound.js +51 -0
  26. package/dist/action/play/tool.js +83 -0
  27. package/dist/action/predeploy/ac.js +75 -0
  28. package/dist/action/predeploy/game.js +12 -0
  29. package/dist/action/predeploy/git.js +151 -0
  30. package/dist/action/predeploy/pm.js +20 -0
  31. package/dist/action/predeploy/published.js +54 -0
  32. package/dist/action/predeploy/secrets.js +35 -0
  33. package/dist/action/predeploy/tool-git.js +108 -0
  34. package/dist/action/predeploy/tool.js +16 -0
  35. package/dist/action/secret/tool.js +91 -0
  36. package/dist/action/serve/tool.js +249 -0
  37. package/dist/action/validate/checked.js +28 -0
  38. package/dist/action/validate/tool.js +56 -0
  39. package/dist/action/validate/unknown.js +58 -0
  40. package/dist/action/validate/unsound.js +99 -0
  41. package/dist/action/whoami/tool.js +7 -0
  42. package/dist/api.js +160 -0
  43. package/dist/arc.js +41 -0
  44. package/dist/cli/argv.js +61 -0
  45. package/dist/cli/channel.js +29 -0
  46. package/dist/cli/command.js +163 -0
  47. package/dist/cli/confirm.js +39 -0
  48. package/dist/cli/options.js +62 -0
  49. package/dist/cli/rc.js +103 -0
  50. package/dist/cli/yargs.js +40 -0
  51. package/dist/command/build.js +68 -0
  52. package/dist/command/delete.js +66 -0
  53. package/dist/command/deploy.js +308 -0
  54. package/dist/command/function/index.js +17 -0
  55. package/dist/command/function/pause.js +18 -0
  56. package/dist/command/function/resume.js +18 -0
  57. package/dist/command/function/run.js +41 -0
  58. package/dist/command/function/secret/index.js +15 -0
  59. package/dist/command/function/secret/list.js +27 -0
  60. package/dist/command/function/secret/name.js +8 -0
  61. package/dist/command/function/secret/remove.js +26 -0
  62. package/dist/command/function/secret/run.js +52 -0
  63. package/dist/command/function/secret/set.js +48 -0
  64. package/dist/command/function/status.js +40 -0
  65. package/dist/command/init.js +128 -0
  66. package/dist/command/inspect.js +38 -0
  67. package/dist/command/login.js +108 -0
  68. package/dist/command/logout.js +24 -0
  69. package/dist/command/open.js +48 -0
  70. package/dist/command/pack.js +90 -0
  71. package/dist/command/play.js +80 -0
  72. package/dist/command/serve.js +176 -0
  73. package/dist/command/server/index.js +17 -0
  74. package/dist/command/server/key/create.js +36 -0
  75. package/dist/command/server/key/index.js +15 -0
  76. package/dist/command/server/key/list.js +34 -0
  77. package/dist/command/server/key/revoke.js +24 -0
  78. package/dist/command/server/key/run.js +54 -0
  79. package/dist/command/validate.js +47 -0
  80. package/dist/command/whoami.js +55 -0
  81. package/dist/commands.js +93 -0
  82. package/dist/config/ai.js +2 -0
  83. package/dist/config/art.js +13 -0
  84. package/dist/config/audience.js +2 -0
  85. package/dist/config/code.js +129 -0
  86. package/dist/config/file.js +13 -0
  87. package/dist/config/genre.js +19 -0
  88. package/{src → dist}/config/html.js +2 -7
  89. package/dist/config/image.js +5 -0
  90. package/dist/config/input.js +11 -0
  91. package/dist/config/json.js +23 -0
  92. package/dist/config/limit.js +14 -0
  93. package/dist/config/orientation.js +11 -0
  94. package/dist/config/package.js +8 -0
  95. package/dist/config/product.js +14 -0
  96. package/dist/config/template.js +37 -0
  97. package/dist/config/uri.js +18 -0
  98. package/dist/config/url.js +11 -0
  99. package/dist/config/video.js +5 -0
  100. package/dist/config/visibility.js +2 -0
  101. package/dist/config/workflow.js +7 -0
  102. package/dist/parser/env.js +61 -0
  103. package/dist/parser/given.js +8 -0
  104. package/dist/parser/manifest.js +45 -0
  105. package/dist/parser/media.js +57 -0
  106. package/dist/parser/project.js +129 -0
  107. package/dist/parser/readme-file.js +44 -0
  108. package/dist/parser/readme.js +70 -0
  109. package/dist/parser/sections.js +92 -0
  110. package/dist/parser/self.js +16 -0
  111. package/dist/phrase/account.js +35 -0
  112. package/dist/phrase/common.js +130 -0
  113. package/dist/phrase/deploy.js +184 -0
  114. package/dist/phrase/function.js +135 -0
  115. package/dist/phrase/game.js +27 -0
  116. package/dist/phrase/index.js +15 -0
  117. package/dist/phrase/init.js +53 -0
  118. package/dist/phrase/internal.js +61 -0
  119. package/dist/phrase/manifest.js +120 -0
  120. package/dist/phrase/media.js +90 -0
  121. package/dist/phrase/pack.js +69 -0
  122. package/dist/phrase/serve.js +84 -0
  123. package/dist/phrase/server.js +38 -0
  124. package/dist/runner/bundle.js +95 -0
  125. package/dist/runner/outbound.js +69 -0
  126. package/dist/schema/check/game.js +29 -0
  127. package/dist/schema/check/workflow.js +57 -0
  128. package/dist/schema/game.js +462 -0
  129. package/dist/schema/message.js +61 -0
  130. package/dist/schema/readme.js +27 -0
  131. package/dist/schema/runner.js +43 -0
  132. package/dist/schema/server.js +91 -0
  133. package/dist/schema/workflow.js +99 -0
  134. package/dist/serve/files.js +39 -0
  135. package/dist/serve/game.js +172 -0
  136. package/dist/serve/page.js +490 -0
  137. package/dist/serve/reload.js +55 -0
  138. package/dist/serve/remote.js +114 -0
  139. package/dist/serve/runner.js +296 -0
  140. package/dist/serve/server.js +163 -0
  141. package/dist/serve/ticket.js +232 -0
  142. package/dist/util/bytes.js +16 -0
  143. package/dist/util/chars.js +19 -0
  144. package/dist/util/command.js +11 -0
  145. package/dist/util/delay.js +36 -0
  146. package/dist/util/doc.js +59 -0
  147. package/dist/util/error.js +35 -0
  148. package/dist/util/http.js +13 -0
  149. package/dist/util/image.js +64 -0
  150. package/dist/util/links.js +45 -0
  151. package/dist/util/lockfile.js +17 -0
  152. package/dist/util/log.js +101 -0
  153. package/dist/util/md.js +37 -0
  154. package/dist/util/media.js +27 -0
  155. package/dist/util/objs.js +29 -0
  156. package/dist/util/os.js +13 -0
  157. package/dist/util/output.js +133 -0
  158. package/dist/util/paths.js +8 -0
  159. package/dist/util/progress.js +57 -0
  160. package/dist/util/promise.js +18 -0
  161. package/dist/util/request.js +91 -0
  162. package/dist/util/s3.js +67 -0
  163. package/dist/util/schema.js +151 -0
  164. package/dist/util/screenshot.js +24 -0
  165. package/dist/util/shell.js +64 -0
  166. package/dist/util/size.js +32 -0
  167. package/dist/util/spinner.js +35 -0
  168. package/dist/util/strs.js +46 -0
  169. package/dist/util/table.js +18 -0
  170. package/dist/util/term.js +21 -0
  171. package/dist/util/time.js +16 -0
  172. package/dist/util/toml.js +28 -0
  173. package/{src → dist}/util/uris.js +8 -14
  174. package/dist/util/video.js +113 -0
  175. package/dist/util/zip.js +62 -0
  176. package/npm-shrinkwrap.json +3256 -0
  177. package/package.json +41 -39
  178. package/bin/arc-build.js +0 -139
  179. package/bin/arc-default.js +0 -65
  180. package/bin/arc-deploy.js +0 -456
  181. package/bin/arc-init.js +0 -187
  182. package/bin/arc-inspect.js +0 -97
  183. package/bin/arc-login.js +0 -165
  184. package/bin/arc-logout.js +0 -75
  185. package/bin/arc-open.js +0 -104
  186. package/bin/arc-pack.js +0 -146
  187. package/bin/arc-play.js +0 -140
  188. package/bin/arc-serve.js +0 -214
  189. package/bin/arc-validate.js +0 -112
  190. package/bin/arc-whoami.js +0 -119
  191. package/src/account.js +0 -249
  192. package/src/action/build/tool.js +0 -80
  193. package/src/action/deploy/tool-git.js +0 -90
  194. package/src/action/deploy/tool.js +0 -88
  195. package/src/action/deploy/wait.js +0 -151
  196. package/src/action/init/manifest.js +0 -83
  197. package/src/action/init/tool-patch.js +0 -32
  198. package/src/action/init/tool.js +0 -97
  199. package/src/action/inspect/tool.js +0 -26
  200. package/src/action/login/flow.js +0 -101
  201. package/src/action/login/tool.js +0 -16
  202. package/src/action/logout/tool.js +0 -15
  203. package/src/action/open/tool.js +0 -38
  204. package/src/action/pack/limits.js +0 -51
  205. package/src/action/pack/tool.js +0 -171
  206. package/src/action/pack/unsound.js +0 -69
  207. package/src/action/play/tool.js +0 -109
  208. package/src/action/predeploy/ac.js +0 -112
  209. package/src/action/predeploy/git.js +0 -223
  210. package/src/action/predeploy/pm.js +0 -37
  211. package/src/action/predeploy/published.js +0 -82
  212. package/src/action/predeploy/tool-git.js +0 -154
  213. package/src/action/predeploy/tool.js +0 -29
  214. package/src/action/serve/tool.js +0 -209
  215. package/src/action/validate/checked.js +0 -37
  216. package/src/action/validate/tool.js +0 -67
  217. package/src/action/validate/unknown.js +0 -86
  218. package/src/action/validate/unsound.js +0 -138
  219. package/src/action/whoami/tool.js +0 -15
  220. package/src/api.js +0 -163
  221. package/src/cli/build.js +0 -15
  222. package/src/cli/deploy.js +0 -21
  223. package/src/cli/init.js +0 -17
  224. package/src/cli/inspect.js +0 -15
  225. package/src/cli/login.js +0 -15
  226. package/src/cli/logout.js +0 -15
  227. package/src/cli/open.js +0 -15
  228. package/src/cli/pack.js +0 -15
  229. package/src/cli/play.js +0 -15
  230. package/src/cli/predeploy.js +0 -21
  231. package/src/cli/serve.js +0 -15
  232. package/src/cli/validate.js +0 -15
  233. package/src/cli/whoami.js +0 -15
  234. package/src/config/ai.js +0 -5
  235. package/src/config/art.js +0 -16
  236. package/src/config/audience.js +0 -5
  237. package/src/config/code.js +0 -142
  238. package/src/config/file.js +0 -23
  239. package/src/config/genre.js +0 -22
  240. package/src/config/image.js +0 -7
  241. package/src/config/input.js +0 -14
  242. package/src/config/limit.js +0 -21
  243. package/src/config/orientation.js +0 -14
  244. package/src/config/package.js +0 -5
  245. package/src/config/product.js +0 -5
  246. package/src/config/template.js +0 -45
  247. package/src/config/uri.js +0 -27
  248. package/src/config/url.js +0 -20
  249. package/src/config/video.js +0 -7
  250. package/src/config/visibility.js +0 -5
  251. package/src/config/workflow.js +0 -18
  252. package/src/parser/env.js +0 -84
  253. package/src/parser/given.js +0 -17
  254. package/src/parser/manifest.js +0 -80
  255. package/src/parser/media.js +0 -90
  256. package/src/parser/project.js +0 -166
  257. package/src/parser/readme-file.js +0 -76
  258. package/src/parser/readme.js +0 -96
  259. package/src/parser/sections.js +0 -107
  260. package/src/parser/self.js +0 -27
  261. package/src/phrase.js +0 -1294
  262. package/src/schema/check/game.js +0 -61
  263. package/src/schema/check/workflow.js +0 -99
  264. package/src/schema/game.js +0 -649
  265. package/src/schema/message.js +0 -85
  266. package/src/schema/readme.js +0 -44
  267. package/src/schema/workflow.js +0 -150
  268. package/src/serve/files.js +0 -61
  269. package/src/serve/game.js +0 -191
  270. package/src/serve/page.js +0 -345
  271. package/src/serve/reload.js +0 -68
  272. package/src/serve/remote.js +0 -121
  273. package/src/serve/server.js +0 -128
  274. package/src/util/argv.js +0 -116
  275. package/src/util/bytes.js +0 -25
  276. package/src/util/chars.js +0 -30
  277. package/src/util/command.js +0 -18
  278. package/src/util/delay.js +0 -52
  279. package/src/util/doc.js +0 -72
  280. package/src/util/error.js +0 -50
  281. package/src/util/http.js +0 -25
  282. package/src/util/image.js +0 -93
  283. package/src/util/links.js +0 -78
  284. package/src/util/lockfile.js +0 -35
  285. package/src/util/log.js +0 -149
  286. package/src/util/md.js +0 -61
  287. package/src/util/media.js +0 -40
  288. package/src/util/objs.js +0 -45
  289. package/src/util/os.js +0 -27
  290. package/src/util/output.js +0 -174
  291. package/src/util/paths.js +0 -21
  292. package/src/util/progress.js +0 -85
  293. package/src/util/promise.js +0 -29
  294. package/src/util/rc.js +0 -144
  295. package/src/util/request.js +0 -89
  296. package/src/util/s3.js +0 -92
  297. package/src/util/schema.js +0 -189
  298. package/src/util/screenshot.js +0 -37
  299. package/src/util/shell.js +0 -84
  300. package/src/util/size.js +0 -53
  301. package/src/util/spinner.js +0 -52
  302. package/src/util/strs.js +0 -73
  303. package/src/util/term.js +0 -28
  304. package/src/util/time.js +0 -29
  305. package/src/util/toml.js +0 -14
  306. package/src/util/video.js +0 -157
  307. package/src/util/zip.js +0 -88
  308. /package/{src/serve → assets}/favicon.ico +0 -0
@@ -0,0 +1,35 @@
1
+ // the secrets a build declares that have no value: a release never checks
2
+ // them, so a build can ship naming one (`[function] secrets`) with no value
3
+ // on its channel, and its function then reads nothing for it. A direct
4
+ // deploy can say so first, since it has the login that reads the game's
5
+ // secrets; `arc deploy git` has none, and never asks.
6
+ //
7
+ // Nothing calls this yet: what it finds is a warning, a warning has a code,
8
+ // and a code has an entry on the public Errors page, which says nothing of
9
+ // functions until they ship (TODO.md, Agreed next).
10
+ import { auth, gameSecrets } from "../../api.js";
11
+ import { channel } from "../../util/links.js";
12
+ // [function]
13
+ // the names `declared` (the manifest's `function.secrets`) that have no
14
+ // value on the channel the game's version goes to, in the order they're
15
+ // declared. With none declared, nothing is asked. When the game's secrets
16
+ // can't be read (offline, an API error, a game that isn't on Arcadible
17
+ // yet), it resolves with none, as the predeploy's other checks pass over
18
+ // what they can't answer: a warning states a fact, and there's none to
19
+ // state.
20
+ export async function unset(current, { id, version }, declared) {
21
+ const where = channel(version);
22
+ if (!declared?.length) {
23
+ return { channel: where, names: [] };
24
+ }
25
+ try {
26
+ const secrets = await gameSecrets(id, null, auth(current?.session?.access_token));
27
+ const set = new Set((secrets ?? [])
28
+ .filter((secret) => secret.channel === where)
29
+ .map((secret) => secret.name));
30
+ return { channel: where, names: declared.filter((name) => !set.has(name)) };
31
+ }
32
+ catch {
33
+ return { channel: where, names: [] };
34
+ }
35
+ }
@@ -0,0 +1,108 @@
1
+ // [import]
2
+ import { discoverGame, discoverGameBuild, discoverGameRepo, } from "../../api.js";
3
+ import { GAME_HANDLE_CHANGED, GAME_NOT_DEPLOYED, REPO_NOT_CONNECTED, WARNING, } from "../../config/code.js";
4
+ import { ArcError } from "../../util/error.js";
5
+ import { releasing } from "./game.js";
6
+ import { ensureClean, ensureRemote, ensureRepo, ensureRoot, ensureTagFree, ensureWorkflow, originRepo, } from "./git.js";
7
+ import { given } from "../../parser/given.js";
8
+ import { HttpError } from "../../util/http.js";
9
+ import { gameHandleChanged, gameNotDeployed, repoNotConnected, versionUnchecked, } from "../../phrase/index.js";
10
+ import { studioUrl } from "../../util/links.js";
11
+ import { ensureLockFile } from "./pm.js";
12
+ import { refuse } from "./published.js";
13
+ // [function]
14
+ // a public lookup's answer: found (200, with its data), missing (404), or
15
+ // null for any other answer, such as when the API can't be reached.
16
+ function answerOf(request) {
17
+ return request.then((data) => ({ data, status: 200 }), (err) => err instanceof HttpError && err.status === 404 ? { status: 404 } : null);
18
+ }
19
+ // [function]
20
+ // what Arcadible would refuse in the release, refused before the tag is pushed: a
21
+ // game that was never deployed (a release can't create one), a version
22
+ // that's already published, and a handle that isn't the game's (only a
23
+ // direct deploy changes one, so a collaborator's push can't). The lookups
24
+ // are public, so this needs no login.
25
+ // when Arcadible can't be reached, it warns and pushes anyway: a release
26
+ // shouldn't depend on the API, and Arcadible still checks.
27
+ function ensurePublishable({ handle, id, version }, handler) {
28
+ return Promise.all([
29
+ answerOf(discoverGame(id)),
30
+ answerOf(discoverGameBuild(id, version)),
31
+ ]).then(([game, build]) => {
32
+ if (game?.status === 404) {
33
+ throw new ArcError(GAME_NOT_DEPLOYED, gameNotDeployed(handle ?? id));
34
+ }
35
+ if (game === null || build === null) {
36
+ if (handler.onWarning) {
37
+ handler.onWarning({
38
+ code: WARNING.VERSION_UNCHECKED,
39
+ message: versionUnchecked(version),
40
+ });
41
+ }
42
+ return null;
43
+ }
44
+ if (build.status === 200) {
45
+ return refuse(id, version);
46
+ }
47
+ const current = game.data?.handle ?? null;
48
+ if (handle !== current) {
49
+ throw new ArcError(GAME_HANDLE_CHANGED, gameHandleChanged(handle, current));
50
+ }
51
+ return null;
52
+ });
53
+ }
54
+ // [function]
55
+ // the project's checks: a lockfile when there's a package.json, and a clean
56
+ // repository, whose root is the project, with the release workflow and a
57
+ // reachable origin.
58
+ function ensureProject(root) {
59
+ return ensureLockFile(root)
60
+ .then(() => ensureRepo(root))
61
+ .then(() => ensureRoot(root))
62
+ .then(() => ensureClean(root))
63
+ .then(() => ensureWorkflow(root))
64
+ .then(() => ensureRemote(root));
65
+ }
66
+ // [function]
67
+ // fails when origin isn't the game's connected repository, which Arcadible
68
+ // would refuse (repo_not_connected) once GitHub Actions had built it. It's
69
+ // asked by name, which needs no login, so it checks whoever pushes. Skipped
70
+ // when origin is a path on this machine, or Arcadible can't be reached.
71
+ function ensureConnected(root, { handle, id }) {
72
+ return originRepo(root).then((repo) => {
73
+ if (!repo) {
74
+ return undefined;
75
+ }
76
+ return answerOf(discoverGameRepo(id, repo.owner, repo.name)).then((connected) => {
77
+ if (connected?.status === 404) {
78
+ throw new ArcError(REPO_NOT_CONNECTED, repoNotConnected(handle ?? id, `${repo.owner}/${repo.name}`, studioUrl(id, "repository")));
79
+ }
80
+ });
81
+ });
82
+ }
83
+ // [function]
84
+ // the release's checks: its tag is free, Arcadible would publish it, and
85
+ // origin is its connected repository. resolves with the version.
86
+ function ensureRelease(root, game, handler) {
87
+ return ensureTagFree(root, game.version)
88
+ .then(() => ensurePublishable(game, handler))
89
+ .then(() => ensureConnected(root, game))
90
+ .then(() => ({ to: game.version }));
91
+ }
92
+ // [function]
93
+ // a git deploy needs no login, and never uses one: anyone who can push can
94
+ // release, and so can tools other than arc. Every lookup is public, so its
95
+ // answer is the same whoever runs it, and true when it's asked; the release
96
+ // pipeline has the final word.
97
+ export function predeployToolGit(conf, { onPredeployBegin, ...handler }) {
98
+ const root = conf.root;
99
+ if (onPredeployBegin) {
100
+ onPredeployBegin();
101
+ }
102
+ return given(conf)
103
+ .then(({ game }) => {
104
+ const releases = releasing(game);
105
+ return ensureProject(root).then(() => releases);
106
+ })
107
+ .then((game) => ensureRelease(root, game, handler));
108
+ }
@@ -0,0 +1,16 @@
1
+ // [import]
2
+ import { ensureId, ensureUnpublished } from "./ac.js";
3
+ import { releasing } from "./game.js";
4
+ import { given } from "../../parser/given.js";
5
+ // [function]
6
+ // a direct deploy needs a login. Each lookup uses its token or not, as it
7
+ // needs, and its answer is true when it's asked.
8
+ export function predeployTool(current, conf, { onPredeployBegin, ...handler }) {
9
+ if (onPredeployBegin) {
10
+ onPredeployBegin({ root: conf.root });
11
+ }
12
+ return given(conf)
13
+ .then(({ game }) => ensureId(current, releasing(game), handler))
14
+ .then((game) => ensureUnpublished(current, game))
15
+ .then((game) => ({ held: game.held, to: game.version }));
16
+ }
@@ -0,0 +1,91 @@
1
+ // a runner's secrets: the values a game's runner needs and its repository
2
+ // mustn't hold, such as another service's key. Each is for one game and one
3
+ // channel, by the name the manifest declares (function.secrets), set by the
4
+ // game's owner, and never shown again. Nothing here keeps one.
5
+ import { deleteGameSecret, gameSecrets, putGameSecret } from "../../api.js";
6
+ import { API_REFUSED, ARGUMENT_INVALID, GAME_UNAVAILABLE, } from "../../config/code.js";
7
+ import { ArcError } from "../../util/error.js";
8
+ import { channelOf, gameOf, headersOf, isStatus, needOf } from "../game.js";
9
+ import { gameUnavailable, secretLimitReached, secretNameInvalid, secretNotFound, secretValueInvalid, } from "../../phrase/index.js";
10
+ // [declare]
11
+ // a secret's name, as an environment variable is named; ARCADIBLE_ is kept
12
+ // for Arcadible's own.
13
+ const NAME = /^(?!ARCADIBLE_)[A-Z][A-Z0-9_]{0,63}$/u;
14
+ const VALUE_MAX = 4096;
15
+ // [function]
16
+ // a secret's name as it was given, or a refusal before the API is asked.
17
+ function nameOf(name) {
18
+ if (typeof name !== "string" || !NAME.test(name)) {
19
+ throw new ArcError(ARGUMENT_INVALID, secretNameInvalid());
20
+ }
21
+ return name;
22
+ }
23
+ // [function]
24
+ // sets a secret, as `{ name, channel }`. `value()` resolves with its value,
25
+ // asked for only once the rest holds, so nothing is typed for a refusal.
26
+ export async function set(current, { channel, name, value, ...conf }) {
27
+ const named = nameOf(name);
28
+ const where = needOf(channel);
29
+ const id = await gameOf(conf);
30
+ const headers = headersOf(current);
31
+ const secret = await value();
32
+ if (typeof secret !== "string" ||
33
+ secret === "" ||
34
+ Buffer.byteLength(secret) > VALUE_MAX) {
35
+ throw new ArcError(ARGUMENT_INVALID, secretValueInvalid());
36
+ }
37
+ const form = new FormData();
38
+ form.append("value", secret);
39
+ try {
40
+ const kept = await putGameSecret(id, where, named, form, null, headers);
41
+ return { channel: kept.channel, name: kept.name };
42
+ }
43
+ catch (err) {
44
+ if (isStatus(err, 404)) {
45
+ throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
46
+ cause: err,
47
+ });
48
+ }
49
+ if (isStatus(err, 409)) {
50
+ throw new ArcError(API_REFUSED, secretLimitReached(where), {
51
+ cause: err,
52
+ });
53
+ }
54
+ throw err;
55
+ }
56
+ }
57
+ // [function]
58
+ // the game's secrets, by channel and name, of one channel or both: each as
59
+ // `{ name, channel, updated_at }`, never a value.
60
+ export async function list(current, { channel, ...conf }) {
61
+ const where = channelOf(channel);
62
+ const id = await gameOf(conf);
63
+ const headers = headersOf(current);
64
+ const secrets = await gameSecrets(id, null, headers);
65
+ return (secrets ?? [])
66
+ .filter((secret) => !where || secret.channel === where)
67
+ .map((secret) => ({
68
+ channel: secret.channel,
69
+ name: secret.name,
70
+ updated_at: secret.updated_at,
71
+ }));
72
+ }
73
+ // [function]
74
+ // removes a secret, and resolves with `{ name, channel }`. One that isn't
75
+ // set, or isn't the game's, is the same to its owner: not found.
76
+ export async function remove(current, { channel, name, ...conf }) {
77
+ const named = nameOf(name);
78
+ const where = needOf(channel);
79
+ const id = await gameOf(conf);
80
+ const headers = headersOf(current);
81
+ try {
82
+ const gone = await deleteGameSecret(id, where, named, null, headers);
83
+ return { channel: gone.channel, name: gone.name };
84
+ }
85
+ catch (err) {
86
+ if (isStatus(err, 404)) {
87
+ throw new ArcError(API_REFUSED, secretNotFound({ channel: where, name: named }), { cause: err });
88
+ }
89
+ throw err;
90
+ }
91
+ }
@@ -0,0 +1,249 @@
1
+ // arc serve: builds the project unless told not to, then serves deploy_dir
2
+ // framed in a local play page (src/serve), reloading the game when deploy_dir
3
+ // changes.
4
+ // [import]
5
+ import { readFile } from "node:fs/promises";
6
+ import { dirname, join, relative, resolve as resolvePath } from "node:path";
7
+ import { setTimeout as sleep } from "node:timers/promises";
8
+ // [import]
9
+ import { pathExists } from "fs-extra";
10
+ // [import]
11
+ import { ARGUMENT_INVALID, DEPLOY_DIR_MISSING, PORT_IN_USE, } from "../../config/code.js";
12
+ import { buildCommand } from "../../util/command.js";
13
+ import { ArcError } from "../../util/error.js";
14
+ import { dirFiles } from "../../serve/files.js";
15
+ import { given } from "../../parser/given.js";
16
+ import * as phrase from "../../phrase/index.js";
17
+ import { media } from "../../parser/media.js";
18
+ import { configDir } from "../../util/os.js";
19
+ import { title, tool } from "../../config/product.js";
20
+ import { watchDir } from "../../serve/reload.js";
21
+ import { remoteFiles } from "../../serve/remote.js";
22
+ import { serve } from "../../serve/server.js";
23
+ import { playerOf } from "../../serve/ticket.js";
24
+ import { buildTool } from "../build/tool.js";
25
+ import { ARCADIBLE_SDK, HOST_HTTP_PLAY } from "../../config/uri.js";
26
+ // [declare]
27
+ // what build.channel says while served locally (docs: arc-serve.md).
28
+ const CHANNEL = "local";
29
+ // the saves of a game with no id yet, kept apart from any other's.
30
+ const UNNAMED = "local";
31
+ // [declare]
32
+ // the headers a page needs for the play page to frame it: the play page is
33
+ // cross-origin isolated, so a cross-origin frame must be too, and allow it.
34
+ const FRAMEABLE = {
35
+ "cross-origin-embedder-policy": ["credentialless", "require-corp"],
36
+ "cross-origin-resource-policy": ["cross-origin"],
37
+ };
38
+ // [declare]
39
+ // how long `url` has to answer before it counts as unreachable: a server
40
+ // that takes the connection and never answers would otherwise hold `arc
41
+ // serve` for minutes.
42
+ const PROBE_MS = 10000;
43
+ // [function]
44
+ // what `url` says when asked: `{ reachable, frameable }`, where `frameable`
45
+ // says whether it sends the headers the play page needs to frame it.
46
+ async function probe(url) {
47
+ try {
48
+ // null when it hasn't answered in time
49
+ const res = await Promise.race([
50
+ fetch(url, { method: "GET" }),
51
+ sleep(PROBE_MS, null, { ref: false }),
52
+ ]);
53
+ if (!res) {
54
+ return { frameable: false, reachable: false };
55
+ }
56
+ await res.body?.cancel();
57
+ const frameable = Object.entries(FRAMEABLE).every(([name, values]) => {
58
+ const sent = res.headers.get(name)?.trim().toLowerCase();
59
+ return sent !== undefined && values.includes(sent);
60
+ });
61
+ return { frameable, reachable: true };
62
+ }
63
+ catch {
64
+ return { frameable: false, reachable: false };
65
+ }
66
+ }
67
+ // [function]
68
+ // one of the project's art files, read, or null for a field with none.
69
+ function readArt(root, file) {
70
+ return typeof file === "string" && file ? readFile(join(root, file)) : null;
71
+ }
72
+ // [function]
73
+ // the project's store icon, .arcadible/icon.png, or null: found by its exact
74
+ // name, as `arc deploy` finds it, each time it's asked for.
75
+ function storeIcon(root) {
76
+ return async () => {
77
+ const { game } = await media(root);
78
+ return readArt(root, game?.["icon"]);
79
+ };
80
+ }
81
+ // [function]
82
+ // the loading screen's art: the project's splash, else its banner, else its
83
+ // cover, as the play page picks it, or null; each time it's asked for.
84
+ function storeArt(root) {
85
+ return async () => {
86
+ const { game } = await media(root);
87
+ return readArt(root, game?.["splash"] ?? game?.["banner"] ?? game?.["cover"]);
88
+ };
89
+ }
90
+ // [function]
91
+ // listens, turning a port in use into its code.
92
+ async function listen(options) {
93
+ try {
94
+ return await serve(options);
95
+ }
96
+ catch (ex) {
97
+ if (ex instanceof Error && "code" in ex && ex.code === "EADDRINUSE") {
98
+ throw new ArcError(PORT_IN_USE, phrase.portInUse(options.port), {
99
+ cause: ex,
100
+ });
101
+ }
102
+ throw ex;
103
+ }
104
+ }
105
+ // [function]
106
+ // the strings of a list the manifest has, or none: the project is as it was
107
+ // parsed, and arc serve doesn't validate it.
108
+ function strings(value) {
109
+ return Array.isArray(value)
110
+ ? value.filter((item) => typeof item === "string")
111
+ : [];
112
+ }
113
+ // [function]
114
+ // serves the project at `conf.root`. `conf.build` false skips the build, and
115
+ // `conf.url` frames that server's page instead of serving deploy_dir.
116
+ // `conf.handler` hears `onBuild()` as a build starts, `onRemote(name, file,
117
+ // error)` for each of Arcadible's files, and `onReload()` for each reload.
118
+ // resolves with `{ page, game, built, deployDir, url, probed, version,
119
+ // close() }`, where `probed` is what `conf.url` answered.
120
+ export async function serveTool(conf) {
121
+ const { port, root, url } = conf;
122
+ const handler = {
123
+ onBuild() { },
124
+ onReload() { },
125
+ onRemote() { },
126
+ onRunnerError() { },
127
+ onRunnerInstall() { },
128
+ onRunnerStart() { },
129
+ ...conf.handler,
130
+ };
131
+ const project = await given(conf);
132
+ const game = project.game;
133
+ // who the game runs for, by name (`--player`), or a guest
134
+ const player = playerOf(game.id ?? UNNAMED, conf.player);
135
+ if (player === false) {
136
+ throw new ArcError(ARGUMENT_INVALID, phrase.playerInvalid());
137
+ }
138
+ // whether to say how a server finds this arc serve: only for a game with
139
+ // servers of its own, or run for a player
140
+ const forServer = Boolean(project.server) || Boolean(player);
141
+ // the game's runner, when the project has one: its code, where its runtime
142
+ // is kept, and who hears how it's doing
143
+ const runs = project.function;
144
+ if (runs && typeof runs.main !== "string") {
145
+ throw new TypeError("function.main must be a path.");
146
+ }
147
+ const runnerMain = runs ? resolvePath(root, String(runs.main)) : null;
148
+ const options = {
149
+ art: storeArt(root),
150
+ icon: storeIcon(root),
151
+ info: {
152
+ channel: CHANNEL,
153
+ id: game.id ?? UNNAMED,
154
+ title: String(game.title ?? game.handle ?? title),
155
+ version: game.version ?? null,
156
+ },
157
+ // arc serve's own tickets, signed with a key kept beside the session
158
+ keyFile: join(configDir(), tool, "ticket-key.json"),
159
+ onRemote: handler.onRemote,
160
+ player,
161
+ port,
162
+ remote: remoteFiles({
163
+ dir: join(configDir(), tool, "sdk"),
164
+ host: HOST_HTTP_PLAY,
165
+ sdk: ARCADIBLE_SDK,
166
+ }),
167
+ ...(runs && runnerMain
168
+ ? {
169
+ runner: {
170
+ dir: join(configDir(), tool, "runner"),
171
+ handler: {
172
+ onError: handler.onRunnerError,
173
+ onInstall: handler.onRunnerInstall,
174
+ onStart: handler.onRunnerStart,
175
+ },
176
+ hosts: strings(runs.outbound_hosts),
177
+ main: runnerMain,
178
+ // the secrets the manifest names, from this process's own
179
+ // environment: one that isn't set is undefined in the code, as
180
+ // on Arcadible
181
+ secrets: Object.fromEntries(strings(runs.secrets).flatMap((name) => {
182
+ const value = process.env[name];
183
+ return typeof value === "string" ? [[name, value]] : [];
184
+ })),
185
+ },
186
+ }
187
+ : {}),
188
+ servers: strings(project.server?.origins),
189
+ ...(conf.host ? { hostFile: resolvePath(root, conf.host) } : {}),
190
+ };
191
+ // the runner's code, watched: a change runs the new code
192
+ const watchRunner = function (served) {
193
+ const running = served.runner;
194
+ if (!running || !runnerMain) {
195
+ return () => null;
196
+ }
197
+ return watchDir(dirname(runnerMain), () => {
198
+ void running.restart();
199
+ });
200
+ };
201
+ const version = game.version ?? null;
202
+ if (url) {
203
+ const served = await listen({ ...options, src: url });
204
+ const probed = await probe(url);
205
+ const unwatch = watchRunner(served);
206
+ return {
207
+ ...served,
208
+ built: false,
209
+ close() {
210
+ unwatch();
211
+ served.close();
212
+ },
213
+ deployDir: null,
214
+ forServer,
215
+ probed,
216
+ url,
217
+ version,
218
+ };
219
+ }
220
+ const built = conf.build !== false && Boolean(buildCommand(project.workflow.build));
221
+ if (built) {
222
+ handler.onBuild();
223
+ await buildTool({ project, root });
224
+ }
225
+ const deployDir = resolvePath(root, String(project.workflow.deploy_dir));
226
+ if (!(await pathExists(deployDir))) {
227
+ throw new ArcError(DEPLOY_DIR_MISSING, phrase.deployDirMissing(relative(root, deployDir) || "."));
228
+ }
229
+ const served = await listen({ ...options, files: dirFiles(deployDir) });
230
+ const stop = watchDir(deployDir, () => {
231
+ served.reload();
232
+ handler.onReload();
233
+ });
234
+ const unwatch = watchRunner(served);
235
+ return {
236
+ ...served,
237
+ built,
238
+ close() {
239
+ stop();
240
+ unwatch();
241
+ served.close();
242
+ },
243
+ deployDir,
244
+ forServer,
245
+ probed: null,
246
+ url: null,
247
+ version,
248
+ };
249
+ }
@@ -0,0 +1,28 @@
1
+ // [import]
2
+ import { VALIDATION_FAILED } from "../../config/code.js";
3
+ import { ArcError } from "../../util/error.js";
4
+ import { issuesFound } from "../../phrase/index.js";
5
+ import { project } from "../../parser/project.js";
6
+ import { validateTool } from "./tool.js";
7
+ // [function]
8
+ // whether a project is checked, which it is when validating it found no
9
+ // issues: each table then passed its schema, which changes nothing it reads.
10
+ function isChecked(_parsed, issues) {
11
+ return !issues.length;
12
+ }
13
+ // [function]
14
+ // parses and validates the project at `root` for a command that goes on from
15
+ // it (arc build, arc pack, arc deploy): resolves with the parsed project, or
16
+ // rejects as validation_failed with its issues in `data`. `onWarnings` gets
17
+ // the warnings either way, for --json to list beside the result or the error.
18
+ export async function checked(root, onWarnings) {
19
+ const parsed = await project(root);
20
+ const { issues, warnings } = await validateTool({ project: parsed, root });
21
+ onWarnings(warnings);
22
+ if (!isChecked(parsed, issues)) {
23
+ throw new ArcError(VALIDATION_FAILED, issuesFound(issues.length), {
24
+ data: { issues },
25
+ });
26
+ }
27
+ return parsed;
28
+ }
@@ -0,0 +1,56 @@
1
+ // [import]
2
+ import { game } from "../../schema/game.js";
3
+ import { given } from "../../parser/given.js";
4
+ import { readme } from "../../schema/readme.js";
5
+ import { read } from "../../parser/readme-file.js";
6
+ import { runner } from "../../schema/runner.js";
7
+ import { compare, validator } from "../../util/schema.js";
8
+ import { split } from "../../parser/sections.js";
9
+ import { server } from "../../schema/server.js";
10
+ import { unknown } from "./unknown.js";
11
+ import { unsound } from "./unsound.js";
12
+ import { workflow } from "../../schema/workflow.js";
13
+ // [define]
14
+ const gameValidator = validator("game", game);
15
+ const readmeValidator = validator("game", readme);
16
+ const runnerValidator = validator("function", runner);
17
+ const serverValidator = validator("server", server);
18
+ const workflowValidator = validator("workflow", workflow);
19
+ // [function]
20
+ // the README's structure, for its validator, or null without a README.
21
+ function structure(root) {
22
+ return read(root).then((file) => {
23
+ if (!file) {
24
+ return null;
25
+ }
26
+ const { rules, trailing } = split(file.doc);
27
+ return { file: file.file, rules, trailing };
28
+ });
29
+ }
30
+ // [function]
31
+ function validate(proj, readmeStructure, { root }) {
32
+ const results = [
33
+ gameValidator(proj.game, { root }),
34
+ workflowValidator(proj.workflow, { root }),
35
+ ];
36
+ if (proj.function) {
37
+ results.push(runnerValidator(proj.function));
38
+ }
39
+ if (proj.server) {
40
+ results.push(serverValidator(proj.server));
41
+ }
42
+ if (readmeStructure) {
43
+ const { file, ...value } = readmeStructure;
44
+ results.push(readmeValidator(value, { file }));
45
+ }
46
+ return results.flatMap((result) => result.issues).sort(compare);
47
+ }
48
+ // [function]
49
+ // the project's issues, which fail it, and its warnings, which don't.
50
+ export function validateTool(conf) {
51
+ const root = conf.root;
52
+ return Promise.all([given(conf), structure(root), unknown(root)]).then(([proj, readmeStructure, warnings]) => ({
53
+ issues: validate(proj, readmeStructure, { root }),
54
+ warnings: [...warnings, ...unsound(proj)].sort(compare),
55
+ }));
56
+ }
@@ -0,0 +1,58 @@
1
+ // [import]
2
+ import { WARNING } from "../../config/code.js";
3
+ import { game } from "../../schema/game.js";
4
+ import { didYouMean, unknownField, unknownTable } from "../../phrase/index.js";
5
+ import { manifest } from "../../parser/manifest.js";
6
+ import { isTable } from "../../util/objs.js";
7
+ import { runner } from "../../schema/runner.js";
8
+ import { server } from "../../schema/server.js";
9
+ import { closest } from "../../util/strs.js";
10
+ import { workflow } from "../../schema/workflow.js";
11
+ // [function]
12
+ // the fields each table takes, from its schema.
13
+ function known(root) {
14
+ return {
15
+ function: Object.keys(runner().shape),
16
+ game: Object.keys(game({}, { root }).shape),
17
+ server: Object.keys(server().shape),
18
+ workflow: Object.keys(workflow({}, { root }).shape),
19
+ };
20
+ }
21
+ // [function]
22
+ // a warning, in an issue's shape: Arcadible ignores what it doesn't know, so
23
+ // it's reported without failing, with the name it might have meant.
24
+ function warning(path, message, near) {
25
+ return {
26
+ code: WARNING.FIELD_UNKNOWN,
27
+ details: near ? [didYouMean(near)] : [],
28
+ link: null,
29
+ message,
30
+ path,
31
+ };
32
+ }
33
+ // [function]
34
+ // a value outside any table, such as a `handle` above `[game]`: the field
35
+ // it is, in the table that takes it, if any.
36
+ function untabled(fields, name) {
37
+ const table = Object.keys(fields).find((each) => (fields[each] ?? []).includes(name));
38
+ return warning(name, unknownField(), table ? `${table}.${name}` : null);
39
+ }
40
+ // [function]
41
+ // the tables and fields in arcadible.toml that Arcadible doesn't know, such
42
+ // as a misspelled `genre`, as warnings.
43
+ export function unknown(root) {
44
+ const fields = known(root);
45
+ const tables = Object.keys(fields);
46
+ return manifest(root).then((conf) => Object.entries(conf).flatMap(([table, values]) => {
47
+ const taken = Object.hasOwn(fields, table) ? fields[table] : undefined;
48
+ if (!isTable(values)) {
49
+ return taken ? [] : [untabled(fields, table)];
50
+ }
51
+ if (!taken) {
52
+ return [warning(table, unknownTable(), closest(table, tables))];
53
+ }
54
+ return Object.keys(values)
55
+ .filter((field) => !taken.includes(field))
56
+ .map((field) => warning(`${table}.${field}`, unknownField(), closest(field, taken)));
57
+ }));
58
+ }