@relayflows/sdk 2.0.29 → 2.0.31
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/dist/agent-artifacts.d.ts.map +1 -1
- package/dist/agent-artifacts.js +2 -9
- package/dist/agent-artifacts.js.map +1 -1
- package/dist/agent-cwd.d.ts +69 -0
- package/dist/agent-cwd.d.ts.map +1 -0
- package/dist/agent-cwd.js +140 -0
- package/dist/agent-cwd.js.map +1 -0
- package/dist/artifact-scan-policy.d.ts +35 -0
- package/dist/artifact-scan-policy.d.ts.map +1 -0
- package/dist/artifact-scan-policy.js +49 -0
- package/dist/artifact-scan-policy.js.map +1 -0
- package/dist/authored-completion-record.d.ts +35 -0
- package/dist/authored-completion-record.d.ts.map +1 -0
- package/dist/authored-completion-record.js +92 -0
- package/dist/authored-completion-record.js.map +1 -0
- package/dist/authored-completion.d.ts +99 -0
- package/dist/authored-completion.d.ts.map +1 -0
- package/dist/authored-completion.js +184 -0
- package/dist/authored-completion.js.map +1 -0
- package/dist/authored-flow-error.d.ts +13 -1
- package/dist/authored-flow-error.d.ts.map +1 -1
- package/dist/authored-flow-error.js +12 -0
- package/dist/authored-flow-error.js.map +1 -1
- package/dist/authored-flow-executor.d.ts +7 -30
- package/dist/authored-flow-executor.d.ts.map +1 -1
- package/dist/authored-flow-executor.js +64 -48
- package/dist/authored-flow-executor.js.map +1 -1
- package/dist/authored-human.d.ts.map +1 -1
- package/dist/authored-human.js +1 -3
- package/dist/authored-human.js.map +1 -1
- package/dist/authored-node-entry.js +4 -1
- package/dist/authored-node-entry.js.map +1 -1
- package/dist/authored-node-runner.d.ts +9 -1
- package/dist/authored-node-runner.d.ts.map +1 -1
- package/dist/authored-node-runner.js +92 -17
- package/dist/authored-node-runner.js.map +1 -1
- package/dist/authored-root.d.ts +5 -0
- package/dist/authored-root.d.ts.map +1 -1
- package/dist/authored-root.js +20 -2
- package/dist/authored-root.js.map +1 -1
- package/dist/authored-step-output.d.ts +35 -10
- package/dist/authored-step-output.d.ts.map +1 -1
- package/dist/authored-step-output.js +108 -40
- package/dist/authored-step-output.js.map +1 -1
- package/dist/authored-verdict.d.ts +28 -0
- package/dist/authored-verdict.d.ts.map +1 -0
- package/dist/authored-verdict.js +79 -0
- package/dist/authored-verdict.js.map +1 -0
- package/dist/authored-worker-step.d.ts +5 -2
- package/dist/authored-worker-step.d.ts.map +1 -1
- package/dist/authored-worker-step.js +48 -11
- package/dist/authored-worker-step.js.map +1 -1
- package/dist/bundle-extensions.d.ts.map +1 -1
- package/dist/bundle-extensions.js +4 -7
- package/dist/bundle-extensions.js.map +1 -1
- package/dist/bundle.d.ts.map +1 -1
- package/dist/bundle.js +41 -7
- package/dist/bundle.js.map +1 -1
- package/dist/canonical.d.ts.map +1 -1
- package/dist/canonical.js +18 -6
- package/dist/canonical.js.map +1 -1
- package/dist/cli/check-worker-surface.d.ts +27 -0
- package/dist/cli/check-worker-surface.d.ts.map +1 -0
- package/dist/cli/check-worker-surface.js +63 -0
- package/dist/cli/check-worker-surface.js.map +1 -0
- package/dist/cli/check.d.ts +19 -2
- package/dist/cli/check.d.ts.map +1 -1
- package/dist/cli/check.js +12 -4
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/cloud-format.d.ts +9 -0
- package/dist/cli/cloud-format.d.ts.map +1 -0
- package/dist/cli/cloud-format.js +77 -0
- package/dist/cli/cloud-format.js.map +1 -0
- package/dist/cli/cloud-live.d.ts +39 -0
- package/dist/cli/cloud-live.d.ts.map +1 -0
- package/dist/cli/cloud-live.js +325 -0
- package/dist/cli/cloud-live.js.map +1 -0
- package/dist/cli/cloud-read.d.ts +3 -7
- package/dist/cli/cloud-read.d.ts.map +1 -1
- package/dist/cli/cloud-read.js +14 -266
- package/dist/cli/cloud-read.js.map +1 -1
- package/dist/cli/cloud-refusal.d.ts +39 -0
- package/dist/cli/cloud-refusal.d.ts.map +1 -0
- package/dist/cli/cloud-refusal.js +95 -0
- package/dist/cli/cloud-refusal.js.map +1 -0
- package/dist/cli/cloud-status-view.d.ts +7 -0
- package/dist/cli/cloud-status-view.d.ts.map +1 -0
- package/dist/cli/cloud-status-view.js +214 -0
- package/dist/cli/cloud-status-view.js.map +1 -0
- package/dist/cli/direct-run.d.ts.map +1 -1
- package/dist/cli/direct-run.js +16 -2
- package/dist/cli/direct-run.js.map +1 -1
- package/dist/cli/hn-monitor.d.ts +0 -13
- package/dist/cli/hn-monitor.d.ts.map +1 -1
- package/dist/cli/hn-monitor.js +2 -1
- package/dist/cli/hn-monitor.js.map +1 -1
- package/dist/cli/local-agent-remedy.d.ts +80 -0
- package/dist/cli/local-agent-remedy.d.ts.map +1 -0
- package/dist/cli/local-agent-remedy.js +116 -0
- package/dist/cli/local-agent-remedy.js.map +1 -0
- package/dist/cli/observer-session.d.ts +41 -0
- package/dist/cli/observer-session.d.ts.map +1 -0
- package/dist/cli/observer-session.js +78 -0
- package/dist/cli/observer-session.js.map +1 -0
- package/dist/cli/run.d.ts +30 -2
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +186 -24
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/status.d.ts +9 -0
- package/dist/cli/status.d.ts.map +1 -1
- package/dist/cli/status.js +31 -2
- package/dist/cli/status.js.map +1 -1
- package/dist/cli/step-evidence.d.ts +90 -0
- package/dist/cli/step-evidence.d.ts.map +1 -0
- package/dist/cli/step-evidence.js +259 -0
- package/dist/cli/step-evidence.js.map +1 -0
- package/dist/cli/step-failure.d.ts +14 -4
- package/dist/cli/step-failure.d.ts.map +1 -1
- package/dist/cli/step-failure.js +41 -76
- package/dist/cli/step-failure.js.map +1 -1
- package/dist/cli-commands.d.ts +6 -0
- package/dist/cli-commands.d.ts.map +1 -1
- package/dist/cli-commands.js +2 -0
- package/dist/cli-commands.js.map +1 -1
- package/dist/cli.d.ts +10 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +53 -42
- package/dist/cli.js.map +1 -1
- package/dist/cloud-read.d.ts +15 -0
- package/dist/cloud-read.d.ts.map +1 -1
- package/dist/cloud-read.js +20 -1
- package/dist/cloud-read.js.map +1 -1
- package/dist/cloud-run-record.d.ts +27 -0
- package/dist/cloud-run-record.d.ts.map +1 -0
- package/dist/cloud-run-record.js +56 -0
- package/dist/cloud-run-record.js.map +1 -0
- package/dist/cloud-run.d.ts +2 -9
- package/dist/cloud-run.d.ts.map +1 -1
- package/dist/cloud-run.js +3 -20
- package/dist/cloud-run.js.map +1 -1
- package/dist/communication/local.d.ts.map +1 -1
- package/dist/communication/local.js +2 -1
- package/dist/communication/local.js.map +1 -1
- package/dist/communication/worker.d.ts +1 -1
- package/dist/communication/worker.d.ts.map +1 -1
- package/dist/communication/worker.js +13 -5
- package/dist/communication/worker.js.map +1 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +28 -6
- package/dist/compile.js.map +1 -1
- package/dist/direct-input.d.ts.map +1 -1
- package/dist/direct-input.js +21 -1
- package/dist/direct-input.js.map +1 -1
- package/dist/failure-kinds.d.ts +96 -6
- package/dist/failure-kinds.d.ts.map +1 -1
- package/dist/failure-kinds.js +29 -2
- package/dist/failure-kinds.js.map +1 -1
- package/dist/flow-extension-compat.d.ts.map +1 -1
- package/dist/flow-extension-compat.js +26 -8
- package/dist/flow-extension-compat.js.map +1 -1
- package/dist/flow-extension-loader.d.ts +7 -0
- package/dist/flow-extension-loader.d.ts.map +1 -1
- package/dist/flow-extension-loader.js +48 -22
- package/dist/flow-extension-loader.js.map +1 -1
- package/dist/flow-requirements.d.ts.map +1 -1
- package/dist/flow-requirements.js +24 -9
- package/dist/flow-requirements.js.map +1 -1
- package/dist/fs-descriptor.d.ts +17 -0
- package/dist/fs-descriptor.d.ts.map +1 -0
- package/dist/fs-descriptor.js +96 -0
- package/dist/fs-descriptor.js.map +1 -0
- package/dist/gate-contract.d.ts +7 -0
- package/dist/gate-contract.d.ts.map +1 -1
- package/dist/gate-contract.js +6 -1
- package/dist/gate-contract.js.map +1 -1
- package/dist/helper-preflight.d.ts.map +1 -1
- package/dist/helper-preflight.js +10 -3
- package/dist/helper-preflight.js.map +1 -1
- package/dist/helper-reference.d.ts +25 -0
- package/dist/helper-reference.d.ts.map +1 -0
- package/dist/helper-reference.js +129 -0
- package/dist/helper-reference.js.map +1 -0
- package/dist/hosted-base-snapshot.d.ts +25 -0
- package/dist/hosted-base-snapshot.d.ts.map +1 -0
- package/dist/hosted-base-snapshot.js +278 -0
- package/dist/hosted-base-snapshot.js.map +1 -0
- package/dist/hosted-extension-declarations.d.ts +10 -0
- package/dist/hosted-extension-declarations.d.ts.map +1 -0
- package/dist/hosted-extension-declarations.js +272 -0
- package/dist/hosted-extension-declarations.js.map +1 -0
- package/dist/hosted-extension-isolation.d.ts +82 -0
- package/dist/hosted-extension-isolation.d.ts.map +1 -0
- package/dist/hosted-extension-isolation.js +322 -0
- package/dist/hosted-extension-isolation.js.map +1 -0
- package/dist/hosted-extension-manifest.d.ts +9 -0
- package/dist/hosted-extension-manifest.d.ts.map +1 -0
- package/dist/hosted-extension-manifest.js +235 -0
- package/dist/hosted-extension-manifest.js.map +1 -0
- package/dist/hosted-extension-protocol.d.ts +16 -0
- package/dist/hosted-extension-protocol.d.ts.map +1 -0
- package/dist/hosted-extension-protocol.js +224 -0
- package/dist/hosted-extension-protocol.js.map +1 -0
- package/dist/hosted-extension-runtime.d.ts +30 -0
- package/dist/hosted-extension-runtime.d.ts.map +1 -0
- package/dist/hosted-extension-runtime.js +167 -0
- package/dist/hosted-extension-runtime.js.map +1 -0
- package/dist/hosted-extension-sandbox-source.d.ts +9 -0
- package/dist/hosted-extension-sandbox-source.d.ts.map +1 -0
- package/dist/hosted-extension-sandbox-source.js +95 -0
- package/dist/hosted-extension-sandbox-source.js.map +1 -0
- package/dist/hosted-extension-sandbox.d.ts +39 -0
- package/dist/hosted-extension-sandbox.d.ts.map +1 -0
- package/dist/hosted-extension-sandbox.js +418 -0
- package/dist/hosted-extension-sandbox.js.map +1 -0
- package/dist/hosted-project.d.ts +3 -0
- package/dist/hosted-project.d.ts.map +1 -0
- package/dist/hosted-project.js +19 -0
- package/dist/hosted-project.js.map +1 -0
- package/dist/hosted-promise-safety.d.ts +12 -0
- package/dist/hosted-promise-safety.d.ts.map +1 -0
- package/dist/hosted-promise-safety.js +63 -0
- package/dist/hosted-promise-safety.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/intrinsic-array.d.ts +3 -0
- package/dist/intrinsic-array.d.ts.map +1 -0
- package/dist/intrinsic-array.js +14 -0
- package/dist/intrinsic-array.js.map +1 -0
- package/dist/journal-client.d.ts +3 -1
- package/dist/journal-client.d.ts.map +1 -1
- package/dist/journal-client.js +17 -2
- package/dist/journal-client.js.map +1 -1
- package/dist/journal-projection.d.ts +16 -0
- package/dist/journal-projection.d.ts.map +1 -0
- package/dist/journal-projection.js +108 -0
- package/dist/journal-projection.js.map +1 -0
- package/dist/json-value.d.ts +6 -1
- package/dist/json-value.d.ts.map +1 -1
- package/dist/json-value.js +155 -36
- package/dist/json-value.js.map +1 -1
- package/dist/llm-worker.d.ts +9 -0
- package/dist/llm-worker.d.ts.map +1 -1
- package/dist/llm-worker.js +16 -2
- package/dist/llm-worker.js.map +1 -1
- package/dist/local-agent.d.ts +1 -1
- package/dist/local-agent.d.ts.map +1 -1
- package/dist/local-agent.js +4 -3
- package/dist/local-agent.js.map +1 -1
- package/dist/named-gate-lowering.js +35 -5
- package/dist/named-gate-lowering.js.map +1 -1
- package/dist/named-gate-preflight.d.ts +27 -0
- package/dist/named-gate-preflight.d.ts.map +1 -0
- package/dist/named-gate-preflight.js +47 -0
- package/dist/named-gate-preflight.js.map +1 -0
- package/dist/named-gates.d.ts +1 -1
- package/dist/named-gates.d.ts.map +1 -1
- package/dist/named-gates.js +3 -0
- package/dist/named-gates.js.map +1 -1
- package/dist/observer-link.d.ts +7 -0
- package/dist/observer-link.d.ts.map +1 -1
- package/dist/observer-link.js +3 -1
- package/dist/observer-link.js.map +1 -1
- package/dist/plugin-store.d.ts +8 -2
- package/dist/plugin-store.d.ts.map +1 -1
- package/dist/plugin-store.js +233 -56
- package/dist/plugin-store.js.map +1 -1
- package/dist/preflight.d.ts.map +1 -1
- package/dist/preflight.js +7 -0
- package/dist/preflight.js.map +1 -1
- package/dist/protocol.d.ts +2 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/redact.d.ts +42 -0
- package/dist/redact.d.ts.map +1 -1
- package/dist/redact.js +128 -0
- package/dist/redact.js.map +1 -1
- package/dist/run-projection.d.ts +83 -0
- package/dist/run-projection.d.ts.map +1 -0
- package/dist/run-projection.js +199 -0
- package/dist/run-projection.js.map +1 -0
- package/dist/semver-range.d.ts.map +1 -1
- package/dist/semver-range.js +27 -15
- package/dist/semver-range.js.map +1 -1
- package/dist/shell-word.d.ts +19 -0
- package/dist/shell-word.d.ts.map +1 -0
- package/dist/shell-word.js +23 -0
- package/dist/shell-word.js.map +1 -0
- package/dist/spec.d.ts +52 -3
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js.map +1 -1
- package/dist/step-fields.d.ts +1 -1
- package/dist/step-fields.js +1 -1
- package/dist/step-fields.js.map +1 -1
- package/dist/steps-green.d.ts +27 -0
- package/dist/steps-green.d.ts.map +1 -0
- package/dist/steps-green.js +164 -0
- package/dist/steps-green.js.map +1 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +39 -8
- package/dist/validate.js.map +1 -1
- package/dist/worker-lease.d.ts +8 -1
- package/dist/worker-lease.d.ts.map +1 -1
- package/dist/worker-lease.js +34 -4
- package/dist/worker-lease.js.map +1 -1
- package/dist/worker.d.ts +8 -0
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +17 -9
- package/dist/worker.js.map +1 -1
- package/package.json +3 -7
- package/src/agent-artifacts.ts +2 -10
- package/src/agent-cwd.ts +139 -0
- package/src/artifact-scan-policy.ts +51 -0
- package/src/authored-completion-record.ts +119 -0
- package/src/authored-completion.ts +203 -0
- package/src/authored-flow-error.ts +13 -1
- package/src/authored-flow-executor.ts +101 -59
- package/src/authored-human.ts +1 -4
- package/src/authored-node-entry.ts +4 -1
- package/src/authored-node-runner.ts +96 -22
- package/src/authored-root.ts +20 -2
- package/src/authored-step-output.ts +139 -42
- package/src/authored-verdict.ts +87 -0
- package/src/authored-worker-step.ts +60 -12
- package/src/bundle-extensions.ts +6 -5
- package/src/bundle.ts +52 -7
- package/src/canonical.ts +20 -6
- package/src/cli/check-worker-surface.ts +66 -0
- package/src/cli/check.ts +35 -4
- package/src/cli/cloud-format.ts +82 -0
- package/src/cli/cloud-live.ts +366 -0
- package/src/cli/cloud-read.ts +13 -282
- package/src/cli/cloud-refusal.ts +113 -0
- package/src/cli/cloud-status-view.ts +213 -0
- package/src/cli/direct-run.ts +19 -2
- package/src/cli/hn-monitor.ts +2 -1
- package/src/cli/local-agent-remedy.ts +160 -0
- package/src/cli/observer-session.ts +107 -0
- package/src/cli/run.ts +233 -28
- package/src/cli/status.ts +59 -3
- package/src/cli/step-evidence.ts +310 -0
- package/src/cli/step-failure.ts +57 -81
- package/src/cli-commands.ts +2 -0
- package/src/cli.ts +64 -44
- package/src/cloud-read.ts +25 -1
- package/src/cloud-run-record.ts +64 -0
- package/src/cloud-run.ts +5 -24
- package/src/communication/local.ts +2 -1
- package/src/communication/worker.ts +13 -5
- package/src/compile.ts +28 -6
- package/src/direct-input.ts +22 -1
- package/src/failure-kinds.ts +104 -2
- package/src/flow-extension-compat.ts +32 -7
- package/src/flow-extension-loader.ts +56 -21
- package/src/flow-requirements.ts +24 -9
- package/src/fs-descriptor.ts +127 -0
- package/src/gate-contract.ts +13 -1
- package/src/helper-preflight.ts +10 -3
- package/src/helper-reference.ts +130 -0
- package/src/hosted-base-snapshot.ts +351 -0
- package/src/hosted-extension-declarations.ts +387 -0
- package/src/hosted-extension-isolation.ts +457 -0
- package/src/hosted-extension-manifest.ts +249 -0
- package/src/hosted-extension-protocol.ts +262 -0
- package/src/hosted-extension-runtime.ts +266 -0
- package/src/hosted-extension-sandbox-source.ts +94 -0
- package/src/hosted-extension-sandbox.ts +489 -0
- package/src/hosted-project.ts +18 -0
- package/src/hosted-promise-safety.ts +68 -0
- package/src/index.ts +20 -0
- package/src/intrinsic-array.ts +14 -0
- package/src/journal-client.ts +19 -2
- package/src/journal-projection.ts +106 -0
- package/src/json-value.ts +184 -32
- package/src/llm-worker.ts +16 -2
- package/src/local-agent.ts +4 -2
- package/src/named-gate-lowering.ts +35 -5
- package/src/named-gate-preflight.ts +47 -0
- package/src/named-gates.ts +3 -0
- package/src/observer-link.ts +10 -1
- package/src/plugin-store.ts +323 -56
- package/src/preflight.ts +7 -0
- package/src/protocol.ts +2 -0
- package/src/redact.ts +111 -0
- package/src/run-projection.ts +247 -0
- package/src/semver-range.ts +39 -14
- package/src/shell-word.ts +24 -0
- package/src/spec.ts +54 -3
- package/src/step-fields.ts +1 -1
- package/src/steps-green.ts +168 -0
- package/src/validate.ts +35 -8
- package/src/worker-lease.ts +35 -5
- package/src/worker.ts +27 -11
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import {
|
|
2
|
+
constants,
|
|
3
|
+
closeSync,
|
|
4
|
+
existsSync,
|
|
5
|
+
fstatSync,
|
|
6
|
+
openSync,
|
|
7
|
+
readSync,
|
|
8
|
+
} from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { safePath } from "./bundle.js";
|
|
11
|
+
import { canonicalize } from "./canonical.js";
|
|
12
|
+
import { descriptorIsFile } from "./fs-descriptor.js";
|
|
13
|
+
import { snapshotJsonValue } from "./json-value.js";
|
|
14
|
+
import { PluginError } from "./plugin-manifest.js";
|
|
15
|
+
import { appendIntrinsicArray } from "./intrinsic-array.js";
|
|
16
|
+
import {
|
|
17
|
+
PLUGIN_LOCK_FILE,
|
|
18
|
+
PLUGIN_LOCK_VERSION,
|
|
19
|
+
type PluginLockEntry,
|
|
20
|
+
} from "./plugin-lock.js";
|
|
21
|
+
import { canonicalPluginRef, type PluginSourceRef } from "./plugin-source.js";
|
|
22
|
+
|
|
23
|
+
const CLOSE_SYNC = closeSync;
|
|
24
|
+
const EXISTS_SYNC = existsSync;
|
|
25
|
+
const FSTAT_SYNC = fstatSync;
|
|
26
|
+
const OPEN_SYNC = openSync;
|
|
27
|
+
const READ_SYNC = readSync;
|
|
28
|
+
const PATH_JOIN = join;
|
|
29
|
+
const ERROR = Error;
|
|
30
|
+
const PLUGIN_ERROR_IS_INSTANCE = Function.prototype.call.bind(
|
|
31
|
+
Function.prototype[Symbol.hasInstance],
|
|
32
|
+
PluginError,
|
|
33
|
+
) as (value: unknown) => boolean;
|
|
34
|
+
const MAX_DECLARATION_BYTES = 1024 * 1024;
|
|
35
|
+
const BIG_INT = BigInt;
|
|
36
|
+
const BUFFER_ALLOC_UNSAFE = Buffer.allocUnsafe;
|
|
37
|
+
const BUFFER_TO_STRING = Function.prototype.call.bind(
|
|
38
|
+
Buffer.prototype.toString,
|
|
39
|
+
) as (value: Buffer, encoding: BufferEncoding) => string;
|
|
40
|
+
const NUMBER = Number;
|
|
41
|
+
const DECLARATION_READ_FLAGS =
|
|
42
|
+
constants.O_RDONLY |
|
|
43
|
+
(constants.O_NOFOLLOW ?? 0) |
|
|
44
|
+
(constants.O_NONBLOCK ?? 0);
|
|
45
|
+
const JSON_PARSE = JSON.parse;
|
|
46
|
+
const ARRAY_IS_ARRAY = Array.isArray;
|
|
47
|
+
const DATE_PARSE = Date.parse;
|
|
48
|
+
const NUMBER_IS_NAN = Number.isNaN;
|
|
49
|
+
const OBJECT_FREEZE = Object.freeze;
|
|
50
|
+
const OBJECT_HAS_OWN = Object.hasOwn;
|
|
51
|
+
const OBJECT_KEYS = Object.keys;
|
|
52
|
+
const REGEXP_TEST = Function.prototype.call.bind(RegExp.prototype.test) as (
|
|
53
|
+
regexp: RegExp,
|
|
54
|
+
value: string,
|
|
55
|
+
) => boolean;
|
|
56
|
+
const SET = Set;
|
|
57
|
+
const SET_ADD = Function.prototype.call.bind(Set.prototype.add) as <T>(
|
|
58
|
+
set: Set<T>,
|
|
59
|
+
value: T,
|
|
60
|
+
) => Set<T>;
|
|
61
|
+
const SET_HAS = Function.prototype.call.bind(Set.prototype.has) as <T>(
|
|
62
|
+
set: Set<T>,
|
|
63
|
+
value: T,
|
|
64
|
+
) => boolean;
|
|
65
|
+
const STRING_STARTS_WITH = Function.prototype.call.bind(
|
|
66
|
+
String.prototype.startsWith,
|
|
67
|
+
) as (value: string, search: string) => boolean;
|
|
68
|
+
const LOCK_HEX64 = /^[0-9a-f]{64}$/;
|
|
69
|
+
const LOCK_SHA = /^[0-9a-f]{40}$/;
|
|
70
|
+
const LOCK_OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/;
|
|
71
|
+
const LOCK_REPO = /^[A-Za-z0-9_.-]{1,100}$/;
|
|
72
|
+
const HTTPS_GITHUB = /^https:\/\/github\.com\//;
|
|
73
|
+
|
|
74
|
+
export interface HostedDeclaredExtension {
|
|
75
|
+
readonly ref: string;
|
|
76
|
+
readonly entry: PluginLockEntry;
|
|
77
|
+
readonly source: PluginSourceRef;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function declarationSignature(
|
|
81
|
+
declared: readonly HostedDeclaredExtension[],
|
|
82
|
+
): string {
|
|
83
|
+
const records: Array<{
|
|
84
|
+
ref: string;
|
|
85
|
+
name: string;
|
|
86
|
+
version: string;
|
|
87
|
+
digest: string;
|
|
88
|
+
manifestSha256: string;
|
|
89
|
+
}> = [];
|
|
90
|
+
for (let index = 0; index < declared.length; index += 1) {
|
|
91
|
+
const { ref, entry } = declared[index]!;
|
|
92
|
+
appendIntrinsicArray(records, {
|
|
93
|
+
ref,
|
|
94
|
+
name: entry.name,
|
|
95
|
+
version: entry.version,
|
|
96
|
+
digest: entry.digest,
|
|
97
|
+
manifestSha256: entry.manifestSha256,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return canonicalize(records);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function hostedDeclaredExtensions(
|
|
104
|
+
root: string,
|
|
105
|
+
): readonly HostedDeclaredExtension[] {
|
|
106
|
+
if (
|
|
107
|
+
EXISTS_SYNC(PATH_JOIN(root, "flows.json.tmp")) ||
|
|
108
|
+
EXISTS_SYNC(PATH_JOIN(root, `${PLUGIN_LOCK_FILE}.tmp`))
|
|
109
|
+
) {
|
|
110
|
+
throw new PluginError(
|
|
111
|
+
"plugin_lock_invalid",
|
|
112
|
+
"Hosted extension declarations have a pending transaction.",
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
let config: unknown;
|
|
116
|
+
try {
|
|
117
|
+
config = JSON_PARSE(
|
|
118
|
+
BUFFER_TO_STRING(
|
|
119
|
+
readBoundedDeclaration(PATH_JOIN(root, "flows.json")),
|
|
120
|
+
"utf8",
|
|
121
|
+
),
|
|
122
|
+
);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (PLUGIN_ERROR_IS_INSTANCE(error)) throw error;
|
|
125
|
+
throw new PluginError(
|
|
126
|
+
"plugin_manifest_invalid",
|
|
127
|
+
"Invalid or oversized flows.json.",
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
if (typeof config !== "object" || config === null || ARRAY_IS_ARRAY(config)) {
|
|
131
|
+
throw new PluginError(
|
|
132
|
+
"plugin_manifest_invalid",
|
|
133
|
+
"flows.json plugins must be strings.",
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
const plugins = OBJECT_HAS_OWN(config, "plugins")
|
|
137
|
+
? (config as { plugins?: unknown }).plugins
|
|
138
|
+
: undefined;
|
|
139
|
+
if (plugins !== undefined && !ARRAY_IS_ARRAY(plugins)) {
|
|
140
|
+
throw new PluginError(
|
|
141
|
+
"plugin_manifest_invalid",
|
|
142
|
+
"flows.json plugins must be strings.",
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
const declared: string[] = [];
|
|
146
|
+
if (plugins !== undefined) {
|
|
147
|
+
for (let index = 0; index < plugins.length; index += 1) {
|
|
148
|
+
const ref = plugins[index];
|
|
149
|
+
if (typeof ref !== "string") {
|
|
150
|
+
throw new PluginError(
|
|
151
|
+
"plugin_manifest_invalid",
|
|
152
|
+
"flows.json plugins must be strings.",
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (isHostedGithubPluginRef(ref)) appendIntrinsicArray(declared, ref);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
let lock: {
|
|
159
|
+
readonly version: 2;
|
|
160
|
+
readonly plugins: readonly PluginLockEntry[];
|
|
161
|
+
} = OBJECT_FREEZE({
|
|
162
|
+
version: PLUGIN_LOCK_VERSION,
|
|
163
|
+
plugins: OBJECT_FREEZE([]),
|
|
164
|
+
});
|
|
165
|
+
const lockPath = PATH_JOIN(root, PLUGIN_LOCK_FILE);
|
|
166
|
+
if (EXISTS_SYNC(lockPath)) {
|
|
167
|
+
let value: unknown;
|
|
168
|
+
try {
|
|
169
|
+
value = JSON_PARSE(
|
|
170
|
+
BUFFER_TO_STRING(readBoundedDeclaration(lockPath), "utf8"),
|
|
171
|
+
);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
if (PLUGIN_ERROR_IS_INSTANCE(error)) throw error;
|
|
174
|
+
throw new PluginError(
|
|
175
|
+
"plugin_lock_invalid",
|
|
176
|
+
`${PLUGIN_LOCK_FILE}: not valid or exceeds the hosted size limit.`,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
lock = parseHostedPluginLock(value);
|
|
180
|
+
}
|
|
181
|
+
if (declared.length !== lock.plugins.length) {
|
|
182
|
+
throw new PluginError(
|
|
183
|
+
"plugin_lock_invalid",
|
|
184
|
+
"Hosted flows.json and flows.lock.json declarations differ.",
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
const result: HostedDeclaredExtension[] = [];
|
|
188
|
+
for (let index = 0; index < lock.plugins.length; index += 1) {
|
|
189
|
+
const entry = lock.plugins[index]!;
|
|
190
|
+
const source = OBJECT_FREEZE({ ...entry.source, ref: entry.source.sha });
|
|
191
|
+
const ref = canonicalPluginRef(source);
|
|
192
|
+
if (declared[index] !== ref) {
|
|
193
|
+
throw new PluginError(
|
|
194
|
+
"plugin_lock_invalid",
|
|
195
|
+
"Hosted flows.lock.json order differs from flows.json.plugins.",
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
appendIntrinsicArray(result, OBJECT_FREEZE({ ref, entry, source }));
|
|
199
|
+
}
|
|
200
|
+
return OBJECT_FREEZE(result);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function parseHostedPluginLock(input: unknown): {
|
|
204
|
+
readonly version: 2;
|
|
205
|
+
readonly plugins: readonly PluginLockEntry[];
|
|
206
|
+
} {
|
|
207
|
+
let value: unknown;
|
|
208
|
+
try {
|
|
209
|
+
value = snapshotJsonValue(input, "hosted plugin lock");
|
|
210
|
+
} catch {
|
|
211
|
+
return invalidHostedLock(
|
|
212
|
+
`expected { version: ${PLUGIN_LOCK_VERSION}, plugins: [] }.`,
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
if (
|
|
216
|
+
!hostedRecord(value) ||
|
|
217
|
+
value.version !== PLUGIN_LOCK_VERSION ||
|
|
218
|
+
!ARRAY_IS_ARRAY(value.plugins) ||
|
|
219
|
+
!hostedHasOnlyKeys(value, ["version", "plugins"])
|
|
220
|
+
) {
|
|
221
|
+
return invalidHostedLock(
|
|
222
|
+
`expected { version: ${PLUGIN_LOCK_VERSION}, plugins: [] }.`,
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
const names = new SET<string>();
|
|
226
|
+
const plugins: PluginLockEntry[] = [];
|
|
227
|
+
for (let index = 0; index < value.plugins.length; index += 1) {
|
|
228
|
+
const entry = value.plugins[index];
|
|
229
|
+
if (
|
|
230
|
+
!hostedRecord(entry) ||
|
|
231
|
+
!hostedHasOnlyKeys(entry, [
|
|
232
|
+
"digest",
|
|
233
|
+
"kind",
|
|
234
|
+
"manifestSha256",
|
|
235
|
+
"name",
|
|
236
|
+
"order",
|
|
237
|
+
"resolvedAt",
|
|
238
|
+
"source",
|
|
239
|
+
"version",
|
|
240
|
+
]) ||
|
|
241
|
+
entry.kind !== "flow-extension" ||
|
|
242
|
+
typeof entry.name !== "string" ||
|
|
243
|
+
typeof entry.version !== "string" ||
|
|
244
|
+
typeof entry.digest !== "string" ||
|
|
245
|
+
!REGEXP_TEST(LOCK_HEX64, entry.digest) ||
|
|
246
|
+
typeof entry.manifestSha256 !== "string" ||
|
|
247
|
+
!REGEXP_TEST(LOCK_HEX64, entry.manifestSha256) ||
|
|
248
|
+
entry.order !== index + 1 ||
|
|
249
|
+
typeof entry.resolvedAt !== "string" ||
|
|
250
|
+
NUMBER_IS_NAN(DATE_PARSE(entry.resolvedAt)) ||
|
|
251
|
+
!hostedRecord(entry.source) ||
|
|
252
|
+
!hostedHasOnlyKeys(entry.source, [
|
|
253
|
+
"host",
|
|
254
|
+
"owner",
|
|
255
|
+
"repo",
|
|
256
|
+
"sha",
|
|
257
|
+
"path",
|
|
258
|
+
]) ||
|
|
259
|
+
entry.source.host !== "github" ||
|
|
260
|
+
typeof entry.source.owner !== "string" ||
|
|
261
|
+
!REGEXP_TEST(LOCK_OWNER, entry.source.owner) ||
|
|
262
|
+
typeof entry.source.repo !== "string" ||
|
|
263
|
+
!REGEXP_TEST(LOCK_REPO, entry.source.repo) ||
|
|
264
|
+
entry.source.repo === "." ||
|
|
265
|
+
entry.source.repo === ".." ||
|
|
266
|
+
typeof entry.source.sha !== "string" ||
|
|
267
|
+
!REGEXP_TEST(LOCK_SHA, entry.source.sha) ||
|
|
268
|
+
typeof entry.source.path !== "string" ||
|
|
269
|
+
(entry.source.path !== "" && !safePath(entry.source.path))
|
|
270
|
+
) {
|
|
271
|
+
return invalidHostedLock(`plugins[${index}] is malformed.`);
|
|
272
|
+
}
|
|
273
|
+
if (SET_HAS(names, entry.name))
|
|
274
|
+
return invalidHostedLock(`plugin ${entry.name} is listed twice.`);
|
|
275
|
+
SET_ADD(names, entry.name);
|
|
276
|
+
appendIntrinsicArray(plugins, OBJECT_FREEZE({
|
|
277
|
+
name: entry.name,
|
|
278
|
+
kind: "flow-extension",
|
|
279
|
+
version: entry.version,
|
|
280
|
+
source: OBJECT_FREEZE({
|
|
281
|
+
host: "github",
|
|
282
|
+
owner: entry.source.owner,
|
|
283
|
+
repo: entry.source.repo,
|
|
284
|
+
sha: entry.source.sha,
|
|
285
|
+
path: entry.source.path,
|
|
286
|
+
}),
|
|
287
|
+
digest: entry.digest,
|
|
288
|
+
manifestSha256: entry.manifestSha256,
|
|
289
|
+
order: entry.order,
|
|
290
|
+
resolvedAt: entry.resolvedAt,
|
|
291
|
+
}));
|
|
292
|
+
}
|
|
293
|
+
return OBJECT_FREEZE({
|
|
294
|
+
version: PLUGIN_LOCK_VERSION,
|
|
295
|
+
plugins: OBJECT_FREEZE(plugins),
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function isHostedGithubPluginRef(value: string): boolean {
|
|
300
|
+
return (
|
|
301
|
+
STRING_STARTS_WITH(value, "github:") || REGEXP_TEST(HTTPS_GITHUB, value)
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function hostedRecord(value: unknown): value is Record<string, unknown> {
|
|
306
|
+
return typeof value === "object" && value !== null && !ARRAY_IS_ARRAY(value);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function hostedHasOnlyKeys(
|
|
310
|
+
value: Record<string, unknown>,
|
|
311
|
+
allowed: readonly string[],
|
|
312
|
+
): boolean {
|
|
313
|
+
const keys = OBJECT_KEYS(value);
|
|
314
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
315
|
+
let found = false;
|
|
316
|
+
for (
|
|
317
|
+
let allowedIndex = 0;
|
|
318
|
+
allowedIndex < allowed.length;
|
|
319
|
+
allowedIndex += 1
|
|
320
|
+
) {
|
|
321
|
+
if (keys[index] === allowed[allowedIndex]) {
|
|
322
|
+
found = true;
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (!found) return false;
|
|
327
|
+
}
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function invalidHostedLock(message: string): never {
|
|
332
|
+
throw new PluginError(
|
|
333
|
+
"plugin_lock_invalid",
|
|
334
|
+
`${PLUGIN_LOCK_FILE}: ${message}`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function readBoundedDeclaration(path: string): Buffer {
|
|
339
|
+
let descriptor: number | undefined;
|
|
340
|
+
try {
|
|
341
|
+
descriptor = OPEN_SYNC(path, DECLARATION_READ_FLAGS);
|
|
342
|
+
const before = FSTAT_SYNC(descriptor, { bigint: true });
|
|
343
|
+
if (
|
|
344
|
+
!descriptorIsFile(before) ||
|
|
345
|
+
before.size < 0n ||
|
|
346
|
+
before.size > BIG_INT(MAX_DECLARATION_BYTES)
|
|
347
|
+
) {
|
|
348
|
+
throw new PluginError(
|
|
349
|
+
"plugin_source_invalid",
|
|
350
|
+
"Hosted extension declaration is not a bounded regular file.",
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
const expected = NUMBER(before.size);
|
|
354
|
+
const bytes = BUFFER_ALLOC_UNSAFE(expected);
|
|
355
|
+
let offset = 0;
|
|
356
|
+
while (offset < expected) {
|
|
357
|
+
const count = READ_SYNC(
|
|
358
|
+
descriptor,
|
|
359
|
+
bytes,
|
|
360
|
+
offset,
|
|
361
|
+
expected - offset,
|
|
362
|
+
offset,
|
|
363
|
+
);
|
|
364
|
+
if (count === 0) throw new ERROR("short read");
|
|
365
|
+
offset += count;
|
|
366
|
+
}
|
|
367
|
+
if (READ_SYNC(descriptor, BUFFER_ALLOC_UNSAFE(1), 0, 1, expected) !== 0)
|
|
368
|
+
throw new ERROR("grew");
|
|
369
|
+
const after = FSTAT_SYNC(descriptor, { bigint: true });
|
|
370
|
+
if (
|
|
371
|
+
after.size !== before.size ||
|
|
372
|
+
after.mtimeNs !== before.mtimeNs ||
|
|
373
|
+
after.ctimeNs !== before.ctimeNs
|
|
374
|
+
) {
|
|
375
|
+
throw new ERROR("changed");
|
|
376
|
+
}
|
|
377
|
+
return bytes;
|
|
378
|
+
} catch (error) {
|
|
379
|
+
if (PLUGIN_ERROR_IS_INSTANCE(error)) throw error;
|
|
380
|
+
throw new PluginError(
|
|
381
|
+
"plugin_source_invalid",
|
|
382
|
+
"Hosted extension declaration is unreadable or changed while reading.",
|
|
383
|
+
);
|
|
384
|
+
} finally {
|
|
385
|
+
if (descriptor !== undefined) CLOSE_SYNC(descriptor);
|
|
386
|
+
}
|
|
387
|
+
}
|