arcadible 1.0.23 → 1.0.25

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 (320) 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 +61 -0
  5. package/dist/action/delete/tool.js +47 -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 +49 -0
  10. package/dist/action/deploy/tool.js +49 -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 +62 -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 +88 -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 +30 -0
  23. package/dist/action/pack/limits.js +46 -0
  24. package/dist/action/pack/tool.js +148 -0
  25. package/dist/action/pack/unsound.js +51 -0
  26. package/dist/action/play/tool.js +84 -0
  27. package/dist/action/predeploy/ac.js +75 -0
  28. package/dist/action/predeploy/game.js +6 -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 +103 -0
  34. package/dist/action/predeploy/tool.js +14 -0
  35. package/dist/action/secret/tool.js +91 -0
  36. package/dist/action/serve/tool.js +270 -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/value/tool.js +216 -0
  42. package/dist/action/whoami/tool.js +7 -0
  43. package/dist/api.js +312 -0
  44. package/dist/arc.js +41 -0
  45. package/dist/cli/argv.js +61 -0
  46. package/dist/cli/channel.js +29 -0
  47. package/dist/cli/command.js +163 -0
  48. package/dist/cli/confirm.js +39 -0
  49. package/dist/cli/options.js +62 -0
  50. package/dist/cli/rc.js +103 -0
  51. package/dist/cli/yargs.js +40 -0
  52. package/dist/command/build.js +68 -0
  53. package/dist/command/delete.js +66 -0
  54. package/dist/command/deploy.js +308 -0
  55. package/dist/command/function/index.js +17 -0
  56. package/dist/command/function/pause.js +18 -0
  57. package/dist/command/function/resume.js +18 -0
  58. package/dist/command/function/run.js +41 -0
  59. package/dist/command/function/secret/index.js +15 -0
  60. package/dist/command/function/secret/list.js +27 -0
  61. package/dist/command/function/secret/name.js +8 -0
  62. package/dist/command/function/secret/remove.js +26 -0
  63. package/dist/command/function/secret/run.js +52 -0
  64. package/dist/command/function/secret/set.js +48 -0
  65. package/dist/command/function/status.js +40 -0
  66. package/dist/command/init.js +128 -0
  67. package/dist/command/inspect.js +39 -0
  68. package/dist/command/login.js +108 -0
  69. package/dist/command/logout.js +24 -0
  70. package/dist/command/open.js +49 -0
  71. package/dist/command/pack.js +90 -0
  72. package/dist/command/play.js +81 -0
  73. package/dist/command/serve.js +177 -0
  74. package/dist/command/server/index.js +17 -0
  75. package/dist/command/server/key/create.js +36 -0
  76. package/dist/command/server/key/index.js +15 -0
  77. package/dist/command/server/key/list.js +34 -0
  78. package/dist/command/server/key/revoke.js +24 -0
  79. package/dist/command/server/key/run.js +54 -0
  80. package/dist/command/validate.js +47 -0
  81. package/dist/command/value/get.js +21 -0
  82. package/dist/command/value/index.js +19 -0
  83. package/dist/command/value/key.js +8 -0
  84. package/dist/command/value/list.js +41 -0
  85. package/dist/command/value/remove.js +26 -0
  86. package/dist/command/value/set.js +62 -0
  87. package/dist/command/value/usage.js +69 -0
  88. package/dist/command/whoami.js +55 -0
  89. package/dist/commands.js +100 -0
  90. package/dist/config/ai.js +2 -0
  91. package/dist/config/art.js +13 -0
  92. package/dist/config/audience.js +2 -0
  93. package/dist/config/code.js +129 -0
  94. package/dist/config/file.js +13 -0
  95. package/dist/config/genre.js +19 -0
  96. package/{src → dist}/config/html.js +2 -7
  97. package/dist/config/image.js +5 -0
  98. package/dist/config/input.js +11 -0
  99. package/dist/config/json.js +23 -0
  100. package/dist/config/limit.js +14 -0
  101. package/dist/config/orientation.js +11 -0
  102. package/dist/config/package.js +8 -0
  103. package/dist/config/product.js +14 -0
  104. package/dist/config/template.js +37 -0
  105. package/dist/config/uri.js +18 -0
  106. package/dist/config/url.js +11 -0
  107. package/dist/config/video.js +5 -0
  108. package/dist/config/visibility.js +2 -0
  109. package/dist/config/workflow.js +7 -0
  110. package/dist/parser/env.js +61 -0
  111. package/dist/parser/given.js +8 -0
  112. package/dist/parser/manifest.js +45 -0
  113. package/dist/parser/media.js +57 -0
  114. package/dist/parser/project.js +129 -0
  115. package/dist/parser/readme-file.js +44 -0
  116. package/dist/parser/readme.js +70 -0
  117. package/dist/parser/sections.js +92 -0
  118. package/dist/parser/self.js +16 -0
  119. package/dist/phrase/account.js +35 -0
  120. package/dist/phrase/common.js +139 -0
  121. package/dist/phrase/deploy.js +192 -0
  122. package/dist/phrase/function.js +139 -0
  123. package/dist/phrase/game.js +27 -0
  124. package/dist/phrase/index.js +16 -0
  125. package/dist/phrase/init.js +53 -0
  126. package/dist/phrase/internal.js +61 -0
  127. package/dist/phrase/manifest.js +120 -0
  128. package/dist/phrase/media.js +90 -0
  129. package/dist/phrase/pack.js +69 -0
  130. package/dist/phrase/serve.js +84 -0
  131. package/dist/phrase/server.js +38 -0
  132. package/dist/phrase/value.js +55 -0
  133. package/dist/runner/bundle.js +45 -0
  134. package/dist/runner/entry.js +57 -0
  135. package/dist/runner/outbound.js +69 -0
  136. package/dist/schema/check/game.js +29 -0
  137. package/dist/schema/check/workflow.js +57 -0
  138. package/dist/schema/game.js +462 -0
  139. package/dist/schema/message.js +61 -0
  140. package/dist/schema/readme.js +27 -0
  141. package/dist/schema/runner.js +43 -0
  142. package/dist/schema/server.js +91 -0
  143. package/dist/schema/workflow.js +99 -0
  144. package/dist/serve/files.js +39 -0
  145. package/dist/serve/game.js +172 -0
  146. package/dist/serve/page.js +689 -0
  147. package/dist/serve/reload.js +55 -0
  148. package/dist/serve/remote.js +114 -0
  149. package/dist/serve/runner.js +303 -0
  150. package/dist/serve/server.js +169 -0
  151. package/dist/serve/ticket.js +232 -0
  152. package/dist/serve/values.js +317 -0
  153. package/dist/util/bytes.js +16 -0
  154. package/dist/util/chars.js +19 -0
  155. package/dist/util/command.js +11 -0
  156. package/dist/util/delay.js +36 -0
  157. package/dist/util/doc.js +59 -0
  158. package/dist/util/error.js +35 -0
  159. package/dist/util/http.js +13 -0
  160. package/dist/util/image.js +64 -0
  161. package/dist/util/links.js +45 -0
  162. package/dist/util/lockfile.js +17 -0
  163. package/dist/util/log.js +101 -0
  164. package/dist/util/md.js +37 -0
  165. package/dist/util/media.js +27 -0
  166. package/dist/util/objs.js +46 -0
  167. package/dist/util/os.js +13 -0
  168. package/dist/util/output.js +133 -0
  169. package/dist/util/paths.js +8 -0
  170. package/dist/util/progress.js +57 -0
  171. package/dist/util/promise.js +18 -0
  172. package/dist/util/request.js +103 -0
  173. package/dist/util/s3.js +67 -0
  174. package/dist/util/schema.js +151 -0
  175. package/dist/util/screenshot.js +24 -0
  176. package/dist/util/shape.js +49 -0
  177. package/dist/util/shell.js +64 -0
  178. package/dist/util/size.js +32 -0
  179. package/dist/util/spinner.js +35 -0
  180. package/dist/util/strs.js +46 -0
  181. package/dist/util/table.js +18 -0
  182. package/dist/util/term.js +21 -0
  183. package/dist/util/time.js +16 -0
  184. package/dist/util/toml.js +28 -0
  185. package/{src → dist}/util/uris.js +8 -14
  186. package/dist/util/video.js +113 -0
  187. package/dist/util/zip.js +62 -0
  188. package/npm-shrinkwrap.json +3256 -0
  189. package/package.json +41 -39
  190. package/bin/arc-build.js +0 -139
  191. package/bin/arc-default.js +0 -65
  192. package/bin/arc-deploy.js +0 -456
  193. package/bin/arc-init.js +0 -187
  194. package/bin/arc-inspect.js +0 -97
  195. package/bin/arc-login.js +0 -165
  196. package/bin/arc-logout.js +0 -75
  197. package/bin/arc-open.js +0 -104
  198. package/bin/arc-pack.js +0 -146
  199. package/bin/arc-play.js +0 -140
  200. package/bin/arc-serve.js +0 -214
  201. package/bin/arc-validate.js +0 -112
  202. package/bin/arc-whoami.js +0 -119
  203. package/src/account.js +0 -249
  204. package/src/action/build/tool.js +0 -80
  205. package/src/action/deploy/tool-git.js +0 -90
  206. package/src/action/deploy/tool.js +0 -88
  207. package/src/action/deploy/wait.js +0 -151
  208. package/src/action/init/manifest.js +0 -83
  209. package/src/action/init/tool-patch.js +0 -32
  210. package/src/action/init/tool.js +0 -97
  211. package/src/action/inspect/tool.js +0 -26
  212. package/src/action/login/flow.js +0 -101
  213. package/src/action/login/tool.js +0 -16
  214. package/src/action/logout/tool.js +0 -15
  215. package/src/action/open/tool.js +0 -38
  216. package/src/action/pack/limits.js +0 -51
  217. package/src/action/pack/tool.js +0 -171
  218. package/src/action/pack/unsound.js +0 -69
  219. package/src/action/play/tool.js +0 -109
  220. package/src/action/predeploy/ac.js +0 -112
  221. package/src/action/predeploy/git.js +0 -223
  222. package/src/action/predeploy/pm.js +0 -37
  223. package/src/action/predeploy/published.js +0 -82
  224. package/src/action/predeploy/tool-git.js +0 -154
  225. package/src/action/predeploy/tool.js +0 -29
  226. package/src/action/serve/tool.js +0 -209
  227. package/src/action/validate/checked.js +0 -37
  228. package/src/action/validate/tool.js +0 -67
  229. package/src/action/validate/unknown.js +0 -86
  230. package/src/action/validate/unsound.js +0 -138
  231. package/src/action/whoami/tool.js +0 -15
  232. package/src/api.js +0 -163
  233. package/src/cli/build.js +0 -15
  234. package/src/cli/deploy.js +0 -21
  235. package/src/cli/init.js +0 -17
  236. package/src/cli/inspect.js +0 -15
  237. package/src/cli/login.js +0 -15
  238. package/src/cli/logout.js +0 -15
  239. package/src/cli/open.js +0 -15
  240. package/src/cli/pack.js +0 -15
  241. package/src/cli/play.js +0 -15
  242. package/src/cli/predeploy.js +0 -21
  243. package/src/cli/serve.js +0 -15
  244. package/src/cli/validate.js +0 -15
  245. package/src/cli/whoami.js +0 -15
  246. package/src/config/ai.js +0 -5
  247. package/src/config/art.js +0 -16
  248. package/src/config/audience.js +0 -5
  249. package/src/config/code.js +0 -142
  250. package/src/config/file.js +0 -23
  251. package/src/config/genre.js +0 -22
  252. package/src/config/image.js +0 -7
  253. package/src/config/input.js +0 -14
  254. package/src/config/limit.js +0 -21
  255. package/src/config/orientation.js +0 -14
  256. package/src/config/package.js +0 -5
  257. package/src/config/product.js +0 -5
  258. package/src/config/template.js +0 -45
  259. package/src/config/uri.js +0 -27
  260. package/src/config/url.js +0 -20
  261. package/src/config/video.js +0 -7
  262. package/src/config/visibility.js +0 -5
  263. package/src/config/workflow.js +0 -18
  264. package/src/parser/env.js +0 -84
  265. package/src/parser/given.js +0 -17
  266. package/src/parser/manifest.js +0 -80
  267. package/src/parser/media.js +0 -90
  268. package/src/parser/project.js +0 -166
  269. package/src/parser/readme-file.js +0 -76
  270. package/src/parser/readme.js +0 -96
  271. package/src/parser/sections.js +0 -107
  272. package/src/parser/self.js +0 -27
  273. package/src/phrase.js +0 -1294
  274. package/src/schema/check/game.js +0 -61
  275. package/src/schema/check/workflow.js +0 -99
  276. package/src/schema/game.js +0 -649
  277. package/src/schema/message.js +0 -85
  278. package/src/schema/readme.js +0 -44
  279. package/src/schema/workflow.js +0 -150
  280. package/src/serve/files.js +0 -61
  281. package/src/serve/game.js +0 -191
  282. package/src/serve/page.js +0 -345
  283. package/src/serve/reload.js +0 -68
  284. package/src/serve/remote.js +0 -121
  285. package/src/serve/server.js +0 -128
  286. package/src/util/argv.js +0 -116
  287. package/src/util/bytes.js +0 -25
  288. package/src/util/chars.js +0 -30
  289. package/src/util/command.js +0 -18
  290. package/src/util/delay.js +0 -52
  291. package/src/util/doc.js +0 -72
  292. package/src/util/error.js +0 -50
  293. package/src/util/http.js +0 -25
  294. package/src/util/image.js +0 -93
  295. package/src/util/links.js +0 -78
  296. package/src/util/lockfile.js +0 -35
  297. package/src/util/log.js +0 -149
  298. package/src/util/md.js +0 -61
  299. package/src/util/media.js +0 -40
  300. package/src/util/objs.js +0 -45
  301. package/src/util/os.js +0 -27
  302. package/src/util/output.js +0 -174
  303. package/src/util/paths.js +0 -21
  304. package/src/util/progress.js +0 -85
  305. package/src/util/promise.js +0 -29
  306. package/src/util/rc.js +0 -144
  307. package/src/util/request.js +0 -89
  308. package/src/util/s3.js +0 -92
  309. package/src/util/schema.js +0 -189
  310. package/src/util/screenshot.js +0 -37
  311. package/src/util/shell.js +0 -84
  312. package/src/util/size.js +0 -53
  313. package/src/util/spinner.js +0 -52
  314. package/src/util/strs.js +0 -73
  315. package/src/util/term.js +0 -28
  316. package/src/util/time.js +0 -29
  317. package/src/util/toml.js +0 -14
  318. package/src/util/video.js +0 -157
  319. package/src/util/zip.js +0 -88
  320. /package/{src/serve → assets}/favicon.ico +0 -0
