arcadible 1.0.36 → 1.0.38
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 +1 -1
- package/dist/action/build/tool.js +57 -8
- package/dist/action/function/logs.js +1 -1
- package/dist/action/login/flow.js +8 -1
- package/dist/action/pack/limits.js +28 -4
- package/dist/action/pack/tool.js +2 -1
- package/dist/action/secret/tool.js +3 -5
- package/dist/action/serve/tool.js +28 -21
- package/dist/action/value/tool.js +18 -12
- package/dist/action/wire/tool.js +1 -1
- package/dist/api.js +1 -1
- package/dist/arc.js +6 -2
- package/dist/cli/argv.js +3 -1
- package/dist/cli/command.js +12 -2
- package/dist/command/function/index.js +4 -5
- package/dist/command/function/logs.js +8 -1
- package/dist/command/function/pause.js +1 -1
- package/dist/command/function/resume.js +1 -1
- package/dist/command/function/run.js +1 -1
- package/dist/command/function/secret/index.js +1 -1
- package/dist/command/function/secret/remove.js +2 -2
- package/dist/command/function/secret/run.js +1 -1
- package/dist/command/function/secret/set.js +1 -1
- package/dist/command/{delete.js → game/delete.js} +14 -13
- package/dist/command/game/index.js +12 -0
- package/dist/command/login.js +1 -2
- package/dist/command/serve.js +9 -3
- package/dist/command/server/index.js +3 -4
- package/dist/command/server/key/create.js +1 -1
- package/dist/command/server/key/index.js +1 -1
- package/dist/command/server/key/revoke.js +1 -1
- package/dist/command/server/key/run.js +1 -1
- package/dist/command/unstable/index.js +23 -0
- package/dist/command/value/get.js +1 -1
- package/dist/command/value/index.js +6 -6
- package/dist/command/value/list.js +1 -1
- package/dist/command/value/remove.js +2 -2
- package/dist/command/value/set.js +1 -1
- package/dist/command/value/usage.js +5 -16
- package/dist/command/wire/index.js +4 -5
- package/dist/commands.js +3 -29
- package/dist/config/code.js +7 -3
- package/dist/config/limit.js +13 -0
- package/dist/phrase/deploy.js +1 -1
- package/dist/phrase/function.js +7 -7
- package/dist/phrase/game.js +1 -1
- package/dist/phrase/index.js +1 -0
- package/dist/phrase/pack.js +17 -0
- package/dist/phrase/serve.js +8 -3
- package/dist/phrase/server.js +5 -5
- package/dist/phrase/unstable.js +6 -0
- package/dist/phrase/value.js +30 -5
- package/dist/runner/bundle.js +13 -4
- package/dist/runner/entry.js +113 -17
- package/dist/runner/outbound.js +21 -5
- package/dist/schema/check/workflow.js +0 -21
- package/dist/schema/game.js +0 -32
- package/dist/schema/message.js +2 -3
- package/dist/schema/runner.js +8 -6
- package/dist/schema/workflow.js +6 -28
- package/dist/serve/page.js +1 -1
- package/dist/serve/remote.js +14 -6
- package/dist/serve/runner.js +89 -6
- package/dist/serve/server.js +8 -6
- package/dist/util/term.js +8 -0
- package/dist/util/zip.js +5 -0
- package/dist/wires/room.js +3 -3
- package/npm-shrinkwrap.json +33 -33
- package/package.json +1 -1
package/dist/phrase/value.js
CHANGED
|
@@ -5,9 +5,9 @@ export function valueKeyInvalid(key) {
|
|
|
5
5
|
return blocks(`Not a key: ${key}`, "A key is 1 to 128 letters, digits, -, _, ., and /.");
|
|
6
6
|
}
|
|
7
7
|
// [function]
|
|
8
|
-
// `arc value set` given neither a key nor a folder, or both.
|
|
8
|
+
// `arc unstable value set` given neither a key nor a folder, or both.
|
|
9
9
|
export function valueSetWhat() {
|
|
10
|
-
return blocks("Name a key, or a folder.", "`arc value set <key> --file value.json` sets one value, and `arc value set --dir .arcadible-data/values` sets a value for each .json file in a folder.");
|
|
10
|
+
return blocks("Name a key, or a folder.", "`arc unstable value set <key> --file value.json` sets one value, and `arc unstable value set --dir .arcadible-data/values` sets a value for each .json file in a folder.");
|
|
11
11
|
}
|
|
12
12
|
// [function]
|
|
13
13
|
// a value that isn't JSON: `source` is its file, or standard input.
|
|
@@ -27,8 +27,33 @@ export function valueTooLarge(key) {
|
|
|
27
27
|
return blocks(`Too large: ${key}`, "A value is up to 64 KB of JSON.");
|
|
28
28
|
}
|
|
29
29
|
// [function]
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
// a size in the unit that reads best: "0", "812 B", "14 KB", "2.4 MB".
|
|
31
|
+
export function valueSize(bytes) {
|
|
32
|
+
if (bytes < 1024) {
|
|
33
|
+
return bytes === 0 ? "0" : `${bytes} B`;
|
|
34
|
+
}
|
|
35
|
+
if (bytes < 1024 * 1024) {
|
|
36
|
+
return `${Math.round(bytes / 1024)} KB`;
|
|
37
|
+
}
|
|
38
|
+
return `${(bytes / (1024 * 1024)).toFixed(1).replace(/\.0$/u, "")} MB`;
|
|
39
|
+
}
|
|
40
|
+
// [function]
|
|
41
|
+
// what a scope may hold, as the API states it (null is no limit): "10,000
|
|
42
|
+
// keys, 64 MB", or "no limit".
|
|
43
|
+
export function valueHolds({ bytes_limit: bytes, keys_limit: keys, }) {
|
|
44
|
+
if (keys === null && bytes === null) {
|
|
45
|
+
return "no limit";
|
|
46
|
+
}
|
|
47
|
+
return `${keys === null ? "any number of" : keys.toLocaleString("en-US")} keys, ${bytes === null ? "any size" : valueSize(bytes)}`;
|
|
48
|
+
}
|
|
49
|
+
// [function]
|
|
50
|
+
// the developer's values on `channel` full, with what they may hold, the
|
|
51
|
+
// account's plan's, when the API could say.
|
|
52
|
+
export function valueFull(channel, holds) {
|
|
53
|
+
const remove = "Remove some with `arc unstable value remove <key>`, then try again.";
|
|
54
|
+
return blocks(`The developer's values on ${channel} are full.`, holds === null
|
|
55
|
+
? `${remove}\n\`arc unstable value usage\` shows what they hold.`
|
|
56
|
+
: `They may hold ${holds}. ${remove}`);
|
|
32
57
|
}
|
|
33
58
|
// [function]
|
|
34
59
|
export function valueSet({ channel, keys, }) {
|
|
@@ -39,7 +64,7 @@ export function valueSet({ channel, keys, }) {
|
|
|
39
64
|
}
|
|
40
65
|
// [function]
|
|
41
66
|
export function valueNotFound({ channel, key, }) {
|
|
42
|
-
return blocks(`Value not found: ${key}`, `It isn't set on ${channel}.\n\`arc value list --${channel}\` shows what is.`);
|
|
67
|
+
return blocks(`Value not found: ${key}`, `It isn't set on ${channel}.\n\`arc unstable value list --${channel}\` shows what is.`);
|
|
43
68
|
}
|
|
44
69
|
// [function]
|
|
45
70
|
export function valueRemoveQuestion({ channel, key, }) {
|
package/dist/runner/bundle.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// a game's
|
|
1
|
+
// a game's function, bundled: its server code (plan/SERVERS.md, Runners) with
|
|
2
2
|
// what it imports, as one module whose default export is the developer's
|
|
3
3
|
// handler. It's the developer's code alone: Arcadible's entry, which is
|
|
4
4
|
// where a function's script starts, is added beside it where it runs, by
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// build carries an entry of the day its `arc` was installed.
|
|
7
7
|
// [import]
|
|
8
8
|
import { stat } from "node:fs/promises";
|
|
9
|
-
import { join } from "node:path";
|
|
9
|
+
import { join, resolve } from "node:path";
|
|
10
10
|
// [import]
|
|
11
11
|
import { build } from "esbuild";
|
|
12
12
|
import { pathExists } from "fs-extra";
|
|
@@ -41,7 +41,11 @@ export const WRONG = {
|
|
|
41
41
|
// finds is a warning, a warning has a code, and a code has an entry on the
|
|
42
42
|
// public Errors page, which says nothing of functions until they ship
|
|
43
43
|
// (TODO.md, Agreed next).
|
|
44
|
-
|
|
44
|
+
//
|
|
45
|
+
// `onInputs`, when given, hears every file the bundle was made from, each a
|
|
46
|
+
// full path, so `arc serve` can run the function again when any of them
|
|
47
|
+
// changes, wherever it is (a game's rules its function shares).
|
|
48
|
+
export async function bundle({ main, onInputs, onPackages, outfile, }) {
|
|
45
49
|
if (!(await pathExists(main))) {
|
|
46
50
|
throw new ArcError(BUILD_FAILED, phrase.runnerMissing(main));
|
|
47
51
|
}
|
|
@@ -52,7 +56,7 @@ export async function bundle({ main, onPackages, outfile, }) {
|
|
|
52
56
|
conditions: ["workerd", "worker", "browser"],
|
|
53
57
|
format: "esm",
|
|
54
58
|
logLevel: "silent",
|
|
55
|
-
metafile: Boolean(onPackages),
|
|
59
|
+
metafile: Boolean(onPackages ?? onInputs),
|
|
56
60
|
outfile,
|
|
57
61
|
platform: "neutral",
|
|
58
62
|
entryPoints: [main],
|
|
@@ -68,6 +72,11 @@ export async function bundle({ main, onPackages, outfile, }) {
|
|
|
68
72
|
throw new ArcError(FUNCTION_TOO_LARGE, phrase.functionTooLarge(size));
|
|
69
73
|
}
|
|
70
74
|
onPackages?.(packagesOf(inputs));
|
|
75
|
+
// a metafile's inputs are relative to where esbuild ran, and a plugin's
|
|
76
|
+
// own (`ns:name`) aren't files
|
|
77
|
+
onInputs?.(inputs
|
|
78
|
+
.filter((input) => !/^[a-z-]+:/iu.test(input) || /^[a-z]:[\\/]/iu.test(input))
|
|
79
|
+
.map((input) => resolve(input)));
|
|
71
80
|
return outfile;
|
|
72
81
|
}
|
|
73
82
|
// [function]
|
package/dist/runner/entry.js
CHANGED
|
@@ -26,10 +26,15 @@ export const FUNCTION_MODULE = "function.js";
|
|
|
26
26
|
// arrive as a header too (x-arcadible-secrets, opened by the dispatcher),
|
|
27
27
|
// and are added to what the code is given, `env`. Neither header reaches
|
|
28
28
|
// the developer's code. Under arc serve they're the script's own bindings,
|
|
29
|
-
// named by ARCADIBLE_SECRETS
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
29
|
+
// named by ARCADIBLE_SECRETS, which the code isn't given, nor ARCADIBLE_SERVE,
|
|
30
|
+
// as on Arcadible. Whatever the code logs has the secrets' values it was
|
|
31
|
+
// given hidden, `[secret NAME]`, as they are and as JSON escapes them, and an
|
|
32
|
+
// error that holds one, thrown by the handler, by work it handed on
|
|
33
|
+
// (waitUntil), by its response's body as it's sent, or by what no one
|
|
34
|
+
// awaited, is logged hidden and given on as one that doesn't. What's hidden
|
|
35
|
+
// is a secret as the code logs or throws it, in plain text: one encoded,
|
|
36
|
+
// split, or put into an error's message after it was made isn't found
|
|
37
|
+
// (plan/FUNCTION-LOGS.md, What's redacted).
|
|
33
38
|
export const ENTRY = `import handler from "./${FUNCTION_MODULE}";
|
|
34
39
|
const CLAIM = "x-arcadible-claim";
|
|
35
40
|
const SECRETS = "x-arcadible-secrets";
|
|
@@ -43,13 +48,17 @@ let serve = null;
|
|
|
43
48
|
// the secrets' values the code has been given, each with its name, longest
|
|
44
49
|
// first, so one inside another is hidden as the longer
|
|
45
50
|
const hidden = [];
|
|
51
|
+
// each value as it is, and as it reads inside JSON, escaped (a quote, a
|
|
52
|
+
// backslash, a newline), as a value logged inside an object is
|
|
46
53
|
const remember = (values) => {
|
|
47
54
|
let added = false;
|
|
48
55
|
for (const [name, value] of Object.entries(values)) {
|
|
49
56
|
if (typeof value !== "string" || value.length < SHORTEST) continue;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
for (const form of new Set([value, JSON.stringify(value).slice(1, -1)])) {
|
|
58
|
+
if (hidden.some(([known]) => known === form)) continue;
|
|
59
|
+
hidden.push([form, name]);
|
|
60
|
+
added = true;
|
|
61
|
+
}
|
|
53
62
|
}
|
|
54
63
|
if (added) hidden.sort((a, b) => b[0].length - a[0].length);
|
|
55
64
|
};
|
|
@@ -59,24 +68,108 @@ const hide = (text) => {
|
|
|
59
68
|
};
|
|
60
69
|
// one of console's arguments with any secret in it hidden: a string as it
|
|
61
70
|
// is, an error as its stack, anything else as JSON, and as the console
|
|
62
|
-
// would show it when no secret's in it
|
|
71
|
+
// would show it when no secret's in it. A value JSON can't hold (a BigInt)
|
|
72
|
+
// is shown as its text, hidden, since what's inside it can't be looked at.
|
|
63
73
|
const shown = (value) => {
|
|
64
74
|
if (typeof value === "string") return hide(value);
|
|
65
75
|
let text;
|
|
66
76
|
try {
|
|
67
77
|
text = value instanceof Error ? String(value.stack ?? value) : JSON.stringify(value);
|
|
68
78
|
} catch {
|
|
69
|
-
|
|
79
|
+
try {
|
|
80
|
+
return hide(String(value));
|
|
81
|
+
} catch {
|
|
82
|
+
return "[unloggable]";
|
|
83
|
+
}
|
|
70
84
|
}
|
|
71
85
|
if (typeof text !== "string") return value;
|
|
72
86
|
const safe = hide(text);
|
|
73
87
|
return safe === text ? value : safe;
|
|
74
88
|
};
|
|
75
|
-
|
|
89
|
+
// whether an error, or anything thrown, holds a secret
|
|
90
|
+
const holds = (err) => {
|
|
91
|
+
if (hidden.length === 0) return false;
|
|
92
|
+
let text;
|
|
93
|
+
try {
|
|
94
|
+
text = String(err?.stack ?? err);
|
|
95
|
+
} catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return hide(text) !== text;
|
|
99
|
+
};
|
|
100
|
+
// an error that held a secret: logged with it hidden, and given on in place
|
|
101
|
+
// of the error, so neither the logs nor what's thrown keep it
|
|
102
|
+
const holding = (err) => {
|
|
103
|
+
console.error(err);
|
|
104
|
+
return new Error("The function threw an error holding a secret: it's logged with the secret hidden.");
|
|
105
|
+
};
|
|
106
|
+
// every method of console's that prints what it's given (assert, its
|
|
107
|
+
// arguments after the condition)
|
|
108
|
+
for (const level of ["assert", "count", "debug", "dir", "error", "group", "groupCollapsed", "info", "log", "table", "timeLog", "trace", "warn"]) {
|
|
76
109
|
const original = console[level];
|
|
77
110
|
if (typeof original !== "function") continue;
|
|
78
|
-
console[level] =
|
|
111
|
+
console[level] =
|
|
112
|
+
level === "assert"
|
|
113
|
+
? (condition, ...args) => original.call(console, condition, ...(hidden.length > 0 ? args.map(shown) : args))
|
|
114
|
+
: (...args) => original.apply(console, hidden.length > 0 ? args.map(shown) : args);
|
|
79
115
|
}
|
|
116
|
+
// what fails outside the awaited handler (a promise no one waits for, a
|
|
117
|
+
// timer): logged with any secret hidden, in place of the runtime's own
|
|
118
|
+
// report of it
|
|
119
|
+
if (typeof addEventListener === "function") {
|
|
120
|
+
addEventListener("unhandledrejection", (event) => {
|
|
121
|
+
if (!holds(event.reason)) return;
|
|
122
|
+
event.preventDefault?.();
|
|
123
|
+
console.error(event.reason);
|
|
124
|
+
});
|
|
125
|
+
addEventListener("error", (event) => {
|
|
126
|
+
if (!holds(event.error)) return;
|
|
127
|
+
event.preventDefault?.();
|
|
128
|
+
console.error(event.error);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// the work the code hands on (ctx.waitUntil), whose failure holding a
|
|
132
|
+
// secret is given on as one that doesn't; the rest of ctx as it is, its
|
|
133
|
+
// methods called on ctx itself
|
|
134
|
+
const wrapped = (ctx) => {
|
|
135
|
+
if (!ctx || typeof ctx.waitUntil !== "function") return ctx;
|
|
136
|
+
const waitUntil = (promise) =>
|
|
137
|
+
ctx.waitUntil(
|
|
138
|
+
Promise.resolve(promise).catch((err) => {
|
|
139
|
+
throw holds(err) ? holding(err) : err;
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
return new Proxy(ctx, {
|
|
143
|
+
get(target, key) {
|
|
144
|
+
if (key === "waitUntil") return waitUntil;
|
|
145
|
+
const value = target[key];
|
|
146
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
// a response whose body fails as it's sent, with a secret in its error,
|
|
151
|
+
// fails with one that doesn't hold it
|
|
152
|
+
const streamed = (response) => {
|
|
153
|
+
if (hidden.length === 0 || !(response instanceof Response) || !response.body || response.status === 101 || response.webSocket) {
|
|
154
|
+
return response;
|
|
155
|
+
}
|
|
156
|
+
const reader = response.body.getReader();
|
|
157
|
+
const body = new ReadableStream({
|
|
158
|
+
async pull(controller) {
|
|
159
|
+
try {
|
|
160
|
+
const { done, value } = await reader.read();
|
|
161
|
+
if (done) controller.close();
|
|
162
|
+
else controller.enqueue(value);
|
|
163
|
+
} catch (err) {
|
|
164
|
+
controller.error(holds(err) ? holding(err) : err);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
cancel(reason) {
|
|
168
|
+
return reader.cancel(reason);
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
return new Response(body, response);
|
|
172
|
+
};
|
|
80
173
|
globalThis[Symbol.for("arcadible.function.api")] = {
|
|
81
174
|
version: 1,
|
|
82
175
|
async fetch(path, init = {}) {
|
|
@@ -108,13 +201,19 @@ export default {
|
|
|
108
201
|
} else {
|
|
109
202
|
delete set.ARCADIBLE_CLAIM;
|
|
110
203
|
}
|
|
204
|
+
// what the code is given: the script's bindings, but the entry's own
|
|
205
|
+
// two under arc serve, which Arcadible's env doesn't have
|
|
111
206
|
let given = env;
|
|
207
|
+
if ("ARCADIBLE_SERVE" in env || "ARCADIBLE_SECRETS" in env) {
|
|
208
|
+
const { ARCADIBLE_SERVE: _serve, ARCADIBLE_SECRETS: _secrets, ...rest } = env;
|
|
209
|
+
given = rest;
|
|
210
|
+
}
|
|
112
211
|
if (secrets) {
|
|
113
212
|
const text = atob(secrets.replace(/-/g, "+").replace(/_/g, "/"));
|
|
114
213
|
const bytes = Uint8Array.from(text, (char) => char.charCodeAt(0));
|
|
115
214
|
const opened = JSON.parse(new TextDecoder().decode(bytes));
|
|
116
215
|
remember(opened);
|
|
117
|
-
given = { ...
|
|
216
|
+
given = { ...given, ...opened };
|
|
118
217
|
}
|
|
119
218
|
if (typeof env.ARCADIBLE_SECRETS === "string") {
|
|
120
219
|
remember(Object.fromEntries(env.ARCADIBLE_SECRETS.split(",").map((name) => [name, env[name]])));
|
|
@@ -129,12 +228,9 @@ export default {
|
|
|
129
228
|
return new Response("The function's default export has no fetch(request).\\n", { status: 500 });
|
|
130
229
|
}
|
|
131
230
|
try {
|
|
132
|
-
return await handler.fetch(request, given, ctx);
|
|
231
|
+
return streamed(await handler.fetch(request, given, wrapped(ctx)));
|
|
133
232
|
} catch (err) {
|
|
134
|
-
|
|
135
|
-
if (hidden.length === 0 || hide(text) === text) throw err;
|
|
136
|
-
console.error(err);
|
|
137
|
-
throw new Error("The function threw an error holding a secret: it's logged with the secret hidden.");
|
|
233
|
+
throw holds(err) ? holding(err) : err;
|
|
138
234
|
}
|
|
139
235
|
},
|
|
140
236
|
};
|
package/dist/runner/outbound.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// A runner's way out: every request a game's
|
|
1
|
+
// A runner's way out: every request a game's function makes of its own goes
|
|
2
2
|
// through here first (plan/SERVERS.md, The runner to Arcadible, and beyond),
|
|
3
3
|
// and reaches only the hosts its manifest declares (function.outbound_hosts), so a
|
|
4
4
|
// runner can't be turned on other sites. On Arcadible it's the rule the
|
|
@@ -28,18 +28,31 @@ export function allowed(url, hosts) {
|
|
|
28
28
|
return (to.protocol === "https:" && to.port === "" && hosts.includes(to.hostname));
|
|
29
29
|
}
|
|
30
30
|
// [function]
|
|
31
|
-
/**
|
|
31
|
+
/** Whether `name` is one of Arcadible's own, which no manifest declares. */
|
|
32
|
+
export function isArcadible(name) {
|
|
33
|
+
return ["arcadible.com", "arcadible.io"].some((domain) => name === domain || name.endsWith(`.${domain}`));
|
|
34
|
+
}
|
|
35
|
+
// [function]
|
|
36
|
+
/**
|
|
37
|
+
* The answer to a request that isn't allowed, which says why: Arcadible's
|
|
38
|
+
* own addresses can't be declared, and are reached through the Function
|
|
39
|
+
* SDK; any other, by declaring it.
|
|
40
|
+
*/
|
|
32
41
|
export function refuse(url) {
|
|
33
42
|
let host = "that address";
|
|
43
|
+
let name = "";
|
|
34
44
|
try {
|
|
35
|
-
host = new URL(url)
|
|
45
|
+
({ host, hostname: name } = new URL(url));
|
|
36
46
|
}
|
|
37
47
|
catch {
|
|
38
48
|
// said as it is.
|
|
39
49
|
}
|
|
50
|
+
const arcadible = isArcadible(name);
|
|
40
51
|
return Response.json({
|
|
41
52
|
code: CODE,
|
|
42
|
-
message:
|
|
53
|
+
message: arcadible
|
|
54
|
+
? `The function may not call ${host} itself. Arcadible is reached through the Function SDK (@arcadible/function-sdk), which needs no host declared.`
|
|
55
|
+
: `The function may not call ${host}. To allow it, add it to function.outbound_hosts in arcadible.toml, as a name reached over HTTPS.`,
|
|
43
56
|
}, { status: STATUS });
|
|
44
57
|
}
|
|
45
58
|
// [function]
|
|
@@ -61,7 +74,10 @@ export default {
|
|
|
61
74
|
if (new URL(request.url).origin !== own &&
|
|
62
75
|
!allowed(request.url, declared(env.HOSTS))) {
|
|
63
76
|
const refused = refuse(request.url);
|
|
64
|
-
|
|
77
|
+
const why = isArcadible(new URL(request.url).hostname)
|
|
78
|
+
? "Arcadible's, reached through the Function SDK"
|
|
79
|
+
: "not in function.outbound_hosts";
|
|
80
|
+
console.warn(`Function: refused ${request.method} ${request.url} (${why})`);
|
|
65
81
|
return refused;
|
|
66
82
|
}
|
|
67
83
|
return fetch(request, { redirect: "manual" });
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// [import]
|
|
2
|
-
import { readdirSync } from "node:fs";
|
|
3
2
|
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
3
|
// [import]
|
|
5
4
|
import fs from "fs-extra";
|
|
@@ -35,23 +34,3 @@ export function avoids(root, target, name) {
|
|
|
35
34
|
.split(sep)
|
|
36
35
|
.includes(name);
|
|
37
36
|
}
|
|
38
|
-
// [function]
|
|
39
|
-
// whether an existing `target` has `file` at its root. A directory that
|
|
40
|
-
// doesn't exist yet, because a build step creates it, passes.
|
|
41
|
-
export function hasFile(root, target, file) {
|
|
42
|
-
return !exists(root, target) || exists(join(root, target), file);
|
|
43
|
-
}
|
|
44
|
-
// [function]
|
|
45
|
-
// whether `target` has none of `names` at its root.
|
|
46
|
-
export function lacksFiles(root, target, names) {
|
|
47
|
-
return names.every((name) => !exists(join(root, target), name));
|
|
48
|
-
}
|
|
49
|
-
// [function]
|
|
50
|
-
// whether an existing `target` lacks a folder named `name` at its root, in any
|
|
51
|
-
// letter case, since a build's paths are case-sensitive once it's served.
|
|
52
|
-
export function lacksFolder(root, target, name) {
|
|
53
|
-
if (!exists(root, target)) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
return !readdirSync(join(root, target), { withFileTypes: true }).some((entry) => entry.isDirectory() && entry.name.toLowerCase() === name);
|
|
57
|
-
}
|
package/dist/schema/game.js
CHANGED
|
@@ -266,18 +266,6 @@ function zArtVideo(field, root) {
|
|
|
266
266
|
return z.optional(zMp4(`${field}_video`, root, { ...ART[field], maxSize: MAX_SIZE_MP4 }));
|
|
267
267
|
}
|
|
268
268
|
// [function]
|
|
269
|
-
function zVimeo() {
|
|
270
|
-
return z
|
|
271
|
-
.string()
|
|
272
|
-
.regex(/^https:\/\/(?:www\.)?(?:vimeo\.com|player\.vimeo\.com\/video)\/([0-9]+)(?:[/?#].*)?$/iu);
|
|
273
|
-
}
|
|
274
|
-
// [function]
|
|
275
|
-
function zYouTube() {
|
|
276
|
-
return z
|
|
277
|
-
.string()
|
|
278
|
-
.regex(/^https:\/\/(?:www\.)?(?:youtube\.com\/(?:watch\?v=|embed\/)|youtu\.be\/)([A-Za-z0-9_-]{11})(?:[?&#].*)?$/iu);
|
|
279
|
-
}
|
|
280
|
-
// [function]
|
|
281
269
|
function zAi() {
|
|
282
270
|
return z.optional(z.enum(AI));
|
|
283
271
|
}
|
|
@@ -376,14 +364,6 @@ function zOrientation() {
|
|
|
376
364
|
return z.optional(z.enum(ORIENTATION));
|
|
377
365
|
}
|
|
378
366
|
// [function]
|
|
379
|
-
function zPrice() {
|
|
380
|
-
const field = "price";
|
|
381
|
-
return z.optional(z
|
|
382
|
-
.int()
|
|
383
|
-
.min(0, message(field, ["Must be 0 or more."]))
|
|
384
|
-
.max(25, message(field, ["Must be 25 or less."])));
|
|
385
|
-
}
|
|
386
|
-
// [function]
|
|
387
367
|
function zShortTitle() {
|
|
388
368
|
const field = "short_title";
|
|
389
369
|
return z.optional(zText(field, { max: 30 / 2, min: 1 }));
|
|
@@ -399,16 +379,6 @@ function zTitle() {
|
|
|
399
379
|
return z.optional(zText(field, { max: 30 * 1, min: 1 }));
|
|
400
380
|
}
|
|
401
381
|
// [function]
|
|
402
|
-
function zTrailer() {
|
|
403
|
-
const field = "trailer";
|
|
404
|
-
return z
|
|
405
|
-
.string()
|
|
406
|
-
.min(1, { ...atLeast(field, 1), abort: true })
|
|
407
|
-
.max(255, message(field, ["Must be at most 255 characters."]))
|
|
408
|
-
.refine((url) => zVimeo().safeParse(url).success || zYouTube().safeParse(url).success, message(field, ["Must be a YouTube or Vimeo URL."], ISSUE.URL_INVALID))
|
|
409
|
-
.optional();
|
|
410
|
-
}
|
|
411
|
-
// [function]
|
|
412
382
|
function zVersion() {
|
|
413
383
|
const field = "version";
|
|
414
384
|
return z
|
|
@@ -449,13 +419,11 @@ export function game(_value, { root }) {
|
|
|
449
419
|
orientation: zOrientation(),
|
|
450
420
|
poster: zArt("poster", root),
|
|
451
421
|
poster_video: zArtVideo("poster", root),
|
|
452
|
-
price: zPrice(),
|
|
453
422
|
short_title: zShortTitle(),
|
|
454
423
|
splash: zArt("splash", root),
|
|
455
424
|
splash_video: zArtVideo("splash", root),
|
|
456
425
|
tagline: zTagline(),
|
|
457
426
|
title: zTitle(),
|
|
458
|
-
trailer: zTrailer(),
|
|
459
427
|
version: zVersion(),
|
|
460
428
|
visibility: zVisibility(),
|
|
461
429
|
});
|
package/dist/schema/message.js
CHANGED
|
@@ -7,10 +7,9 @@ import { indentLines } from "../util/strs.js";
|
|
|
7
7
|
import { MANIFEST } from "../config/url.js";
|
|
8
8
|
// [declare]
|
|
9
9
|
// fields the CLI checks but the docs leave out until they ship, so their
|
|
10
|
-
// issues have no link:
|
|
11
|
-
//
|
|
10
|
+
// issues have no link: a game's function and its own servers, until they do
|
|
11
|
+
// (plan/SERVERS.md).
|
|
12
12
|
export const UNDOCUMENTED = new Set([
|
|
13
|
-
"game.price",
|
|
14
13
|
"function.main",
|
|
15
14
|
"function.outbound_hosts",
|
|
16
15
|
"function.secrets",
|
package/dist/schema/runner.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import * as z from "zod";
|
|
3
3
|
// [import]
|
|
4
4
|
import { ISSUE } from "../config/code.js";
|
|
5
|
+
import { SECRET_NAME, SECRETS } from "../config/limit.js";
|
|
5
6
|
import { zHosts } from "./host.js";
|
|
6
7
|
import { messages } from "./message.js";
|
|
7
8
|
// [declare]
|
|
@@ -10,16 +11,15 @@ const message = messages("function");
|
|
|
10
11
|
const REQUIRED = message("main", [
|
|
11
12
|
"Must be set: the path of the function's code, such as function/index.ts.",
|
|
12
13
|
]).message;
|
|
13
|
-
// a secret's name, as an environment variable is named.
|
|
14
|
-
const SECRET = /^[A-Z][A-Z0-9_]*$/u;
|
|
15
14
|
// [function]
|
|
16
|
-
// a list of distinct strings, each matching `pattern
|
|
17
|
-
function zNames(field, pattern,
|
|
15
|
+
// a list of distinct strings, each matching `pattern`, `max` at most.
|
|
16
|
+
function zNames(field, pattern, lines, max) {
|
|
18
17
|
return z.optional(z
|
|
19
18
|
.array(z
|
|
20
19
|
.string()
|
|
21
|
-
.regex(pattern, message(field,
|
|
20
|
+
.regex(pattern, message(field, lines, ISSUE.CHARACTERS_INVALID)))
|
|
22
21
|
.min(1, message(field, ["Must not be empty.", "Leave the field out instead."]))
|
|
22
|
+
.max(max, message(field, [`Must have at most ${max} items.`]))
|
|
23
23
|
.refine((items) => new Set(items).size === items.length, message(field, ["Must not repeat an item."], ISSUE.DUPLICATE)));
|
|
24
24
|
}
|
|
25
25
|
// [function]
|
|
@@ -38,6 +38,8 @@ export function runner() {
|
|
|
38
38
|
.min(1, message("main", ["Must not be empty."]))
|
|
39
39
|
.refine((file) => !file.startsWith("/") && !file.split(/[/\\]/u).includes(".."), message("main", ["Must be a path within the project."], ISSUE.PATH_INVALID)),
|
|
40
40
|
outbound_hosts: zHosts(message, "outbound_hosts", "a host's name"),
|
|
41
|
-
secrets: zNames("secrets",
|
|
41
|
+
secrets: zNames("secrets", SECRET_NAME, [
|
|
42
|
+
"Must be a name in capitals, such as EXAMPLE_KEY: letters, digits, and underscores, up to 64 characters, starting with a letter, and not with ARCADIBLE_.",
|
|
43
|
+
], SECRETS),
|
|
42
44
|
});
|
|
43
45
|
}
|
package/dist/schema/workflow.js
CHANGED
|
@@ -3,19 +3,13 @@ import * as z from "zod";
|
|
|
3
3
|
// [import]
|
|
4
4
|
import { ISSUE } from "../config/code.js";
|
|
5
5
|
import { buildCommand } from "../util/command.js";
|
|
6
|
-
import { MEDIA
|
|
6
|
+
import { MEDIA } from "../config/file.js";
|
|
7
7
|
import { cmdInspect } from "../phrase/index.js";
|
|
8
8
|
import { messages } from "./message.js";
|
|
9
9
|
import { isTable } from "../util/objs.js";
|
|
10
|
-
import {
|
|
11
|
-
import { avoids as avoidsCheck, exists as existsCheck, hasFile as hasFileCheck, isInside as isInsideCheck, isRelative as isRelativeCheck, isRoot as isRootCheck, lacksFiles as lacksFilesCheck, lacksFolder as lacksFolderCheck, } from "./check/workflow.js";
|
|
10
|
+
import { avoids as avoidsCheck, exists as existsCheck, isInside as isInsideCheck, isRelative as isRelativeCheck, isRoot as isRootCheck, } from "./check/workflow.js";
|
|
12
11
|
// [declare]
|
|
13
12
|
const message = messages("workflow");
|
|
14
|
-
const INDEX = "index.html";
|
|
15
|
-
const RESERVED = [PACKAGED, MEDIA];
|
|
16
|
-
// the folder every build's origin keeps for Arcadible's own files, such as
|
|
17
|
-
// the script games include. arc pack checks it again after the build.
|
|
18
|
-
const RESERVED_FOLDER = handle;
|
|
19
13
|
// [function]
|
|
20
14
|
// whether `build` runs anything, as `arc build` runs it.
|
|
21
15
|
function hasBuild(build) {
|
|
@@ -36,8 +30,10 @@ function zBuild() {
|
|
|
36
30
|
return z.union([z.string(), z.array(z.string())], { error: typeMessage });
|
|
37
31
|
}
|
|
38
32
|
// [function]
|
|
39
|
-
// a directory inside the project
|
|
40
|
-
//
|
|
33
|
+
// a directory inside the project, which exists unless a build makes it.
|
|
34
|
+
// Only the path is checked: what's in it is the build's, checked by arc pack
|
|
35
|
+
// once it's built (package_index_missing, package_path_reserved). Each
|
|
36
|
+
// check aborts the rest when it fails, so one bad path gets one issue.
|
|
41
37
|
function zDeployDir(root, { build }) {
|
|
42
38
|
const field = "deploy_dir";
|
|
43
39
|
return z
|
|
@@ -68,24 +64,6 @@ function zDeployDir(root, { build }) {
|
|
|
68
64
|
`Run ${cmdInspect()} for details.`,
|
|
69
65
|
], ISSUE.PATH_INVALID),
|
|
70
66
|
abort: true,
|
|
71
|
-
})
|
|
72
|
-
.refine((file) => hasFileCheck(root, file, INDEX), {
|
|
73
|
-
...message(field, [`Must have an ${INDEX} at its root.`], ISSUE.INDEX_MISSING),
|
|
74
|
-
abort: true,
|
|
75
|
-
})
|
|
76
|
-
.refine((file) => lacksFilesCheck(root, file, RESERVED), {
|
|
77
|
-
...message(field, [
|
|
78
|
-
`Must not have ${RESERVED.join(" or ")} at its root.`,
|
|
79
|
-
`They're reserved for the files ${title} adds.`,
|
|
80
|
-
], ISSUE.PATH_INVALID),
|
|
81
|
-
abort: true,
|
|
82
|
-
})
|
|
83
|
-
.refine((file) => lacksFolderCheck(root, file, RESERVED_FOLDER), {
|
|
84
|
-
...message(field, [
|
|
85
|
-
`Must not have an ${RESERVED_FOLDER} folder at its root, in any letter case.`,
|
|
86
|
-
`It's reserved for ${title}'s own files.`,
|
|
87
|
-
], ISSUE.PATH_INVALID),
|
|
88
|
-
abort: true,
|
|
89
67
|
});
|
|
90
68
|
}
|
|
91
69
|
// [function]
|
package/dist/serve/page.js
CHANGED
|
@@ -215,7 +215,7 @@ export function html(game, pictures = { art: false, icon: false }, opened, link)
|
|
|
215
215
|
// who the game runs for: a local player (`arc serve --player`), or null,
|
|
216
216
|
// a guest.
|
|
217
217
|
player: opened ? opened.player : (game.player ?? null),
|
|
218
|
-
// where the game's
|
|
218
|
+
// where the game's function is, when the project has one
|
|
219
219
|
runner: game.runner?.url ?? null,
|
|
220
220
|
sandbox: SANDBOX,
|
|
221
221
|
src: game.src,
|
package/dist/serve/remote.js
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
// them, so a fix reaches `arc serve` without a new CLI: the SDK's hosted
|
|
3
3
|
// script, as every game's origin serves it at /arcadible/sdk/, and the play
|
|
4
4
|
// page's host, as the play page runs it. Each is fetched once a session, and
|
|
5
|
-
// the last copy is kept on disk for when Arcadible can't be reached
|
|
5
|
+
// the last copy is kept on disk for when Arcadible can't be reached, or
|
|
6
|
+
// answers 403 or 404 for a file that's always there: the names this module
|
|
7
|
+
// knows are at fixed addresses, so a refusal of one is Arcadible's fault
|
|
8
|
+
// (the router answered sdk.arcadible.io with 404 on 2026-11-19), and the
|
|
9
|
+
// game keeps its SDK.
|
|
6
10
|
// [import]
|
|
7
11
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
8
12
|
import { join } from "node:path";
|
|
@@ -56,10 +60,12 @@ async function keep(dir, name, { body, ...meta }) {
|
|
|
56
60
|
// [function]
|
|
57
61
|
// the files from Arcadible. `host` is the play site's origin, `sdk` an
|
|
58
62
|
// origin that serves /arcadible/sdk/, and `dir` where copies are kept.
|
|
59
|
-
// `get(name)` resolves with `{ body, type, fetchedAt, kept }`,
|
|
60
|
-
// says the copy is from disk because Arcadible couldn't be
|
|
61
|
-
//
|
|
62
|
-
// and there's no copy
|
|
63
|
+
// `get(name)` resolves with `{ body, type, fetchedAt, kept, refused? }`,
|
|
64
|
+
// where `kept` says the copy is from disk because Arcadible couldn't be
|
|
65
|
+
// reached, or answered `refused` (403 or 404); or null when Arcadible has
|
|
66
|
+
// no such file and there's no copy; it rejects when Arcadible can't be
|
|
67
|
+
// reached and there's no copy. `name` is `host`, or a path under
|
|
68
|
+
// /arcadible/: a name this module doesn't know is never asked for.
|
|
63
69
|
export function remoteFiles({ dir, host, request = fetch, sdk, }) {
|
|
64
70
|
const session = new Map();
|
|
65
71
|
const url = function (name) {
|
|
@@ -77,7 +83,9 @@ export function remoteFiles({ dir, host, request = fetch, sdk, }) {
|
|
|
77
83
|
try {
|
|
78
84
|
const res = await request(target);
|
|
79
85
|
if (res.status === 403 || res.status === 404) {
|
|
80
|
-
|
|
86
|
+
await res.body?.cancel();
|
|
87
|
+
const file = await readKept(dir, kept);
|
|
88
|
+
return file ? { ...file, kept: true, refused: res.status } : null;
|
|
81
89
|
}
|
|
82
90
|
if (!res.ok) {
|
|
83
91
|
throw new Error(`${res.status}`);
|