arcadible 1.0.24 → 1.0.26

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 (54) hide show
  1. package/dist/action/build/tool.js +6 -10
  2. package/dist/action/delete/tool.js +2 -1
  3. package/dist/action/deploy/tool-git.js +4 -9
  4. package/dist/action/deploy/tool.js +3 -8
  5. package/dist/action/deploy/wait.js +1 -1
  6. package/dist/action/function/tool.js +6 -6
  7. package/dist/action/game.js +3 -2
  8. package/dist/action/key/tool.js +6 -5
  9. package/dist/action/open/tool.js +2 -1
  10. package/dist/action/pack/tool.js +13 -15
  11. package/dist/action/play/tool.js +2 -1
  12. package/dist/action/predeploy/ac.js +3 -3
  13. package/dist/action/predeploy/game.js +2 -8
  14. package/dist/action/predeploy/secrets.js +2 -2
  15. package/dist/action/predeploy/tool-git.js +3 -8
  16. package/dist/action/predeploy/tool.js +1 -3
  17. package/dist/action/secret/tool.js +4 -4
  18. package/dist/action/serve/tool.js +26 -5
  19. package/dist/action/value/tool.js +216 -0
  20. package/dist/api.js +190 -38
  21. package/dist/command/inspect.js +2 -1
  22. package/dist/command/open.js +2 -1
  23. package/dist/command/play.js +4 -3
  24. package/dist/command/serve.js +3 -2
  25. package/dist/command/value/get.js +21 -0
  26. package/dist/command/value/index.js +19 -0
  27. package/dist/command/value/key.js +8 -0
  28. package/dist/command/value/list.js +41 -0
  29. package/dist/command/value/remove.js +26 -0
  30. package/dist/command/value/set.js +62 -0
  31. package/dist/command/value/usage.js +69 -0
  32. package/dist/commands.js +8 -1
  33. package/dist/phrase/common.js +9 -0
  34. package/dist/phrase/deploy.js +9 -1
  35. package/dist/phrase/function.js +6 -2
  36. package/dist/phrase/index.js +1 -0
  37. package/dist/phrase/server.js +1 -1
  38. package/dist/phrase/value.js +55 -0
  39. package/dist/runner/bundle.js +10 -60
  40. package/dist/runner/entry.js +57 -0
  41. package/dist/runner/outbound.js +1 -1
  42. package/dist/schema/workflow.js +1 -1
  43. package/dist/serve/page.js +205 -6
  44. package/dist/serve/runner.js +9 -2
  45. package/dist/serve/server.js +7 -1
  46. package/dist/serve/ticket.js +2 -2
  47. package/dist/serve/values.js +317 -0
  48. package/dist/util/objs.js +17 -0
  49. package/dist/util/progress.js +13 -1
  50. package/dist/util/request.js +15 -3
  51. package/dist/util/schema.js +1 -1
  52. package/dist/util/shape.js +49 -0
  53. package/npm-shrinkwrap.json +2 -2
  54. package/package.json +1 -1