package/README.md CHANGED
@@ -50,6 +50,7 @@ Your repository is the store page: `arcadible.toml` holds the game's settings, `
50
50
  | `arc deploy` | Validates, builds, packages, and publishes, directly or through GitHub Actions |
51
51
  | `arc play` | Plays a deployed game from any channel or version |
52
52
  | `arc open` | Opens a game's store page |
53
+ | `arc delete` | Deletes the project's game from Arcadible, for good, asking first |
53
54
  | `arc login` | Logs in to Arcadible with a device code |
54
55
  | `arc logout` | Logs out |
55
56
  | `arc whoami` | Shows the account you're logged in to |
package/bin/arc.js CHANGED
@@ -1,86 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
-
4
- // [import]
5
-
6
- const fs = require("fs-extra");
7
-
8
- // [import]
9
-
10
- const cfgpackage = require("../src/config/package");
11
- const cfgproduct = require("../src/config/product");
12
- const log = require("../src/util/log");
13
- const phrase = require("../src/phrase");
14
-
15
- // [use]
16
-
17
- const pathExists = fs.pathExists;
18
- const realpath = fs.realpath;
19
-
20
- // [declare]
21
-
22
- const BIN = cfgpackage.bin;
23
- const TOOL = cfgproduct.tool;
24
-
25
- // [function]
26
-
27
- const dispatch = function (argv) {
28
- const args = [...argv];
29
- const subcmds = Object.keys(BIN)
30
- .filter((key) => key !== TOOL)
31
- .map((key) => key.slice(TOOL.length + 1));
32
- if (!subcmds.includes(args[2])) {
33
- args.splice(2, 0, "default");
34
- }
35
- return args;
36
- };
37
-
38
- // [function]
39
-
40
- const normalize = function (argv) {
41
- const args = [...argv];
42
- args[1] = args[1].endsWith(".js")
43
- ? args[1].replace(/\.js$/u, `-${args[2]}.js`)
44
- : args[1].concat(`-${args[2]}`);
45
- args.splice(2, 1);
46
- return args;
47
- };
48
-
49
- // [function]
50
-
51
- // the script's own path, through any links: npm links only package.json's
52
- // `bin` entries, so a command's sibling, such as `arc-default`, is found
53
- // beside the real script, not beside the link that started it.
54
- const resolve = function (argv) {
55
- // left as it is when it can't be resolved, and reported as not found
56
- return realpath(argv[1])
57
- .catch(() => argv[1])
58
- .then((file) => [argv[0], file, ...argv.slice(2)]);
59
- };
60
-
61
- // [function]
62
-
63
- const main = function (argv, load) {
64
- return resolve(argv).then((resolved) => {
65
- const args = normalize(dispatch(resolved));
66
- pathExists(args[1], (err, exists) => {
67
- if (err || !exists) {
68
- log.hd(phrase.aborted("command"));
69
- log.pd(phrase.unableToFind(args[1]));
70
- process.exit(1);
71
- }
72
- const command = load(args[1]);
73
- command.main(args);
74
- });
75
- });
76
- };
77
-
78
- // [start]
79
-
80
- if (require.main === module) {
81
- main(process.argv, require);
82
- }
83
-
84
- // [export]
85
-
86
- module.exports = { main };
2
+ import "../dist/arc.js";
@@ -0,0 +1,197 @@
1
+ // [import]
2
+ import { chmod, mkdir, readFile, unlink, writeFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ // [import]
5
+ import { auth, postAuthLogout, postAuthRefresh, } from "./api.js";
6
+ import { SESSION_EXPIRED } from "./config/code.js";
7
+ import { ArcError } from "./util/error.js";
8
+ import { HttpError } from "./util/http.js";
9
+ import { sessionExpired } from "./phrase/index.js";
10
+ import { deepSort, isTable } from "./util/objs.js";
11
+ import { configDir } from "./util/os.js";
12
+ import { title, tool } from "./config/product.js";
13
+ // [declare]
14
+ const DIR_MODE = 0o700;
15
+ const FILE = "account.json";
16
+ const FILE_MODE = 0o600;
17
+ // [declare]
18
+ // the statuses that mean the refresh token itself was refused.
19
+ const REJECTED = [400, 401, 403];
20
+ // [declare]
21
+ const TOKEN_USER = { display_name: `${title} Token`, id: null };
22
+ const TOOL = tool;
23
+ // [define]
24
+ const dir = join(configDir(), TOOL);
25
+ const file = join(dir, FILE);
26
+ // [function]
27
+ // whether a failure is the file system's, with this code, such as ENOENT.
28
+ function isCode(ex, code) {
29
+ return isTable(ex) && ex["code"] === code;
30
+ }
31
+ // [function]
32
+ function expired(session) {
33
+ // a session without an expiry never compares as expired, as the first
34
+ // CLI's `undefined <= …` didn't.
35
+ return Number(session.expires_at) <= Math.floor(Date.now() / 1000) + 60;
36
+ }
37
+ // [function]
38
+ // the session is a credential, so only its owner can read it: the directory
39
+ // is 0700 and the file 0600. `mode` only applies when a file is created, so
40
+ // both are also set on every save, which fixes an older, readable file. The
41
+ // modes are ignored on Windows, where %LOCALAPPDATA% is already private.
42
+ export function save(current) {
43
+ return mkdir(dir, { mode: DIR_MODE, recursive: true })
44
+ .then(() => chmod(dir, DIR_MODE))
45
+ .then(() => writeFile(file, JSON.stringify(deepSort(current), null, 2), {
46
+ encoding: "utf8",
47
+ mode: FILE_MODE,
48
+ }))
49
+ .then(() => chmod(file, FILE_MODE))
50
+ .then(() => current);
51
+ }
52
+ // [function]
53
+ export function remove() {
54
+ return unlink(file).catch((ex) => {
55
+ if (isCode(ex, "ENOENT")) {
56
+ return;
57
+ }
58
+ throw ex;
59
+ });
60
+ }
61
+ // [function]
62
+ // the error for a session that can't be used again, once it's removed, so
63
+ // arc whoami no longer names its account.
64
+ function expire(ex) {
65
+ return remove().then(() => {
66
+ throw new ArcError(SESSION_EXPIRED, sessionExpired(), {
67
+ cause: ex,
68
+ });
69
+ });
70
+ }
71
+ // [function]
72
+ // renews the session. When the refresh token is rejected, the session can't
73
+ // be used again: it's removed, and the error says to log in.
74
+ function refresh({ session, ...current }) {
75
+ const form = new FormData();
76
+ form.append("refresh_token", String(session.refresh_token));
77
+ return postAuthRefresh(form).then((data) => save({ ...current, session: data }), (ex) => {
78
+ if (ex instanceof HttpError && REJECTED.includes(ex.status)) {
79
+ return expire(ex);
80
+ }
81
+ throw ex;
82
+ });
83
+ }
84
+ // [function]
85
+ // the saved file as an account, when it holds a session: the file is the
86
+ // CLI's own, as `save` wrote it, so what its session and user hold is taken
87
+ // as it is.
88
+ function isAccount(saved) {
89
+ return isTable(saved) && isTable(saved["session"]);
90
+ }
91
+ // [function]
92
+ // the saved file as it is, or null when there's none.
93
+ function readSaved() {
94
+ return readFile(file, "utf8")
95
+ .then((text) => JSON.parse(text))
96
+ .catch((ex) => {
97
+ // a session file cut short (a full disk, a crash while saving) is no
98
+ // session: `arc login` writes a new one
99
+ if (isCode(ex, "ENOENT") || ex instanceof SyntaxError) {
100
+ return null;
101
+ }
102
+ throw ex;
103
+ });
104
+ }
105
+ // [function]
106
+ function getSaved(onRefresh) {
107
+ return readSaved().then((current) => {
108
+ if (!isAccount(current)) {
109
+ return null;
110
+ }
111
+ if (!expired(current.session)) {
112
+ return current;
113
+ }
114
+ // the handler starts its spinner, then refreshes.
115
+ return onRefresh ? onRefresh(() => refresh(current)) : null;
116
+ });
117
+ }
118
+ // [function]
119
+ // the account an ARCADIBLE_TOKEN stands for. The API doesn't describe a
120
+ // token's user yet, so this is a placeholder with a real user's shape, to be
121
+ // replaced by the API's answer without changing it.
122
+ function fromToken(token) {
123
+ return { session: { access_token: token }, token: true, user: TOKEN_USER };
124
+ }
125
+ // [function]
126
+ // the account commands use: ARCADIBLE_TOKEN when it's set, which takes
127
+ // precedence over the saved session, or else the saved session, refreshed if
128
+ // needed.
129
+ export function get(onRefresh) {
130
+ const token = process.env["ARCADIBLE_TOKEN"];
131
+ if (token) {
132
+ return Promise.resolve(fromToken(token));
133
+ }
134
+ return getSaved(onRefresh);
135
+ }
136
+ // [function]
137
+ // a failed request's handler for commands that send the saved session's
138
+ // token. The API refuses it (401) only when Supabase does: for a deleted
139
+ // account, or a token that expired by the server's clock though not by
140
+ // this one's. A refresh tells them apart: refused, the session is over, so
141
+ // it's removed and the error says to log in (session_expired); renewed, the
142
+ // session is kept, and the request's own error stands, so running the
143
+ // command again works. An ARCADIBLE_TOKEN's refusal stays as it is, since
144
+ // logging in doesn't change the token.
145
+ export function ended(current) {
146
+ return (ex) => {
147
+ if (!current?.session ||
148
+ current.token ||
149
+ !(ex instanceof HttpError) ||
150
+ ex.status !== 401) {
151
+ throw ex;
152
+ }
153
+ return refresh(current).then(() => {
154
+ throw ex;
155
+ }, (refreshEx) => {
156
+ throw refreshEx instanceof ArcError ? refreshEx : ex;
157
+ });
158
+ };
159
+ }
160
+ // [function]
161
+ // an access token for the saved session to end with: its own, or a refreshed
162
+ // one when it's expired, which isn't saved, since the session is ending.
163
+ function accessToken(session) {
164
+ if (!expired(session)) {
165
+ return Promise.resolve(session.access_token);
166
+ }
167
+ const form = new FormData();
168
+ form.append("refresh_token", String(session.refresh_token));
169
+ return postAuthRefresh(form).then((data) => data.access_token);
170
+ }
171
+ // [function]
172
+ function revoke(session) {
173
+ return accessToken(session).then((access) => postAuthLogout(null, auth(access)));
174
+ }
175
+ // [function]
176
+ // a logout: the saved session ended on the server, so its refresh token stops
177
+ // working, then removed. Never an error: a refused refresh means the session
178
+ // was already over, and a failure to reach the API (offline, an outage)
179
+ // leaves it to expire after 90 idle days, while the file is removed either
180
+ // way. It ends only the saved session: never an ARCADIBLE_TOKEN, nor any
181
+ // other session. It resolves with the user whose session it was, or null
182
+ // when there was none to end.
183
+ export function end() {
184
+ return readSaved()
185
+ .then((current) => {
186
+ if (!isAccount(current)) {
187
+ return null;
188
+ }
189
+ const user = isTable(current.user) ? current.user : null;
190
+ if (!current.session.refresh_token) {
191
+ return user;
192
+ }
193
+ return revoke(current.session).then(() => user, () => user);
194
+ })
195
+ .catch(() => null)
196
+ .then((user) => remove().then(() => user));
197
+ }
@@ -0,0 +1,61 @@
1
+ // [import]
2
+ import cp from "node:child_process";
3
+ import { resolve as resolvePath } from "node:path";
4
+ // [import]
5
+ import { pathExists } from "fs-extra";
6
+ // [import]
7
+ import { BUILT, bundle } from "../../runner/bundle.js";
8
+ import { BUILD_FAILED } from "../../config/code.js";
9
+ import { buildCommand } from "../../util/command.js";
10
+ import { ArcError } from "../../util/error.js";
11
+ import * as phrase from "../../phrase/index.js";
12
+ // [function]
13
+ // a build's output has no limit: exec's default maxBuffer, 1 MB, would kill a
14
+ // verbose build that otherwise succeeds. `exec` is called through the module,
15
+ // so the tests' fake of it applies.
16
+ function execBuild(command, { cwdPath }) {
17
+ return new Promise((resolve, reject) => {
18
+ cp.exec(command, { cwd: cwdPath, maxBuffer: Infinity }, (err, stdout, stderr) => {
19
+ if (err) {
20
+ const { code, signal } = err;
21
+ reject(new ArcError(BUILD_FAILED, phrase.buildFailed({ code, signal, stderr, stdout }), { cause: err }));
22
+ return;
23
+ }
24
+ resolve();
25
+ });
26
+ });
27
+ }
28
+ // [function]
29
+ // runs the build, and resolves with deploy_dir's path. It resolves with null
30
+ // when there's no build to run, and with `{ missing }` when the build ran but
31
+ // didn't create deploy_dir.
32
+ function build(command, { cwdPath, outputPath }) {
33
+ return command
34
+ ? execBuild(command, { cwdPath })
35
+ .then(() => pathExists(outputPath))
36
+ .then((exists) => (exists ? { path: outputPath } : { missing: outputPath }))
37
+ : Promise.resolve(null);
38
+ }
39
+ // [function]
40
+ // the game's runner, bundled after the project's own build, which may have
41
+ // written the code it's made from: resolves with the bundle's path, or null
42
+ // for a game with none.
43
+ function buildRunner(root, main) {
44
+ return typeof main === "string"
45
+ ? bundle({
46
+ main: resolvePath(root, main),
47
+ outfile: resolvePath(root, BUILT),
48
+ })
49
+ : Promise.resolve(null);
50
+ }
51
+ // [function]
52
+ // builds the project: its own build, then its runner, when it has one. The
53
+ // result is the build's, with `function`, the bundle's path, beside it.
54
+ export async function buildTool({ project: { function: runner, workflow }, root, }) {
55
+ const artifact = await build(buildCommand(workflow.build), {
56
+ cwdPath: root,
57
+ outputPath: resolvePath(root, workflow.deploy_dir),
58
+ });
59
+ const bundled = await buildRunner(root, runner?.main);
60
+ return bundled ? { ...artifact, function: bundled } : artifact;
61
+ }
@@ -0,0 +1,47 @@
1
+ // deleting a game: the project's own, on Arcadible, by its owner. It's gone
2
+ // for players at once, with every build, and it can't be undone. Nothing in
3
+ // the project changes.
4
+ import { deleteGame } from "../../api.js";
5
+ import { GAME_ID_MISSING, GAME_UNAVAILABLE } from "../../config/code.js";
6
+ import { ArcError } from "../../util/error.js";
7
+ import { headersOf, isStatus } from "../game.js";
8
+ import { given } from "../../parser/given.js";
9
+ import { gameIdMissing, gameUndeletable } from "../../phrase/index.js";
10
+ import { textOf } from "../../util/objs.js";
11
+ // [function]
12
+ // a value of the manifest's as a name, when it's text with something in it.
13
+ function text(value) {
14
+ return typeof value === "string" && value.trim() ? value.trim() : null;
15
+ }
16
+ // [function]
17
+ // the game the project names, which must have an id: a game is deleted by
18
+ // its id, never by a handle, which another game could come to hold.
19
+ export function named(conf) {
20
+ return given(conf).then(({ game }) => {
21
+ if (!game.id) {
22
+ throw new ArcError(GAME_ID_MISSING, gameIdMissing());
23
+ }
24
+ const id = textOf(game.id);
25
+ return { id, title: text(game.title) ?? text(game.handle) ?? id };
26
+ });
27
+ }
28
+ // [function]
29
+ // deletes the game, as the logged-in account, and resolves with `{ game }`,
30
+ // its id. One the API doesn't find for this account (never deployed, deleted
31
+ // already, or another account's) is unavailable, as it is to the other
32
+ // commands a game's owner runs.
33
+ export async function deleteTool(current, { id }) {
34
+ const headers = headersOf(current);
35
+ try {
36
+ await deleteGame(id, null, headers);
37
+ return { game: id };
38
+ }
39
+ catch (err) {
40
+ if (isStatus(err, 404)) {
41
+ throw new ArcError(GAME_UNAVAILABLE, gameUndeletable(id), {
42
+ cause: err,
43
+ });
44
+ }
45
+ throw err;
46
+ }
47
+ }
@@ -0,0 +1,25 @@
1
+ // the project once arc deploy's build has run.
2
+ import { VALIDATION_FAILED } from "../../config/code.js";
3
+ import { ArcError } from "../../util/error.js";
4
+ import { issuesAfterBuild } from "../../phrase/index.js";
5
+ import { project } from "../../parser/project.js";
6
+ import { validateTool } from "../validate/tool.js";
7
+ // [function]
8
+ // whether a project is checked, which it is when validating it found no
9
+ // issues (action/validate/checked.ts).
10
+ function isChecked(_parsed, issues) {
11
+ return !issues.length;
12
+ }
13
+ // [function]
14
+ // A build can write files the manifest reads, such as art, so the project is
15
+ // parsed and validated again after one runs: resolves with it, or rejects as
16
+ // validation_failed with its issues in `data`. Its warnings aren't listed
17
+ // again.
18
+ export async function rebuilt(root) {
19
+ const parsed = await project(root);
20
+ const validated = await validateTool({ project: parsed, root });
21
+ if (!isChecked(parsed, validated.issues)) {
22
+ throw new ArcError(VALIDATION_FAILED, issuesAfterBuild(validated.issues.length), { data: { issues: validated.issues } });
23
+ }
24
+ return parsed;
25
+ }
@@ -0,0 +1,36 @@
1
+ // what arc deploy prints of a deploy and its release.
2
+ import { published } from "../../util/links.js";
3
+ // [function]
4
+ // what the deploy prints. The game and release are for waiting, not
5
+ // printing. `held` when the handle rules held the handle back from this
6
+ // release, so the game's links are by id.
7
+ export function resultOf(deployed, { built, git, held, warnings, }) {
8
+ const { channel, store, url } = held
9
+ ? published({ id: deployed.game, version: deployed.version.to })
10
+ : deployed;
11
+ return {
12
+ ...(git ? {} : { built }),
13
+ channel,
14
+ store,
15
+ ...("tag" in deployed ? { tag: deployed.tag } : {}),
16
+ url,
17
+ version: deployed.version,
18
+ warnings,
19
+ };
20
+ }
21
+ // [function]
22
+ // the release, as `--json` prints it.
23
+ export function releaseJson(row) {
24
+ if (!row) {
25
+ return null;
26
+ }
27
+ return {
28
+ build: row.build,
29
+ channel: row.channel,
30
+ id: row.id,
31
+ message: row.message,
32
+ reason: row.reason,
33
+ status: row.status,
34
+ version: row.version,
35
+ };
36
+ }
@@ -0,0 +1,18 @@
1
+ // arc deploy's `--timeout`: how long `--wait` waits, and what it may be.
2
+ // [import]
3
+ import { ARGUMENT_INVALID } from "../../config/code.js";
4
+ import { ArcError } from "../../util/error.js";
5
+ import { timeoutInvalid } from "../../phrase/index.js";
6
+ // [declare]
7
+ // how long `--wait` waits, in seconds. A git release waits on its GitHub
8
+ // workflow first.
9
+ export const TIMEOUT = { direct: 300, git: 900 };
10
+ // [function]
11
+ // fails unless the timeout is a number of seconds above 0: otherwise the
12
+ // wait would never end.
13
+ export function checkTimeout(timeout) {
14
+ if (Number.isFinite(timeout) && timeout > 0) {
15
+ return Promise.resolve();
16
+ }
17
+ return Promise.reject(new ArcError(ARGUMENT_INVALID, timeoutInvalid()));
18
+ }
@@ -0,0 +1,49 @@
1
+ // [import]
2
+ import { GIT_TAG_CREATE_FAILED, GIT_TAG_PUSH_FAILED, } from "../../config/code.js";
3
+ import { ArcError } from "../../util/error.js";
4
+ import { releasing } from "../predeploy/game.js";
5
+ import { git, stderrOf, tagOf } from "../predeploy/git.js";
6
+ import { gitTagCreateFailed, gitTagPushFailed, versionPrerelease, versionRelease, } from "../../phrase/index.js";
7
+ import { channel, PRODUCTION, published, } from "../../util/links.js";
8
+ // [function]
9
+ function createTag(root, version) {
10
+ const message = channel(version) === PRODUCTION
11
+ ? versionRelease(version)
12
+ : versionPrerelease(version);
13
+ return git(root, ["tag", "-a", tagOf(version), "-m", message]).then(() => null, (err) => {
14
+ throw new ArcError(GIT_TAG_CREATE_FAILED, gitTagCreateFailed(version, stderrOf(err)), { cause: err });
15
+ });
16
+ }
17
+ // [function]
18
+ // deletes the local tag, then fails with `failed` whether or not it could.
19
+ function untag(root, version, failed) {
20
+ const fail = () => {
21
+ throw failed;
22
+ };
23
+ return git(root, ["tag", "-d", tagOf(version)]).then(fail, fail);
24
+ }
25
+ // [function]
26
+ // the local tag is deleted when the push fails, so trying again isn't
27
+ // blocked by a tag that was never released.
28
+ function pushTag(root, version) {
29
+ return git(root, ["push", "origin", tagOf(version)]).then(() => null, (err) => untag(root, version, new ArcError(GIT_TAG_PUSH_FAILED, gitTagPushFailed(version, stderrOf(err)), {
30
+ cause: err,
31
+ })));
32
+ }
33
+ // [function]
34
+ // tags the version and pushes the tag: the Arcadible GitHub App publishes
35
+ // the release that the workflow builds from it.
36
+ export function deployToolGit(conf, { onDeployBegin }) {
37
+ if (onDeployBegin) {
38
+ onDeployBegin();
39
+ }
40
+ const game = releasing(conf.project.game);
41
+ return createTag(conf.root, game.version)
42
+ .then(() => pushTag(conf.root, game.version))
43
+ .then(() => ({
44
+ ...published(game),
45
+ game: game.id,
46
+ tag: tagOf(game.version),
47
+ version: { to: game.version },
48
+ }));
49
+ }
@@ -0,0 +1,49 @@
1
+ // [import]
2
+ import { auth, postUpload } from "../../api.js";
3
+ import { DEPLOY_RATE_LIMITED, GAME_UNAVAILABLE } from "../../config/code.js";
4
+ import { ArcError } from "../../util/error.js";
5
+ import { releasing } from "../predeploy/game.js";
6
+ import { HttpError } from "../../util/http.js";
7
+ import { deployRateLimited, gameUnavailable } from "../../phrase/index.js";
8
+ import { published } from "../../util/links.js";
9
+ import { upload as s3Upload } from "../../util/s3.js";
10
+ // [function]
11
+ // asks the API for an upload link, then sends the zip to it, and resolves
12
+ // with the upload.
13
+ function uploadBuild(current, artifact, { id, version }, onProgress) {
14
+ const form = new FormData();
15
+ form.append("artifact", id);
16
+ form.append("version", version);
17
+ form.append("sha256", artifact.sha256);
18
+ form.append("size", String(artifact.size));
19
+ return postUpload(form, null, auth(current?.session.access_token)).then((upload) => s3Upload(upload.upload_url, artifact, onProgress).then(() => upload), (err) => {
20
+ // the API refuses a game that was deleted or is another account's
21
+ // (403), and the same version deployed again within 5 minutes (429).
22
+ if (err instanceof HttpError && err.status === 403) {
23
+ throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
24
+ cause: err,
25
+ });
26
+ }
27
+ if (err instanceof HttpError && err.status === 429) {
28
+ throw new ArcError(DEPLOY_RATE_LIMITED, deployRateLimited(version), {
29
+ cause: err,
30
+ });
31
+ }
32
+ throw err;
33
+ });
34
+ }
35
+ // [function]
36
+ export function deployTool(current, artifact, conf, { onDeployBegin, onUploadProgress }) {
37
+ if (onDeployBegin) {
38
+ onDeployBegin({ root: conf.root });
39
+ }
40
+ const game = releasing(conf.project.game);
41
+ return uploadBuild(current, artifact, game, onUploadProgress).then((upload) => ({
42
+ ...published(game),
43
+ game: game.id,
44
+ // a direct deploy's release shares its upload's id, which `--wait`
45
+ // follows.
46
+ release: upload.id,
47
+ version: { to: game.version },
48
+ }));
49
+ }