arcadible 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  <h1 align="center">Arcadible CLI</h1>
8
8
 
9
9
  <p align="center">
10
- Create, play, and share games made with AI.
10
+ Ship your game to players in one command.
11
11
  </p>
12
12
 
13
13
  <p align="center">
package/package.json CHANGED
@@ -65,5 +65,5 @@
65
65
  "scripts": {
66
66
  "test": "node --test \"test/**/*.test.js\""
67
67
  },
68
- "version": "1.0.5"
68
+ "version": "1.0.7"
69
69
  }
package/src/account.js CHANGED
@@ -14,6 +14,7 @@ const api = require("./api");
14
14
  const cfgcode = require("./config/code");
15
15
  const cfgproduct = require("./config/product");
16
16
  const error = require("./util/error");
17
+ const http = require("./util/http");
17
18
  const objs = require("./util/objs");
18
19
  const os = require("./util/os");
19
20
  const phrase = require("./phrase");
@@ -24,6 +25,7 @@ const ArcError = error.ArcError;
24
25
  const chmod = fs.promises.chmod;
25
26
  const configDir = os.configDir;
26
27
  const deepSort = objs.deepSort;
28
+ const HttpError = http.HttpError;
27
29
  const join = path.join;
28
30
  const mkdir = fs.promises.mkdir;
29
31
  const readFile = fs.promises.readFile;
@@ -78,8 +80,31 @@ const save = function (current) {
78
80
 
79
81
  // [function]
80
82
 
83
+ const remove = function () {
84
+ return unlink(file).catch((ex) => {
85
+ if (ex.code === "ENOENT") {
86
+ return;
87
+ }
88
+ throw ex;
89
+ });
90
+ };
91
+
92
+ // [function]
93
+
94
+ // the error for a session that can't be used again, once it's removed, so
95
+ // arc whoami no longer names its account.
96
+ const expire = function (ex) {
97
+ return remove().then(() => {
98
+ throw new ArcError(cfgcode.SESSION_EXPIRED, phrase.sessionExpired(), {
99
+ cause: ex,
100
+ });
101
+ });
102
+ };
103
+
104
+ // [function]
105
+
81
106
  // renews the session. When the refresh token is rejected, the session can't
82
- // be used again, and the error says to log in.
107
+ // be used again: it's removed, and the error says to log in.
83
108
  const refresh = function ({ session, ...current }) {
84
109
  const form = new FormData();
85
110
  form.append("refresh_token", session.refresh_token);
@@ -87,9 +112,7 @@ const refresh = function ({ session, ...current }) {
87
112
  (data) => save({ ...current, session: data }),
88
113
  (ex) => {
89
114
  if (REJECTED.includes(ex.status)) {
90
- throw new ArcError(cfgcode.SESSION_EXPIRED, phrase.sessionExpired(), {
91
- cause: ex,
92
- });
115
+ return expire(ex);
93
116
  }
94
117
  throw ex;
95
118
  },
@@ -144,15 +167,25 @@ const get = function (onRefresh) {
144
167
 
145
168
  // [function]
146
169
 
147
- const remove = function () {
148
- return unlink(file).catch((ex) => {
149
- if (ex.code === "ENOENT") {
150
- return;
170
+ // a failed request's handler for commands that send the saved session's
171
+ // token: the API refuses it (401) only when Supabase does, such as for a
172
+ // deleted account, so the session is over. It's removed, and the error says
173
+ // to log in, rather than api_refused. An ARC_TOKEN's refusal stays as it is,
174
+ // since logging in doesn't change the token.
175
+ const ended = function (current) {
176
+ return (ex) => {
177
+ if (
178
+ !current?.session ||
179
+ current.token ||
180
+ !(ex instanceof HttpError) ||
181
+ ex.status !== 401
182
+ ) {
183
+ throw ex;
151
184
  }
152
- throw ex;
153
- });
185
+ return expire(ex);
186
+ };
154
187
  };
155
188
 
156
189
  // [export]
157
190
 
158
- module.exports = { get, remove, save };
191
+ module.exports = { ended, get, remove, save };
@@ -6,10 +6,12 @@ const api = require("../../api");
6
6
  const delay = require("../../util/delay");
7
7
  const links = require("../../util/links");
8
8
  const repo = require("../predeploy/git");
9
+ const saved = require("../../account");
9
10
  const time = require("../../util/time");
10
11
 
11
12
  // [use]
12
13
 
14
+ const ended = saved.ended;
13
15
  const git = repo.git;
14
16
  const sleep = delay.sleep;
15
17
  const studioUrl = links.studioUrl;
@@ -146,12 +148,14 @@ const main = function (
146
148
  return Promise.all([
147
149
  pollRelease(find, timeout, onRelease),
148
150
  isGit ? actionsUrl(root) : null,
149
- ]).then(([{ release, timedOut }, actions]) => ({
150
- actions,
151
- release,
152
- studio: owns ? studioUrl(game, "builds") : null,
153
- timedOut,
154
- }));
151
+ ])
152
+ .then(([{ release, timedOut }, actions]) => ({
153
+ actions,
154
+ release,
155
+ studio: owns ? studioUrl(game, "builds") : null,
156
+ timedOut,
157
+ }))
158
+ .catch(ended(current));
155
159
  };
156
160
 
157
161
  // [export]
package/src/cli/deploy.js CHANGED
@@ -2,15 +2,18 @@
2
2
 
3
3
  // [import]
4
4
 
5
+ const account = require("../account");
5
6
  const deployTool = require("../action/deploy/tool");
6
7
  const deployToolGit = require("../action/deploy/tool-git");
7
8
 
8
9
  // [function]
9
10
 
10
11
  const main = function ({ artifact, current, git, handler, ...conf }) {
11
- return git
12
- ? deployToolGit(conf, handler)
13
- : deployTool(current, artifact, conf, handler);
12
+ return (
13
+ git
14
+ ? deployToolGit(conf, handler)
15
+ : deployTool(current, artifact, conf, handler)
16
+ ).catch(account.ended(current));
14
17
  };
15
18
 
16
19
  // [export]
@@ -2,15 +2,18 @@
2
2
 
3
3
  // [import]
4
4
 
5
+ const account = require("../account");
5
6
  const predeployTool = require("../action/predeploy/tool");
6
7
  const predeployToolGit = require("../action/predeploy/tool-git");
7
8
 
8
9
  // [function]
9
10
 
10
11
  const main = function ({ current, git, handler, ...conf }) {
11
- return git
12
- ? predeployToolGit(conf, handler)
13
- : predeployTool(current, conf, handler);
12
+ return (
13
+ git
14
+ ? predeployToolGit(conf, handler)
15
+ : predeployTool(current, conf, handler)
16
+ ).catch(account.ended(current));
14
17
  };
15
18
 
16
19
  // [export]