@@ -0,0 +1,8 @@
1
+ // [import]
2
+ // [declare]
3
+ // `<key>`, of the commands that take one value.
4
+ export const KEY = {
5
+ describe: "The value's key, such as daily/2026-11-12",
6
+ required: true,
7
+ type: "string",
8
+ };
@@ -0,0 +1,41 @@
1
+ // [import]
2
+ import { defineCommand } from "../../cli/command.js";
3
+ import { valueNone } from "../../phrase/index.js";
4
+ import { p } from "../../util/log.js";
5
+ import { CHANNEL, CWD, JSON_OUTPUT, QUIET } from "../../cli/options.js";
6
+ import { run } from "../function/secret/run.js";
7
+ import { day, table } from "../../util/table.js";
8
+ import { list } from "../../action/value/tool.js";
9
+ // [function]
10
+ // the values as a table, a row each: never a value, which `get` shows.
11
+ function rows(entries) {
12
+ return table([
13
+ ["KEY", "SIZE", "SET"],
14
+ ...entries.map((each) => [
15
+ each.key,
16
+ String(each.size ?? "-"),
17
+ day(each.updated_at),
18
+ ]),
19
+ ]);
20
+ }
21
+ // [export]
22
+ export default defineCommand({
23
+ name: "list",
24
+ options: {
25
+ prefix: {
26
+ alias: "p",
27
+ describe: "Only keys that start with this",
28
+ type: "string",
29
+ },
30
+ ...CHANNEL,
31
+ json: JSON_OUTPUT,
32
+ quiet: QUIET,
33
+ cwd: CWD,
34
+ },
35
+ run(argv, aborting) {
36
+ return run(argv, aborting, (current, conf) => list(current, { ...conf, prefix: argv.prefix }), (entries) => {
37
+ p(entries.length ? rows(entries) : valueNone());
38
+ }, "arc value list");
39
+ },
40
+ summary: "List the values' keys, with their sizes",
41
+ });
@@ -0,0 +1,26 @@
1
+ // [import]
2
+ import { defineCommand } from "../../cli/command.js";
3
+ import { valueRemoved, valueRemoveQuestion } from "../../phrase/index.js";
4
+ import { p } from "../../util/log.js";
5
+ import { KEY } from "./key.js";
6
+ import { CHANNEL, CWD, JSON_OUTPUT, QUIET, YES } from "../../cli/options.js";
7
+ import { run } from "../function/secret/run.js";
8
+ import { remove } from "../../action/value/tool.js";
9
+ // [export]
10
+ export default defineCommand({
11
+ name: "remove",
12
+ options: { ...CHANNEL, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD, yes: YES },
13
+ positionals: { key: KEY },
14
+ run(argv, aborting) {
15
+ return run(argv, aborting, (current, conf) => remove(current, { ...conf, key: argv.key }), (gone) => {
16
+ p(valueRemoved({ channel: gone.channel, key: argv.key }));
17
+ }, `arc value remove ${argv.key}`, (where) => ({
18
+ question: valueRemoveQuestion({
19
+ channel: String(where),
20
+ key: argv.key,
21
+ }),
22
+ usage: `arc value remove ${argv.key} --${where}`,
23
+ }));
24
+ },
25
+ summary: "Remove a value",
26
+ });
@@ -0,0 +1,62 @@
1
+ // [import]
2
+ import { defineCommand } from "../../cli/command.js";
3
+ import { valueSet } from "../../phrase/index.js";
4
+ import { p } from "../../util/log.js";
5
+ import { CHANNEL, CWD, JSON_OUTPUT, QUIET } from "../../cli/options.js";
6
+ import { run } from "../function/secret/run.js";
7
+ import { set } from "../../action/value/tool.js";
8
+ // [function]
9
+ // all of standard input, as text: a value's JSON, piped in. At a terminal
10
+ // there's none to read, which fails as empty input does.
11
+ function input() {
12
+ if (process.stdin.isTTY) {
13
+ return Promise.resolve("");
14
+ }
15
+ return new Promise((resolve, reject) => {
16
+ const chunks = [];
17
+ process.stdin.on("data", (chunk) => chunks.push(chunk));
18
+ process.stdin.on("error", reject);
19
+ process.stdin.on("end", () => {
20
+ resolve(Buffer.concat(chunks).toString("utf8"));
21
+ });
22
+ });
23
+ }
24
+ // [export]
25
+ export default defineCommand({
26
+ name: "set",
27
+ options: {
28
+ file: {
29
+ alias: "f",
30
+ describe: "Read the value's JSON from a file",
31
+ type: "string",
32
+ },
33
+ dir: {
34
+ alias: "d",
35
+ describe: "Set a value for each .json file in a folder",
36
+ type: "string",
37
+ },
38
+ ...CHANNEL,
39
+ json: JSON_OUTPUT,
40
+ quiet: QUIET,
41
+ cwd: CWD,
42
+ },
43
+ positionals: {
44
+ key: {
45
+ describe: "The value's key, such as daily/2026-11-12",
46
+ type: "string",
47
+ },
48
+ },
49
+ run(argv, aborting) {
50
+ const what = argv.key ?? `--dir ${argv.dir ?? "<folder>"}`;
51
+ return run(argv, aborting, (current, conf) => set(current, {
52
+ ...conf,
53
+ dir: argv.dir,
54
+ file: argv.file,
55
+ input,
56
+ key: argv.key,
57
+ }), (done) => {
58
+ p(valueSet(done));
59
+ }, `arc value set ${what}`);
60
+ },
61
+ summary: "Set a value, its JSON from a file or standard input",
62
+ });
@@ -0,0 +1,69 @@
1
+ // [import]
2
+ import { defineCommand } from "../../cli/command.js";
3
+ import { p } from "../../util/log.js";
4
+ import { CHANNEL, CWD, JSON_OUTPUT, QUIET } from "../../cli/options.js";
5
+ import { run } from "../function/secret/run.js";
6
+ import { table } from "../../util/table.js";
7
+ import { usage } from "../../action/value/tool.js";
8
+ // [declare]
9
+ // each scope as it's said: a player's limits are each player's own.
10
+ const NAMES = {
11
+ developer: "developer",
12
+ game: "game",
13
+ player: "players",
14
+ server: "server",
15
+ };
16
+ // [function]
17
+ // a size in the unit that reads best: "0", "812 B", "14 KB", "2.4 MB".
18
+ function size(bytes) {
19
+ if (bytes < 1024) {
20
+ return bytes === 0 ? "0" : `${bytes} B`;
21
+ }
22
+ if (bytes < 1024 * 1024) {
23
+ return `${Math.round(bytes / 1024)} KB`;
24
+ }
25
+ return `${(bytes / (1024 * 1024)).toFixed(1).replace(/\.0$/u, "")} MB`;
26
+ }
27
+ // [function]
28
+ // the scopes as a table. A player's row counts every player's together, and
29
+ // its limit is what each may hold, so the most any one holds is beside it.
30
+ function rows(scopes) {
31
+ return table([
32
+ ["SCOPE", "KEYS", "SIZE", "MAY HOLD"],
33
+ ...scopes.map((each) => {
34
+ const players = each.scope === "player";
35
+ const limit = `${each.keys_limit.toLocaleString("en-US")} keys, ${size(each.bytes_limit)}`;
36
+ return [
37
+ NAMES[each.scope] ?? each.scope,
38
+ players
39
+ ? `${each.keys} (${each.owners} ${each.owners === 1 ? "player" : "players"}, ${each.keys_most} at most)`
40
+ : String(each.keys),
41
+ players
42
+ ? `${size(each.bytes)} (${size(each.bytes_most)} at most)`
43
+ : size(each.bytes),
44
+ players ? `${limit} each` : limit,
45
+ ];
46
+ }),
47
+ ]);
48
+ }
49
+ // [function]
50
+ // the game's clients' calls today: this channel's, then the game's against
51
+ // its allowance, which both channels share and the day (UTC) renews.
52
+ function called(calls) {
53
+ const n = (count) => count.toLocaleString("en-US");
54
+ return `Calls from the game today: ${n(calls.reads)} reads, ${n(calls.writes)} writes on ${calls.channel}. ${n(calls.used)} of ${n(calls.allowance)} for the day, both channels together.`;
55
+ }
56
+ // [export]
57
+ export default defineCommand({
58
+ name: "usage",
59
+ options: { ...CHANNEL, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
60
+ run(argv, aborting) {
61
+ return run(argv, aborting, usage, ({ calls, scopes }) => {
62
+ p(rows(scopes));
63
+ if (calls) {
64
+ p(`\n${called(calls)}`);
65
+ }
66
+ }, "arc value usage");
67
+ },
68
+ summary: "Show how much the game's values hold, by scope",
69
+ });
package/dist/commands.js CHANGED
@@ -77,7 +77,8 @@ export const COMMANDS = [
77
77
  name: "logout",
78
78
  summary: `Log out of ${title}`,
79
79
  },
80
- // left out of `arc --help` until functions and keys ship, with the docs.
80
+ // left out of `arc --help` until functions, keys, and values ship, with the
81
+ // docs.
81
82
  {
82
83
  hidden: true,
83
84
  load: () => import("./command/function/index.js"),
@@ -90,4 +91,10 @@ export const COMMANDS = [
90
91
  name: "server",
91
92
  summary: "Make, list, and revoke your server's keys",
92
93
  },
94
+ {
95
+ hidden: true,
96
+ load: () => import("./command/value/index.js"),
97
+ name: "value",
98
+ summary: "Set, get, list, and remove the values you publish for the game",
99
+ },
93
100
  ];
@@ -128,3 +128,12 @@ export function unableToParse(file, message) {
128
128
  export function unableToReach() {
129
129
  return blocks(`Unable to reach ${TITLE}.`, "Check your internet connection, and try again.");
130
130
  }
131
+ // [function]
132
+ // an answer of the API's that isn't what this version reads: a newer
133
+ // Arcadible than this arc, most likely.
134
+ export function answerUnread(what) {
135
+ return [
136
+ `Unable to read ${TITLE}'s answer for ${what}.`,
137
+ "This arc may be out of date. Update it with `npm install -g arcadible`.",
138
+ ].join("\n");
139
+ }
@@ -27,7 +27,15 @@ export function gameHandleTaken(handle) {
27
27
  // a git release that would change the game's handle, which only a direct
28
28
  // deploy does.
29
29
  export function gameHandleChanged(handle, current) {
30
- return blocks(`The handle in ${MANIFEST} (${handle ?? "none"}) isn't the game's on ${TITLE} (${current ?? "none"}).`, `Only ${cmdDeploy()} changes a handle: deploy with it, or set the handle back.`);
30
+ // a sentence a line, so no line runs long whatever the handles are
31
+ return blocks([
32
+ handle
33
+ ? `The handle in ${MANIFEST} is ${handle}.`
34
+ : `${MANIFEST} has no handle.`,
35
+ current
36
+ ? `The game's handle on ${TITLE} is ${current}.`
37
+ : `The game has no handle on ${TITLE}.`,
38
+ ].join("\n"), `Only ${cmdDeploy()} changes a handle: deploy with it, or set the handle back.`);
31
39
  }
32
40
  // [function]
33
41
  export function gameHandleLapsed(handle) {
@@ -86,11 +86,15 @@ export function secretLimitReached(channel) {
86
86
  }
87
87
  // [function]
88
88
  export function secretNotFound({ channel, name, }) {
89
- return blocks(`Secret not found: ${name}`, `It isn't set for ${channel}. \`arc function secret list\` shows the game's secrets.`);
89
+ return blocks(`Secret not found: ${name}`, `It isn't set for ${channel}.\n\`arc function secret list\` shows the game's secrets.`);
90
90
  }
91
91
  // [function]
92
92
  export function secretNameInvalid() {
93
- return "A secret's name is in capitals, such as EXAMPLE_KEY: letters, digits, and underscores, up to 64, starting with a letter and not with ARCADIBLE_.";
93
+ return [
94
+ "A secret's name is in capitals, such as EXAMPLE_KEY.",
95
+ "It holds letters, digits, and underscores, up to 64 characters.",
96
+ "It starts with a letter, and not with ARCADIBLE_.",
97
+ ].join("\n");
94
98
  }
95
99
  // [function]
96
100
  export function secretValueInvalid() {
@@ -13,3 +13,4 @@ export * from "./media.js";
13
13
  export * from "./pack.js";
14
14
  export * from "./serve.js";
15
15
  export * from "./server.js";
16
+ export * from "./value.js";
@@ -21,7 +21,7 @@ export function keyLimitReached(channel) {
21
21
  }
22
22
  // [function]
23
23
  export function keyNotFound(id) {
24
- return blocks(`Key not found: ${id}`, "It was revoked already, or isn't this game's. `arc server key list` shows the game's keys.");
24
+ return blocks(`Key not found: ${id}`, "It was revoked already, or isn't this game's.\n`arc server key list` shows the game's keys.");
25
25
  }
26
26
  // [function]
27
27
  export function keyNameInvalid() {
@@ -0,0 +1,55 @@
1
+ // [import]
2
+ import { blocks } from "./internal.js";
3
+ // [function]
4
+ export function valueKeyInvalid(key) {
5
+ return blocks(`Not a key: ${key}`, "A key is 1 to 128 letters, digits, -, _, ., and /.");
6
+ }
7
+ // [function]
8
+ // `arc value set` given neither a key nor a folder, or both.
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.");
11
+ }
12
+ // [function]
13
+ // a value that isn't JSON: `source` is its file, or standard input.
14
+ export function valueNotJson(source) {
15
+ return blocks(`Not JSON: ${source}`, 'A value is JSON: an object, a list, a number, true, false, null, or text in double quotes ("hello").');
16
+ }
17
+ // [function]
18
+ export function valueFileUnread(path) {
19
+ return `Can't read ${path}.`;
20
+ }
21
+ // [function]
22
+ export function valueDirEmpty(dir) {
23
+ return blocks(`No values in ${dir}.`, "Each .json file there is a value, and its path its key: daily/2026-11-12.json is daily/2026-11-12.");
24
+ }
25
+ // [function]
26
+ export function valueTooLarge(key) {
27
+ return blocks(`Too large: ${key}`, "A value is up to 64 KB of JSON.");
28
+ }
29
+ // [function]
30
+ export function valueFull(channel) {
31
+ return blocks(`The developer's values on ${channel} are full.`, "They hold 10,000 keys and 64 MB. Remove some with `arc value remove <key>`, then try again.");
32
+ }
33
+ // [function]
34
+ export function valueSet({ channel, keys, }) {
35
+ const [only] = keys;
36
+ return keys.length === 1 && only !== undefined
37
+ ? `Set ${only} on ${channel}.`
38
+ : `Set ${keys.length} values on ${channel}.`;
39
+ }
40
+ // [function]
41
+ 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.`);
43
+ }
44
+ // [function]
45
+ export function valueRemoveQuestion({ channel, key, }) {
46
+ return `Remove ${key} from ${channel}? Games read nothing for it from then on.`;
47
+ }
48
+ // [function]
49
+ export function valueRemoved({ channel, key, }) {
50
+ return `Removed ${key} from ${channel}.`;
51
+ }
52
+ // [function]
53
+ export function valueNone() {
54
+ return "No values.";
55
+ }
@@ -1,9 +1,11 @@
1
- // a game's runner, bundled: its server code (plan/SERVERS.md, Runners) as one
2
- // module, as Arcadible runs it. The developer's handler is never the entry:
3
- // it's wrapped in Arcadible's own, which is where what the platform does for
4
- // a runner goes, before the developer's code sees a request.
1
+ // a game's runner, bundled: its server code (plan/SERVERS.md, Runners) with
2
+ // what it imports, as one module whose default export is the developer's
3
+ // handler. It's the developer's code alone: Arcadible's entry, which is
4
+ // where a function's script starts, is added beside it where it runs, by
5
+ // the pipeline as a build is released, and by arc serve (./entry.ts), so no
6
+ // build carries an entry of the day its `arc` was installed.
5
7
  // [import]
6
- import { dirname, join } from "node:path";
8
+ import { join } from "node:path";
7
9
  // [import]
8
10
  import { build } from "esbuild";
9
11
  import { pathExists } from "fs-extra";
@@ -15,60 +17,8 @@ import { ArcError } from "../util/error.js";
15
17
  // where `arc build` writes the bundle, in arc's own folder in the project,
16
18
  // and where `arc pack` puts it in the package: the folder every build's
17
19
  // origin keeps for Arcadible's own files, which is never served.
18
- export const BUILT = join(".arc", "runner", "runner.js");
19
- export const PACKED = "arcadible/runner.js";
20
- // [function]
21
- // the module a runtime runs: the runner's own handler, behind Arcadible's
22
- // own. The runtime gives a Worker its settings as an argument, while the
23
- // server's SDK reads the process's environment, so what's set is passed
24
- // through: the address of Arcadible (ARCADIBLE_SERVE, under arc serve), and
25
- // the claim Arcadible made for this request (the dispatcher's
26
- // x-arcadible-claim, plan/SERVERS.md), which the SDK sends in a key's place. Every claim is for
27
- // this build's runner, so the newest serves every request in flight. The
28
- // environment is changed in place, since the SDK keeps the one it first read;
29
- // the runner's secrets come the same way (the dispatcher's
30
- // x-arcadible-secrets, opened there), and are added to what the code is
31
- // given, `env`, where arc serve's are already. Neither header reaches the
32
- // runner's code.
33
- function entry(main) {
34
- return `import handler from ${JSON.stringify(main)};
35
- const CLAIM = "x-arcadible-claim";
36
- const SECRETS = "x-arcadible-secrets";
37
- // says the code is running as a function, where Arcadible has checked each
38
- // request: the Server SDK's players.primary(request) works only with it
39
- globalThis[Symbol.for("arcadible.function")] = true;
40
- export default {
41
- async fetch(request, env, ctx) {
42
- const process = (globalThis.process ??= {});
43
- const set = (process.env ??= {});
44
- if (env.ARCADIBLE_SERVE) set.ARCADIBLE_SERVE = env.ARCADIBLE_SERVE;
45
- const claim = request.headers.get(CLAIM);
46
- const secrets = request.headers.get(SECRETS);
47
- if (claim) {
48
- set.ARCADIBLE_CLAIM = claim;
49
- } else {
50
- delete set.ARCADIBLE_CLAIM;
51
- }
52
- let given = env;
53
- if (secrets) {
54
- const text = atob(secrets.replace(/-/g, "+").replace(/_/g, "/"));
55
- const bytes = Uint8Array.from(text, (char) => char.charCodeAt(0));
56
- given = { ...env, ...JSON.parse(new TextDecoder().decode(bytes)) };
57
- }
58
- if (claim || secrets) {
59
- const headers = new Headers(request.headers);
60
- headers.delete(CLAIM);
61
- headers.delete(SECRETS);
62
- request = new Request(request, { headers });
63
- }
64
- if (typeof handler?.fetch !== "function") {
65
- return new Response("The function's default export has no fetch(request).\\n", { status: 500 });
66
- }
67
- return handler.fetch(request, given, ctx);
68
- },
69
- };
70
- `;
71
- }
20
+ export const BUILT = join(".arc", "runner", "function.js");
21
+ export const PACKED = "arcadible/function.js";
72
22
  // [function]
73
23
  // bundles the runner whose code is at `main`, a full path, into `outfile`;
74
24
  // code that isn't there, or doesn't build, fails as a build does.
@@ -84,7 +34,7 @@ export async function bundle({ main, outfile, }) {
84
34
  logLevel: "silent",
85
35
  outfile,
86
36
  platform: "neutral",
87
- stdin: { contents: entry(main), loader: "js", resolveDir: dirname(main) },
37
+ entryPoints: [main],
88
38
  target: "es2022",
89
39
  });
90
40
  }
@@ -0,0 +1,57 @@
1
+ // Arcadible's entry for a game's function: the module a function's script
2
+ // starts in, around the developer's own, which is the module beside it. On
3
+ // Arcadible it's added as a build is released, by the pipeline
4
+ // (app/src/lambda/io-arcadible-release-queue-subscriber/src/entry.mts), so a
5
+ // build runs the entry of the day it was released, whichever `arc` built
6
+ // it. `arc serve` runs the same one, from here: the text is the pipeline's,
7
+ // to the letter, which test/unit/runner/entry.test.mjs holds. Change both
8
+ // together.
9
+ // [declare]
10
+ // the script's two modules: Arcadible's entry, its main one, and the
11
+ // developer's bundle, whose default export is their handler.
12
+ export const ENTRY_MODULE = "entry.js";
13
+ export const FUNCTION_MODULE = "function.js";
14
+ // [declare]
15
+ // A runner's calls to Arcadible carry the dispatcher's claim, which the
16
+ // dispatcher puts on each request (x-arcadible-claim), and the Server SDK
17
+ // reads from the process's environment, where arc serve's address is too.
18
+ // Its secrets arrive the same way (x-arcadible-secrets, opened by the
19
+ // dispatcher), and are added to what the code is given, `env`. Neither
20
+ // header reaches the developer's code.
21
+ export const ENTRY = `import handler from "./${FUNCTION_MODULE}";
22
+ const CLAIM = "x-arcadible-claim";
23
+ const SECRETS = "x-arcadible-secrets";
24
+ // says the code is running as a function, where Arcadible has checked each
25
+ // request: the Server SDK's players.primary(request) works only with it
26
+ globalThis[Symbol.for("arcadible.function")] = true;
27
+ export default {
28
+ async fetch(request, env, ctx) {
29
+ const process = (globalThis.process ??= {});
30
+ const set = (process.env ??= {});
31
+ if (env.ARCADIBLE_SERVE) set.ARCADIBLE_SERVE = env.ARCADIBLE_SERVE;
32
+ const claim = request.headers.get(CLAIM);
33
+ const secrets = request.headers.get(SECRETS);
34
+ if (claim) {
35
+ set.ARCADIBLE_CLAIM = claim;
36
+ } else {
37
+ delete set.ARCADIBLE_CLAIM;
38
+ }
39
+ let given = env;
40
+ if (secrets) {
41
+ const text = atob(secrets.replace(/-/g, "+").replace(/_/g, "/"));
42
+ const bytes = Uint8Array.from(text, (char) => char.charCodeAt(0));
43
+ given = { ...env, ...JSON.parse(new TextDecoder().decode(bytes)) };
44
+ }
45
+ if (claim || secrets) {
46
+ const headers = new Headers(request.headers);
47
+ headers.delete(CLAIM);
48
+ headers.delete(SECRETS);
49
+ request = new Request(request, { headers });
50
+ }
51
+ if (typeof handler?.fetch !== "function") {
52
+ return new Response("The function's default export has no fetch(request).\\n", { status: 500 });
53
+ }
54
+ return handler.fetch(request, given, ctx);
55
+ },
56
+ };
57
+ `;
@@ -39,7 +39,7 @@ export function refuse(url) {
39
39
  }
40
40
  return Response.json({
41
41
  code: CODE,
42
- message: `The function may not call ${host}: add it to function.outbound_hosts in arcadible.toml, as a name reached over HTTPS.`,
42
+ message: `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
43
  }, { status: STATUS });
44
44
  }
45
45
  // [function]
@@ -29,7 +29,7 @@ function typeMessage(issue) {
29
29
  return undefined;
30
30
  }
31
31
  const branch = Array.isArray(issue.input) ? 1 : 0;
32
- return issue.errors?.[branch]?.[0]?.message;
32
+ return issue.errors[branch]?.[0]?.message;
33
33
  }
34
34
  // [function]
35
35
  function zBuild() {