withruntime 0.49.0 → 1.0.0
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/generated/apps.d.ts +309 -0
- package/dist/generated/apps.js +333 -0
- package/dist/generated/audit.d.ts +47 -0
- package/dist/generated/audit.js +14 -0
- package/dist/generated/browsers.d.ts +309 -0
- package/dist/generated/browsers.js +333 -0
- package/dist/generated/builds.d.ts +309 -0
- package/dist/generated/builds.js +333 -0
- package/dist/generated/ci.d.ts +309 -0
- package/dist/generated/ci.js +333 -0
- package/dist/generated/containers.d.ts +309 -0
- package/dist/generated/containers.js +333 -0
- package/dist/generated/desktops.d.ts +309 -0
- package/dist/generated/desktops.js +333 -0
- package/dist/generated/domains.d.ts +80 -0
- package/dist/generated/domains.js +58 -0
- package/dist/generated/egressIps.d.ts +36 -0
- package/dist/generated/egressIps.js +14 -0
- package/dist/generated/events.d.ts +37 -0
- package/dist/generated/events.js +14 -0
- package/dist/generated/feedback.d.ts +44 -0
- package/dist/generated/feedback.js +13 -0
- package/dist/generated/functions.d.ts +309 -0
- package/dist/generated/functions.js +333 -0
- package/dist/generated/identities.d.ts +36 -0
- package/dist/generated/identities.js +22 -0
- package/dist/generated/images.d.ts +200 -0
- package/dist/generated/images.js +65 -0
- package/dist/generated/index.d.ts +143 -0
- package/dist/generated/index.js +184 -0
- package/dist/generated/jobRuns.d.ts +68 -0
- package/dist/generated/jobRuns.js +22 -0
- package/dist/generated/jobs.d.ts +144 -0
- package/dist/generated/jobs.js +85 -0
- package/dist/generated/keys.d.ts +105 -0
- package/dist/generated/keys.js +26 -0
- package/dist/generated/me.d.ts +33 -0
- package/dist/generated/me.js +13 -0
- package/dist/generated/networks.d.ts +32 -0
- package/dist/generated/networks.js +14 -0
- package/dist/generated/notebooks.d.ts +309 -0
- package/dist/generated/notebooks.js +333 -0
- package/dist/generated/otel.d.ts +46 -0
- package/dist/generated/otel.js +22 -0
- package/dist/generated/ports.d.ts +55 -0
- package/dist/generated/ports.js +22 -0
- package/dist/generated/previews.d.ts +86 -0
- package/dist/generated/previews.js +67 -0
- package/dist/generated/projects.d.ts +47 -0
- package/dist/generated/projects.js +26 -0
- package/dist/generated/roles.d.ts +36 -0
- package/dist/generated/roles.js +22 -0
- package/dist/generated/routes.d.ts +3 -0
- package/dist/generated/routes.js +4 -0
- package/dist/generated/runtime.d.ts +176 -0
- package/dist/generated/runtime.js +416 -0
- package/dist/generated/sandboxes.d.ts +952 -0
- package/dist/generated/sandboxes.js +342 -0
- package/dist/generated/secrets.d.ts +116 -0
- package/dist/generated/secrets.js +54 -0
- package/dist/generated/sessions.d.ts +47 -0
- package/dist/generated/sessions.js +17 -0
- package/dist/generated/signing.d.ts +68 -0
- package/dist/generated/signing.js +187 -0
- package/dist/generated/sites.d.ts +309 -0
- package/dist/generated/sites.js +333 -0
- package/dist/generated/snapshots.d.ts +27 -0
- package/dist/generated/snapshots.js +22 -0
- package/dist/generated/tunnels.d.ts +68 -0
- package/dist/generated/tunnels.js +14 -0
- package/dist/generated/usage.d.ts +155 -0
- package/dist/generated/usage.js +17 -0
- package/dist/generated/volumes.d.ts +36 -0
- package/dist/generated/volumes.js +26 -0
- package/dist/generated/webhooks.d.ts +44 -0
- package/dist/generated/webhooks.js +22 -0
- package/dist/generated/workspaces.d.ts +309 -0
- package/dist/generated/workspaces.js +333 -0
- package/dist/v2/cli.d.ts +7 -0
- package/dist/v2/cli.js +283 -0
- package/dist/v2/index.d.ts +1 -0
- package/dist/v2/index.js +4 -0
- package/dist/v2/login.d.ts +35 -0
- package/dist/v2/login.js +225 -0
- package/dist/v2/mcp.d.ts +1 -0
- package/dist/v2/mcp.js +49 -0
- package/dist/v2/openapi.json +75750 -0
- package/dist/v2/shims/base.d.ts +33 -0
- package/dist/v2/shims/base.js +54 -0
- package/dist/v2/shims/blaxel.d.ts +60 -0
- package/dist/v2/shims/blaxel.js +71 -0
- package/dist/v2/shims/cloudflare.d.ts +52 -0
- package/dist/v2/shims/cloudflare.js +55 -0
- package/dist/v2/shims/daytona.d.ts +58 -0
- package/dist/v2/shims/daytona.js +74 -0
- package/dist/v2/shims/e2b.d.ts +142 -0
- package/dist/v2/shims/e2b.js +238 -0
- package/dist/v2/shims/fly.d.ts +6 -0
- package/dist/v2/shims/fly.js +91 -0
- package/dist/v2/shims/modal.d.ts +54 -0
- package/dist/v2/shims/modal.js +79 -0
- package/dist/v2/shims/morph.d.ts +60 -0
- package/dist/v2/shims/morph.js +87 -0
- package/dist/v2/shims/vercel.d.ts +53 -0
- package/dist/v2/shims/vercel.js +90 -0
- package/dist/v2/table.d.ts +53 -0
- package/dist/v2/table.js +122 -0
- package/package.json +20 -310
- package/BLAXEL.md +0 -290
- package/COMPATIBILITY.md +0 -447
- package/DAYTONA.md +0 -237
- package/E2B.md +0 -314
- package/README.md +0 -331
- package/README.src.md +0 -333
- package/VERCEL.md +0 -230
- package/agent-platforms-inventory.json +0 -387
- package/compatibility-lock.json +0 -305
- package/dist/agents/browser.d.ts +0 -12
- package/dist/agents/browser.js +0 -12
- package/dist/agents/index.d.ts +0 -11
- package/dist/agents/index.js +0 -11
- package/dist/agents-cli.d.ts +0 -16
- package/dist/agents-cli.js +0 -1237
- package/dist/agents-deploy.d.ts +0 -196
- package/dist/agents-deploy.js +0 -872
- package/dist/agents-file.d.ts +0 -19
- package/dist/agents-file.js +0 -135
- package/dist/ai/index.d.ts +0 -49
- package/dist/ai/index.js +0 -31
- package/dist/ai-harness/index.d.ts +0 -194
- package/dist/ai-harness/index.js +0 -522
- package/dist/api-defaults.d.ts +0 -17
- package/dist/api-defaults.js +0 -22
- package/dist/apps/index.d.ts +0 -10
- package/dist/apps/index.js +0 -11
- package/dist/apps-cli.d.ts +0 -16
- package/dist/apps-cli.js +0 -1021
- package/dist/billing-cli.d.ts +0 -23
- package/dist/billing-cli.js +0 -264
- package/dist/blaxel/client.d.ts +0 -59
- package/dist/blaxel/client.js +0 -86
- package/dist/blaxel/context.d.ts +0 -59
- package/dist/blaxel/context.js +0 -162
- package/dist/blaxel/errors.d.ts +0 -130
- package/dist/blaxel/errors.js +0 -315
- package/dist/blaxel/filesystem.d.ts +0 -147
- package/dist/blaxel/filesystem.js +0 -585
- package/dist/blaxel/index.d.ts +0 -287
- package/dist/blaxel/index.js +0 -351
- package/dist/blaxel/interpreter.d.ts +0 -71
- package/dist/blaxel/interpreter.js +0 -256
- package/dist/blaxel/lookup.d.ts +0 -39
- package/dist/blaxel/lookup.js +0 -84
- package/dist/blaxel/pagination.d.ts +0 -39
- package/dist/blaxel/pagination.js +0 -88
- package/dist/blaxel/preview.d.ts +0 -136
- package/dist/blaxel/preview.js +0 -304
- package/dist/blaxel/process.d.ts +0 -126
- package/dist/blaxel/process.js +0 -581
- package/dist/blaxel/sandbox.d.ts +0 -198
- package/dist/blaxel/sandbox.js +0 -856
- package/dist/blaxel/session.d.ts +0 -31
- package/dist/blaxel/session.js +0 -136
- package/dist/blaxel/snapshot.d.ts +0 -123
- package/dist/blaxel/snapshot.js +0 -199
- package/dist/blaxel/types.d.ts +0 -145
- package/dist/blaxel/types.js +0 -60
- package/dist/blaxel/unsupported.d.ts +0 -20
- package/dist/blaxel/unsupported.js +0 -32
- package/dist/browser-stub.d.ts +0 -1
- package/dist/browser-stub.js +0 -1
- package/dist/browsers/index.d.ts +0 -9
- package/dist/browsers/index.js +0 -10
- package/dist/browsers-cli.d.ts +0 -13
- package/dist/browsers-cli.js +0 -279
- package/dist/builds/index.d.ts +0 -10
- package/dist/builds/index.js +0 -11
- package/dist/ci/index.d.ts +0 -13
- package/dist/ci/index.js +0 -14
- package/dist/ci-cli.d.ts +0 -20
- package/dist/ci-cli.js +0 -537
- package/dist/ci-import.d.ts +0 -23
- package/dist/ci-import.js +0 -565
- package/dist/claude-agent-sdk/index.d.ts +0 -7
- package/dist/claude-agent-sdk/index.js +0 -65
- package/dist/cli/logs.d.ts +0 -21
- package/dist/cli/logs.js +0 -188
- package/dist/cli-extras.d.ts +0 -39
- package/dist/cli-extras.js +0 -267
- package/dist/cli-name.d.ts +0 -6
- package/dist/cli-name.js +0 -8
- package/dist/cli-update.d.ts +0 -11
- package/dist/cli-update.js +0 -46
- package/dist/cli-words.d.ts +0 -36
- package/dist/cli-words.js +0 -167
- package/dist/cli.d.ts +0 -92
- package/dist/cli.js +0 -5463
- package/dist/client.d.ts +0 -189
- package/dist/client.js +0 -205
- package/dist/cloudflare/errors.d.ts +0 -166
- package/dist/cloudflare/errors.js +0 -183
- package/dist/cloudflare/identity.d.ts +0 -7
- package/dist/cloudflare/identity.js +0 -13
- package/dist/cloudflare/index.d.ts +0 -545
- package/dist/cloudflare/index.js +0 -1106
- package/dist/cloudflare/interpreter.d.ts +0 -119
- package/dist/cloudflare/interpreter.js +0 -232
- package/dist/cloudflare/mime.d.ts +0 -1
- package/dist/cloudflare/mime.js +0 -66
- package/dist/cloudflare/streams.d.ts +0 -46
- package/dist/cloudflare/streams.js +0 -175
- package/dist/cloudflare/types.d.ts +0 -338
- package/dist/cloudflare/types.js +0 -80
- package/dist/cloudflare/watch.d.ts +0 -9
- package/dist/cloudflare/watch.js +0 -24
- package/dist/cloudflare/worker.d.ts +0 -706
- package/dist/cloudflare/worker.js +0 -633
- package/dist/codesandbox/guest-service.d.ts +0 -31
- package/dist/codesandbox/guest-service.js +0 -490
- package/dist/codesandbox/index.d.ts +0 -574
- package/dist/codesandbox/index.js +0 -1747
- package/dist/compat/core.d.ts +0 -58
- package/dist/compat/core.js +0 -267
- package/dist/compat/files.d.ts +0 -27
- package/dist/compat/files.js +0 -157
- package/dist/compat/lease.d.ts +0 -37
- package/dist/compat/lease.js +0 -93
- package/dist/compat/shell.d.ts +0 -4
- package/dist/compat/shell.js +0 -165
- package/dist/containers/index.d.ts +0 -10
- package/dist/containers/index.js +0 -11
- package/dist/credentials.d.ts +0 -71
- package/dist/credentials.js +0 -340
- package/dist/daytona/client.d.ts +0 -48
- package/dist/daytona/client.js +0 -45
- package/dist/daytona/computer-use.d.ts +0 -171
- package/dist/daytona/computer-use.js +0 -382
- package/dist/daytona/context.d.ts +0 -41
- package/dist/daytona/context.js +0 -50
- package/dist/daytona/daytona.d.ts +0 -213
- package/dist/daytona/daytona.js +0 -578
- package/dist/daytona/errors.d.ts +0 -117
- package/dist/daytona/errors.js +0 -201
- package/dist/daytona/filesystem.d.ts +0 -99
- package/dist/daytona/filesystem.js +0 -300
- package/dist/daytona/git.d.ts +0 -33
- package/dist/daytona/git.js +0 -128
- package/dist/daytona/image.d.ts +0 -49
- package/dist/daytona/image.js +0 -146
- package/dist/daytona/index.d.ts +0 -87
- package/dist/daytona/index.js +0 -102
- package/dist/daytona/process.d.ts +0 -143
- package/dist/daytona/process.js +0 -565
- package/dist/daytona/sandbox.d.ts +0 -222
- package/dist/daytona/sandbox.js +0 -505
- package/dist/desktops/index.d.ts +0 -9
- package/dist/desktops/index.js +0 -10
- package/dist/domains/index.d.ts +0 -9
- package/dist/domains/index.js +0 -10
- package/dist/e2b/client.d.ts +0 -76
- package/dist/e2b/client.js +0 -124
- package/dist/e2b/code-interpreter.d.ts +0 -134
- package/dist/e2b/code-interpreter.js +0 -239
- package/dist/e2b/commands.d.ts +0 -135
- package/dist/e2b/commands.js +0 -452
- package/dist/e2b/errors.d.ts +0 -125
- package/dist/e2b/errors.js +0 -247
- package/dist/e2b/filesystem.d.ts +0 -111
- package/dist/e2b/filesystem.js +0 -374
- package/dist/e2b/index.d.ts +0 -35
- package/dist/e2b/index.js +0 -69
- package/dist/e2b/pty.d.ts +0 -24
- package/dist/e2b/pty.js +0 -83
- package/dist/e2b/sandbox.d.ts +0 -248
- package/dist/e2b/sandbox.js +0 -781
- package/dist/e2b/unsupported.d.ts +0 -38
- package/dist/e2b/unsupported.js +0 -48
- package/dist/e2b/users.d.ts +0 -39
- package/dist/e2b/users.js +0 -207
- package/dist/errors.d.ts +0 -100
- package/dist/errors.js +0 -198
- package/dist/file-source.d.ts +0 -16
- package/dist/file-source.js +0 -162
- package/dist/fly/index.d.ts +0 -102
- package/dist/fly/index.js +0 -930
- package/dist/freestyle/index.d.ts +0 -629
- package/dist/freestyle/index.js +0 -1187
- package/dist/functions/index.d.ts +0 -10
- package/dist/functions/index.js +0 -11
- package/dist/identity.d.ts +0 -30
- package/dist/identity.js +0 -141
- package/dist/image-context.d.ts +0 -39
- package/dist/image-context.js +0 -176
- package/dist/images/index.d.ts +0 -9
- package/dist/images/index.js +0 -10
- package/dist/index.d.ts +0 -87
- package/dist/index.js +0 -51
- package/dist/inngest/index.d.ts +0 -96
- package/dist/inngest/index.js +0 -183
- package/dist/ips/index.d.ts +0 -9
- package/dist/ips/index.js +0 -10
- package/dist/jobs/index.d.ts +0 -9
- package/dist/jobs/index.js +0 -10
- package/dist/jobs-code/cron.d.ts +0 -12
- package/dist/jobs-code/cron.js +0 -93
- package/dist/jobs-code/registry.d.ts +0 -31
- package/dist/jobs-code/registry.js +0 -30
- package/dist/jobs-code/runner.d.ts +0 -1
- package/dist/jobs-code/runner.js +0 -74
- package/dist/jobs-deploy.d.ts +0 -22
- package/dist/jobs-deploy.js +0 -247
- package/dist/jobs-import.d.ts +0 -15
- package/dist/jobs-import.js +0 -231
- package/dist/keys.d.ts +0 -55
- package/dist/keys.js +0 -211
- package/dist/login.d.ts +0 -88
- package/dist/login.js +0 -369
- package/dist/machine.d.ts +0 -222
- package/dist/machine.js +0 -578
- package/dist/mcp.d.ts +0 -16
- package/dist/mcp.js +0 -377
- package/dist/modal/index.d.ts +0 -532
- package/dist/modal/index.js +0 -1284
- package/dist/morph/index.d.ts +0 -255
- package/dist/morph/index.js +0 -641
- package/dist/network-cli.d.ts +0 -17
- package/dist/network-cli.js +0 -523
- package/dist/networks/index.d.ts +0 -11
- package/dist/networks/index.js +0 -10
- package/dist/openai-agents/index.d.ts +0 -132
- package/dist/openai-agents/index.js +0 -738
- package/dist/page.d.ts +0 -13
- package/dist/page.js +0 -39
- package/dist/ports/index.d.ts +0 -9
- package/dist/ports/index.js +0 -10
- package/dist/product-names.d.ts +0 -52
- package/dist/product-names.js +0 -174
- package/dist/product-renames.d.ts +0 -103
- package/dist/product-renames.js +0 -189
- package/dist/products/agents.d.ts +0 -935
- package/dist/products/agents.js +0 -581
- package/dist/products/api-keys.d.ts +0 -113
- package/dist/products/api-keys.js +0 -32
- package/dist/products/apps.d.ts +0 -409
- package/dist/products/apps.js +0 -231
- package/dist/products/audit.d.ts +0 -51
- package/dist/products/audit.js +0 -10
- package/dist/products/balancers.d.ts +0 -87
- package/dist/products/balancers.js +0 -8
- package/dist/products/billing.d.ts +0 -76
- package/dist/products/billing.js +0 -26
- package/dist/products/browser.d.ts +0 -73
- package/dist/products/browser.js +0 -29
- package/dist/products/browsers.d.ts +0 -184
- package/dist/products/browsers.js +0 -180
- package/dist/products/builds.d.ts +0 -175
- package/dist/products/builds.js +0 -234
- package/dist/products/ci.d.ts +0 -406
- package/dist/products/ci.js +0 -133
- package/dist/products/containers.d.ts +0 -71
- package/dist/products/containers.js +0 -6
- package/dist/products/desktop.d.ts +0 -141
- package/dist/products/desktop.js +0 -83
- package/dist/products/desktops.d.ts +0 -71
- package/dist/products/desktops.js +0 -27
- package/dist/products/functions.d.ts +0 -2
- package/dist/products/functions.js +0 -5
- package/dist/products/images.d.ts +0 -229
- package/dist/products/images.js +0 -235
- package/dist/products/index.d.ts +0 -84
- package/dist/products/index.js +0 -105
- package/dist/products/interpreter.d.ts +0 -97
- package/dist/products/interpreter.js +0 -106
- package/dist/products/jobs.d.ts +0 -408
- package/dist/products/jobs.js +0 -256
- package/dist/products/limits.d.ts +0 -61
- package/dist/products/limits.js +0 -10
- package/dist/products/logs.d.ts +0 -245
- package/dist/products/logs.js +0 -274
- package/dist/products/mcp.d.ts +0 -88
- package/dist/products/mcp.js +0 -58
- package/dist/products/mounts.d.ts +0 -49
- package/dist/products/mounts.js +0 -21
- package/dist/products/network-products.d.ts +0 -268
- package/dist/products/network-products.js +0 -127
- package/dist/products/network.d.ts +0 -62
- package/dist/products/network.js +0 -19
- package/dist/products/observability.d.ts +0 -264
- package/dist/products/observability.js +0 -123
- package/dist/products/plans.d.ts +0 -133
- package/dist/products/plans.js +0 -24
- package/dist/products/previews.d.ts +0 -70
- package/dist/products/previews.js +0 -39
- package/dist/products/private-network.d.ts +0 -22
- package/dist/products/private-network.js +0 -10
- package/dist/products/queues.d.ts +0 -149
- package/dist/products/queues.js +0 -213
- package/dist/products/referrals.d.ts +0 -50
- package/dist/products/referrals.js +0 -8
- package/dist/products/reservations.d.ts +0 -108
- package/dist/products/reservations.js +0 -41
- package/dist/products/resources.d.ts +0 -55
- package/dist/products/resources.js +0 -122
- package/dist/products/secrets.d.ts +0 -316
- package/dist/products/secrets.js +0 -333
- package/dist/products/signed-requests.d.ts +0 -21
- package/dist/products/signed-requests.js +0 -11
- package/dist/products/sso.d.ts +0 -44
- package/dist/products/sso.js +0 -8
- package/dist/products/streams.d.ts +0 -73
- package/dist/products/streams.js +0 -17
- package/dist/products/switching.d.ts +0 -123
- package/dist/products/switching.js +0 -26
- package/dist/products/tailscale.d.ts +0 -57
- package/dist/products/tailscale.js +0 -17
- package/dist/products/uptime.d.ts +0 -97
- package/dist/products/uptime.js +0 -42
- package/dist/products/volumes.d.ts +0 -190
- package/dist/products/volumes.js +0 -114
- package/dist/products/watch.d.ts +0 -112
- package/dist/products/watch.js +0 -249
- package/dist/proxy.d.ts +0 -30
- package/dist/proxy.js +0 -200
- package/dist/record-cli.d.ts +0 -23
- package/dist/record-cli.js +0 -308
- package/dist/renamed-products.d.ts +0 -38
- package/dist/renamed-products.js +0 -34
- package/dist/resumable.d.ts +0 -32
- package/dist/resumable.js +0 -201
- package/dist/runloop/index.d.ts +0 -333
- package/dist/runloop/index.js +0 -560
- package/dist/runloop/pagination.d.ts +0 -46
- package/dist/runloop/pagination.js +0 -82
- package/dist/runloop/sdk.d.ts +0 -131
- package/dist/runloop/sdk.js +0 -167
- package/dist/runloop/snapshots.d.ts +0 -52
- package/dist/runloop/snapshots.js +0 -244
- package/dist/sandbox.d.ts +0 -371
- package/dist/sandbox.js +0 -1500
- package/dist/sandboxes/index.d.ts +0 -11
- package/dist/sandboxes/index.js +0 -12
- package/dist/sealing.d.ts +0 -6
- package/dist/sealing.js +0 -14
- package/dist/snapshots/index.d.ts +0 -9
- package/dist/snapshots/index.js +0 -11
- package/dist/snapshots.d.ts +0 -82
- package/dist/snapshots.js +0 -65
- package/dist/sprites/index.d.ts +0 -563
- package/dist/sprites/index.js +0 -1370
- package/dist/ssh.d.ts +0 -56
- package/dist/ssh.js +0 -416
- package/dist/switched-off.d.ts +0 -5
- package/dist/switched-off.js +0 -8
- package/dist/tar.d.ts +0 -15
- package/dist/tar.js +0 -526
- package/dist/terminal.d.ts +0 -24
- package/dist/terminal.js +0 -32
- package/dist/tools/index.d.ts +0 -62
- package/dist/tools/index.js +0 -181
- package/dist/transport.d.ts +0 -165
- package/dist/transport.js +0 -883
- package/dist/trigger/index.d.ts +0 -202
- package/dist/trigger/index.js +0 -244
- package/dist/tunnel.d.ts +0 -70
- package/dist/tunnel.js +0 -316
- package/dist/types.d.ts +0 -574
- package/dist/types.js +0 -1
- package/dist/vercel/client.d.ts +0 -40
- package/dist/vercel/client.js +0 -39
- package/dist/vercel/command.d.ts +0 -117
- package/dist/vercel/command.js +0 -391
- package/dist/vercel/errors.d.ts +0 -53
- package/dist/vercel/errors.js +0 -131
- package/dist/vercel/filesystem.d.ts +0 -153
- package/dist/vercel/filesystem.js +0 -297
- package/dist/vercel/index.d.ts +0 -24
- package/dist/vercel/index.js +0 -36
- package/dist/vercel/sandbox-user.d.ts +0 -70
- package/dist/vercel/sandbox-user.js +0 -207
- package/dist/vercel/sandbox.d.ts +0 -372
- package/dist/vercel/sandbox.js +0 -1037
- package/dist/vercel/snapshot.d.ts +0 -94
- package/dist/vercel/snapshot.js +0 -137
- package/dist/volumes/index.d.ts +0 -9
- package/dist/volumes/index.js +0 -10
- package/dist/wait.d.ts +0 -12
- package/dist/wait.js +0 -47
- package/dist/wallet.d.ts +0 -45
- package/dist/wallet.js +0 -56
- package/dist/wireguard.d.ts +0 -7
- package/dist/wireguard.js +0 -13
package/dist/sprites/index.js
DELETED
|
@@ -1,1370 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "node:events";
|
|
2
|
-
import { PassThrough, Writable } from "node:stream";
|
|
3
|
-
import { NotFoundError, RuntimeError } from "../errors.js";
|
|
4
|
-
import { timeoutSignal } from "../transport.js";
|
|
5
|
-
import { all, client, CompatibilityError, create, destroy, execOptions, lookup, only, ready, refuse, region, } from "../compat/core.js";
|
|
6
|
-
import { GuestFiles } from "../compat/files.js";
|
|
7
|
-
export { CompatibilityError };
|
|
8
|
-
export const ERR_CODE_CREATION_RATE_LIMITED = "sprite_creation_rate_limited";
|
|
9
|
-
export const ERR_CODE_CONCURRENT_LIMIT_EXCEEDED = "concurrent_sprite_limit_exceeded";
|
|
10
|
-
/** A Sprites progress or event stream: the work behind it runs whether or
|
|
11
|
-
* not anyone reads, as the vendor's server-side operation does; `next()`
|
|
12
|
-
* answers null at the end, `close()` stops reading (and stops a watch). */
|
|
13
|
-
class Feed {
|
|
14
|
-
#items = [];
|
|
15
|
-
#waiters = [];
|
|
16
|
-
#ended = false;
|
|
17
|
-
#closed = false;
|
|
18
|
-
#error;
|
|
19
|
-
constructor(source) {
|
|
20
|
-
if (source)
|
|
21
|
-
void (async () => {
|
|
22
|
-
try {
|
|
23
|
-
for await (const item of source)
|
|
24
|
-
this.push(item);
|
|
25
|
-
this.end();
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
this.end(error);
|
|
29
|
-
}
|
|
30
|
-
})();
|
|
31
|
-
}
|
|
32
|
-
push(item) {
|
|
33
|
-
if (this.#ended || this.#closed)
|
|
34
|
-
return;
|
|
35
|
-
this.#items.push(item);
|
|
36
|
-
this.#wake();
|
|
37
|
-
}
|
|
38
|
-
end(error) {
|
|
39
|
-
if (this.#ended)
|
|
40
|
-
return;
|
|
41
|
-
this.#ended = true;
|
|
42
|
-
this.#error = error;
|
|
43
|
-
this.#wake();
|
|
44
|
-
}
|
|
45
|
-
/** Called once by close(); a watch stops its native watch here. */
|
|
46
|
-
stop() { }
|
|
47
|
-
#wake() {
|
|
48
|
-
for (const waiter of this.#waiters.splice(0))
|
|
49
|
-
waiter();
|
|
50
|
-
}
|
|
51
|
-
async next() {
|
|
52
|
-
while (!this.#items.length && !this.#ended && !this.#closed)
|
|
53
|
-
await new Promise((resolve) => this.#waiters.push(resolve));
|
|
54
|
-
if (this.#closed)
|
|
55
|
-
return null;
|
|
56
|
-
if (this.#items.length)
|
|
57
|
-
return this.#items.shift();
|
|
58
|
-
if (this.#error !== undefined) {
|
|
59
|
-
const error = this.#error;
|
|
60
|
-
this.#error = undefined;
|
|
61
|
-
throw error instanceof Error ? error : new Error("The stream failed", { cause: error });
|
|
62
|
-
}
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
async processAll(handler) {
|
|
66
|
-
for await (const item of this)
|
|
67
|
-
await handler(item);
|
|
68
|
-
}
|
|
69
|
-
close() {
|
|
70
|
-
if (this.#closed)
|
|
71
|
-
return;
|
|
72
|
-
this.#closed = true;
|
|
73
|
-
this.stop();
|
|
74
|
-
this.#wake();
|
|
75
|
-
}
|
|
76
|
-
isClosed() {
|
|
77
|
-
return this.#closed || (this.#ended && !this.#items.length);
|
|
78
|
-
}
|
|
79
|
-
async *[Symbol.asyncIterator]() {
|
|
80
|
-
let item;
|
|
81
|
-
while ((item = await this.next()) !== null)
|
|
82
|
-
yield item;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
export class CheckpointStream extends Feed {
|
|
86
|
-
}
|
|
87
|
-
export class RestoreStream extends Feed {
|
|
88
|
-
}
|
|
89
|
-
export class ServiceLogStream extends Feed {
|
|
90
|
-
}
|
|
91
|
-
export class SessionKillStream extends Feed {
|
|
92
|
-
}
|
|
93
|
-
export class SpriteListStream extends Feed {
|
|
94
|
-
}
|
|
95
|
-
export class APIError extends Error {
|
|
96
|
-
errorCode;
|
|
97
|
-
statusCode;
|
|
98
|
-
limit;
|
|
99
|
-
windowSeconds;
|
|
100
|
-
retryAfterSeconds;
|
|
101
|
-
currentCount;
|
|
102
|
-
upgradeAvailable;
|
|
103
|
-
upgradeUrl;
|
|
104
|
-
retryAfterHeader;
|
|
105
|
-
rateLimitLimit;
|
|
106
|
-
rateLimitRemaining;
|
|
107
|
-
rateLimitReset;
|
|
108
|
-
constructor(message, options = {}) {
|
|
109
|
-
super(message);
|
|
110
|
-
this.name = "APIError";
|
|
111
|
-
Object.assign(this, options);
|
|
112
|
-
}
|
|
113
|
-
isRateLimitError() {
|
|
114
|
-
return this.statusCode === 429;
|
|
115
|
-
}
|
|
116
|
-
isCreationRateLimited() {
|
|
117
|
-
return this.errorCode === ERR_CODE_CREATION_RATE_LIMITED;
|
|
118
|
-
}
|
|
119
|
-
isConcurrentLimitExceeded() {
|
|
120
|
-
return this.errorCode === ERR_CODE_CONCURRENT_LIMIT_EXCEEDED;
|
|
121
|
-
}
|
|
122
|
-
getRetryAfterSeconds() {
|
|
123
|
-
if (this.retryAfterSeconds !== undefined && this.retryAfterSeconds > 0)
|
|
124
|
-
return this.retryAfterSeconds;
|
|
125
|
-
return this.retryAfterHeader;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/** The vendor's parser, for callers that read Sprites-shaped answers themselves. */
|
|
129
|
-
export function parseAPIError(statusCode, body, headers = {}) {
|
|
130
|
-
if (statusCode < 400)
|
|
131
|
-
return undefined;
|
|
132
|
-
const header = (name) => {
|
|
133
|
-
const value = headers[name.toLowerCase()] ?? headers[name];
|
|
134
|
-
const number = value ? parseInt(value, 10) : NaN;
|
|
135
|
-
return Number.isNaN(number) ? undefined : number;
|
|
136
|
-
};
|
|
137
|
-
const retryAfterHeader = header("Retry-After");
|
|
138
|
-
let message = "";
|
|
139
|
-
let data = {};
|
|
140
|
-
if (body)
|
|
141
|
-
try {
|
|
142
|
-
data = JSON.parse(body);
|
|
143
|
-
message = data.message || "";
|
|
144
|
-
}
|
|
145
|
-
catch {
|
|
146
|
-
message = body;
|
|
147
|
-
}
|
|
148
|
-
const errorCode = data.error;
|
|
149
|
-
const limit = data.limit;
|
|
150
|
-
const windowSeconds = data.window_seconds;
|
|
151
|
-
const retryAfterSeconds = data.retry_after_seconds;
|
|
152
|
-
const currentCount = data.current_count;
|
|
153
|
-
const upgradeUrl = data.upgrade_url;
|
|
154
|
-
if (statusCode === 429 && message) {
|
|
155
|
-
const details = [];
|
|
156
|
-
if (limit !== undefined && windowSeconds !== undefined)
|
|
157
|
-
details.push(`limit: ${limit} per ${windowSeconds}s`);
|
|
158
|
-
if (currentCount !== undefined)
|
|
159
|
-
details.push(`current: ${currentCount}`);
|
|
160
|
-
const retry = retryAfterSeconds ?? retryAfterHeader;
|
|
161
|
-
if (retry !== undefined)
|
|
162
|
-
details.push(`retry after: ${retry}s`);
|
|
163
|
-
if (upgradeUrl)
|
|
164
|
-
details.push(`upgrade: ${upgradeUrl}`);
|
|
165
|
-
if (details.length)
|
|
166
|
-
message = `${message} (${details.join(", ")})`;
|
|
167
|
-
}
|
|
168
|
-
return new APIError(message || errorCode || `API error (status ${statusCode})`, {
|
|
169
|
-
errorCode,
|
|
170
|
-
statusCode,
|
|
171
|
-
limit,
|
|
172
|
-
windowSeconds,
|
|
173
|
-
retryAfterSeconds,
|
|
174
|
-
currentCount,
|
|
175
|
-
upgradeAvailable: data.upgrade_available,
|
|
176
|
-
upgradeUrl,
|
|
177
|
-
retryAfterHeader,
|
|
178
|
-
rateLimitLimit: header("X-RateLimit-Limit"),
|
|
179
|
-
rateLimitRemaining: header("X-RateLimit-Remaining"),
|
|
180
|
-
rateLimitReset: header("X-RateLimit-Reset"),
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
/** Runtime's refusal as the APIError the vendor's client throws; limits on
|
|
184
|
-
* running sandboxes are its concurrent limit, the API's rate limit on a
|
|
185
|
-
* create its creation limit. */
|
|
186
|
-
async function api(run, creating = false) {
|
|
187
|
-
try {
|
|
188
|
-
return await run();
|
|
189
|
-
}
|
|
190
|
-
catch (error) {
|
|
191
|
-
if (!(error instanceof RuntimeError) || error.status < 400)
|
|
192
|
-
throw error;
|
|
193
|
-
const errorCode = ["no_credit_running_limit", "quota_exceeded"].includes(error.code)
|
|
194
|
-
? ERR_CODE_CONCURRENT_LIMIT_EXCEEDED
|
|
195
|
-
: creating && error.code === "rate_limited"
|
|
196
|
-
? ERR_CODE_CREATION_RATE_LIMITED
|
|
197
|
-
: error.code;
|
|
198
|
-
const retry = error.retryAfterMs === undefined ? undefined : Math.ceil(error.retryAfterMs / 1000);
|
|
199
|
-
throw Object.assign(new APIError(error.message, {
|
|
200
|
-
errorCode,
|
|
201
|
-
statusCode: error.status,
|
|
202
|
-
retryAfterSeconds: retry,
|
|
203
|
-
retryAfterHeader: retry,
|
|
204
|
-
}), { cause: error });
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
/** "30s", "500ms", "2m" or "1h", as Sprites' durations are written. */
|
|
208
|
-
function duration(value, name) {
|
|
209
|
-
const match = /^(\d+(?:\.\d+)?)(ms|s|m|h)$/.exec(value);
|
|
210
|
-
if (!match)
|
|
211
|
-
throw new TypeError(`${name} must be a duration such as "10s"`);
|
|
212
|
-
return Number(match[1]) * { ms: 1, s: 1000, m: 60_000, h: 3_600_000 }[match[2]];
|
|
213
|
-
}
|
|
214
|
-
const SIGNALS = [
|
|
215
|
-
"SIGTERM",
|
|
216
|
-
"SIGKILL",
|
|
217
|
-
"SIGINT",
|
|
218
|
-
"SIGHUP",
|
|
219
|
-
"SIGQUIT",
|
|
220
|
-
"SIGUSR1",
|
|
221
|
-
"SIGUSR2",
|
|
222
|
-
];
|
|
223
|
-
function signalName(signal) {
|
|
224
|
-
const name = (signal.startsWith("SIG") ? signal : `SIG${signal}`);
|
|
225
|
-
if (!SIGNALS.includes(name))
|
|
226
|
-
throw new TypeError(`Unsupported signal ${signal}`);
|
|
227
|
-
return name;
|
|
228
|
-
}
|
|
229
|
-
/** maxRunAfterDisconnect is left out: a Runtime process runs until it ends
|
|
230
|
-
* or is killed, whoever is connected. */
|
|
231
|
-
const SPAWN_KEYS = [
|
|
232
|
-
"cwd",
|
|
233
|
-
"env",
|
|
234
|
-
"tty",
|
|
235
|
-
"rows",
|
|
236
|
-
"cols",
|
|
237
|
-
"detachable",
|
|
238
|
-
"sessionId",
|
|
239
|
-
"controlMode",
|
|
240
|
-
];
|
|
241
|
-
const EXEC_KEYS = [...SPAWN_KEYS, "encoding", "maxBuffer", "signal", "timeout"];
|
|
242
|
-
function validateURLSettings(settings) {
|
|
243
|
-
only("Sprites URL settings", settings, ["auth"]);
|
|
244
|
-
if (settings.auth !== "public" && settings.auth !== "sprite")
|
|
245
|
-
throw new TypeError("auth must be public or sprite");
|
|
246
|
-
}
|
|
247
|
-
function validateLabels(labels) {
|
|
248
|
-
if (labels !== undefined &&
|
|
249
|
-
(!Array.isArray(labels) || Array.from(labels).some((label) => typeof label !== "string")))
|
|
250
|
-
throw new TypeError("labels must be an array of strings");
|
|
251
|
-
}
|
|
252
|
-
export class FilesystemError extends Error {
|
|
253
|
-
code;
|
|
254
|
-
path;
|
|
255
|
-
syscall;
|
|
256
|
-
constructor(message, code, path, syscall) {
|
|
257
|
-
super(message);
|
|
258
|
-
this.code = code;
|
|
259
|
-
this.path = path;
|
|
260
|
-
this.syscall = syscall;
|
|
261
|
-
this.name = "FilesystemError";
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
async function fileOperation(path, syscall, run) {
|
|
265
|
-
try {
|
|
266
|
-
return await run();
|
|
267
|
-
}
|
|
268
|
-
catch (error) {
|
|
269
|
-
if (!(error instanceof RuntimeError))
|
|
270
|
-
throw error;
|
|
271
|
-
const codes = {
|
|
272
|
-
file_not_found: "ENOENT",
|
|
273
|
-
not_found: "ENOENT",
|
|
274
|
-
already_exists: "EEXIST",
|
|
275
|
-
file_exists: "EEXIST",
|
|
276
|
-
not_a_directory: "ENOTDIR",
|
|
277
|
-
is_a_directory: "EISDIR",
|
|
278
|
-
permission_denied: "EACCES",
|
|
279
|
-
directory_not_empty: "ENOTEMPTY",
|
|
280
|
-
invalid_request: "EINVAL",
|
|
281
|
-
};
|
|
282
|
-
throw new FilesystemError(error.message, codes[error.code] ?? (error.status === 404 ? "ENOENT" : "UNKNOWN"), path, syscall);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
export class ExecError extends Error {
|
|
286
|
-
result;
|
|
287
|
-
constructor(message, result) {
|
|
288
|
-
super(message);
|
|
289
|
-
this.result = result;
|
|
290
|
-
this.name = "ExecError";
|
|
291
|
-
}
|
|
292
|
-
get exitCode() {
|
|
293
|
-
return this.result.exitCode;
|
|
294
|
-
}
|
|
295
|
-
get stdout() {
|
|
296
|
-
return this.result.stdout;
|
|
297
|
-
}
|
|
298
|
-
get stderr() {
|
|
299
|
-
return this.result.stderr;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
/** The vendor's control-mode wire protocol: multiplexed operations over one
|
|
303
|
-
* WebSocket. Runtime's own API multiplexes commands without it. */
|
|
304
|
-
const CONTROL = "Runtime runs each command over its own API; use spawn, exec or execFile";
|
|
305
|
-
export class OpConn extends EventEmitter {
|
|
306
|
-
}
|
|
307
|
-
refuse("Sprites", "OpConn", OpConn, Object.fromEntries([
|
|
308
|
-
"write",
|
|
309
|
-
"sendEOF",
|
|
310
|
-
"resize",
|
|
311
|
-
"signal",
|
|
312
|
-
"handleData",
|
|
313
|
-
"handleText",
|
|
314
|
-
"complete",
|
|
315
|
-
"close",
|
|
316
|
-
"isClosed",
|
|
317
|
-
"getExitCode",
|
|
318
|
-
].map((name) => [name, CONTROL])), { sync: true });
|
|
319
|
-
refuse("Sprites", "OpConn", OpConn, { wait: CONTROL });
|
|
320
|
-
export class ControlConnection extends EventEmitter {
|
|
321
|
-
}
|
|
322
|
-
refuse("Sprites", "ControlConnection", ControlConnection, Object.fromEntries(["isActive", "setActive", "clearOpConn", "sendData", "close", "isClosed"].map((name) => [
|
|
323
|
-
name,
|
|
324
|
-
CONTROL,
|
|
325
|
-
])), { sync: true });
|
|
326
|
-
refuse("Sprites", "ControlConnection", ControlConnection, {
|
|
327
|
-
connect: CONTROL,
|
|
328
|
-
startOp: CONTROL,
|
|
329
|
-
});
|
|
330
|
-
export class SpritesClient {
|
|
331
|
-
runtime;
|
|
332
|
-
/** The Runtime API the calls go to. */
|
|
333
|
-
baseURL;
|
|
334
|
-
/** The Runtime key given, if any; otherwise RUNTIME_API_KEY or the saved login is used. */
|
|
335
|
-
token;
|
|
336
|
-
/** Always false: true is refused (control mode). */
|
|
337
|
-
controlMode = false;
|
|
338
|
-
constructor(token, options = {}) {
|
|
339
|
-
only("Sprites client", options, [
|
|
340
|
-
"apiKey",
|
|
341
|
-
"baseUrl",
|
|
342
|
-
"baseURL",
|
|
343
|
-
"timeout",
|
|
344
|
-
"timeoutMs",
|
|
345
|
-
"maxRetries",
|
|
346
|
-
"fetch",
|
|
347
|
-
"client",
|
|
348
|
-
"controlMode",
|
|
349
|
-
"waitForCapacityMs",
|
|
350
|
-
]);
|
|
351
|
-
if (options.controlMode)
|
|
352
|
-
throw new CompatibilityError("Sprites", "control-mode wire protocol");
|
|
353
|
-
this.runtime = client({
|
|
354
|
-
...options,
|
|
355
|
-
apiKey: options.apiKey ?? token,
|
|
356
|
-
baseUrl: options.baseUrl ?? options.baseURL,
|
|
357
|
-
timeoutMs: options.timeoutMs ?? options.timeout,
|
|
358
|
-
});
|
|
359
|
-
this.baseURL = this.runtime.transport?.baseUrl ?? options.baseUrl ?? options.baseURL ?? "";
|
|
360
|
-
this.token = options.apiKey ?? token ?? "";
|
|
361
|
-
}
|
|
362
|
-
sprite(name) {
|
|
363
|
-
return new Sprite(name, this);
|
|
364
|
-
}
|
|
365
|
-
async createSprite(name, input = {}, extra = {}) {
|
|
366
|
-
const o = ["ramMB", "cpus", "region", "storageGB"].some((k) => k in input)
|
|
367
|
-
? { ...extra, config: input }
|
|
368
|
-
: { ...input, ...extra };
|
|
369
|
-
only("Sprites create", o, [
|
|
370
|
-
"config",
|
|
371
|
-
"environment",
|
|
372
|
-
"labels",
|
|
373
|
-
"urlSettings",
|
|
374
|
-
"runtime",
|
|
375
|
-
"waitForCapacity",
|
|
376
|
-
]);
|
|
377
|
-
if (o.runtime !== undefined)
|
|
378
|
-
throw new CompatibilityError("Sprites", `vendor runtime image ${o.runtime}; import it into Runtime first`);
|
|
379
|
-
if (o.urlSettings !== undefined)
|
|
380
|
-
validateURLSettings(o.urlSettings);
|
|
381
|
-
validateLabels(o.labels);
|
|
382
|
-
const c = o.config ?? {};
|
|
383
|
-
only("Sprites config", c, ["ramMB", "cpus", "region", "storageGB"]);
|
|
384
|
-
const s = await api(() => create(this.runtime, "sprites", {
|
|
385
|
-
name,
|
|
386
|
-
persistent: true,
|
|
387
|
-
vcpu: c.cpus,
|
|
388
|
-
memoryMiB: c.ramMB,
|
|
389
|
-
diskMiB: c.storageGB === undefined ? undefined : Math.ceil((c.storageGB * 1e9) / 1048576),
|
|
390
|
-
region: region("Sprites", c.region),
|
|
391
|
-
labels: { "compat.labels": JSON.stringify(o.labels ?? []) },
|
|
392
|
-
}, o.environment, undefined, o.waitForCapacity === false ? { waitForCapacityMs: 0 } : {}), true);
|
|
393
|
-
const sprite = new Sprite(name, this);
|
|
394
|
-
sprite.hydrate(s);
|
|
395
|
-
sprite.environment = { ...o.environment };
|
|
396
|
-
if (o.urlSettings) {
|
|
397
|
-
try {
|
|
398
|
-
await sprite.updateURLSettings(o.urlSettings);
|
|
399
|
-
}
|
|
400
|
-
catch (e) {
|
|
401
|
-
await destroy(s);
|
|
402
|
-
throw e;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
return sprite;
|
|
406
|
-
}
|
|
407
|
-
async getSprite(name) {
|
|
408
|
-
const sprite = this.sprite(name);
|
|
409
|
-
sprite.hydrate(await api(() => lookup(this.runtime, name)));
|
|
410
|
-
return sprite;
|
|
411
|
-
}
|
|
412
|
-
async deleteSprite(name) {
|
|
413
|
-
await api(async () => destroy(await lookup(this.runtime, name)));
|
|
414
|
-
}
|
|
415
|
-
async listSprites(options = {}) {
|
|
416
|
-
only("Sprites list", options, ["prefix", "maxResults", "continuationToken", "bulkLoad"]);
|
|
417
|
-
const values = (await api(() => all(this.runtime, "sprites"))).filter((s) => (s.info.name ?? s.id).startsWith(options.prefix ?? ""));
|
|
418
|
-
const offset = Number(options.continuationToken ?? 0), limit = options.maxResults ?? 100;
|
|
419
|
-
return {
|
|
420
|
-
sprites: values.slice(offset, offset + limit).map((s) => ({
|
|
421
|
-
id: s.id,
|
|
422
|
-
name: s.info.name ?? s.id,
|
|
423
|
-
status: s.state,
|
|
424
|
-
createdAt: new Date(s.info.createdAt),
|
|
425
|
-
updatedAt: new Date(s.info.createdAt),
|
|
426
|
-
config: {
|
|
427
|
-
cpus: s.info.vcpu,
|
|
428
|
-
ramMB: s.info.memoryMiB,
|
|
429
|
-
storageGB: (s.info.diskMiB * 1048576) / 1e9,
|
|
430
|
-
region: s.info.region,
|
|
431
|
-
},
|
|
432
|
-
})),
|
|
433
|
-
hasMore: offset + limit < values.length,
|
|
434
|
-
nextContinuationToken: offset + limit < values.length ? String(offset + limit) : undefined,
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
async listAllSprites(prefix) {
|
|
438
|
-
return (await api(() => all(this.runtime, "sprites")))
|
|
439
|
-
.filter((s) => (s.info.name ?? s.id).startsWith(prefix ?? ""))
|
|
440
|
-
.map((s) => {
|
|
441
|
-
const sprite = this.sprite(s.info.name ?? s.id);
|
|
442
|
-
sprite.hydrate(s);
|
|
443
|
-
return sprite;
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
async restartSprite(name) {
|
|
447
|
-
return api(async () => {
|
|
448
|
-
const s = await lookup(this.runtime, name);
|
|
449
|
-
await s.stop();
|
|
450
|
-
await s.restart();
|
|
451
|
-
return { spriteName: name, machineId: s.id, message: "Restarted" };
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
/** Its state as Runtime reports it now; `elapsed` is the lookup's milliseconds. */
|
|
455
|
-
async checkSprite(name) {
|
|
456
|
-
const started = performance.now();
|
|
457
|
-
const s = await api(() => lookup(this.runtime, name));
|
|
458
|
-
return {
|
|
459
|
-
spriteName: name,
|
|
460
|
-
spriteId: s.id,
|
|
461
|
-
status: s.state,
|
|
462
|
-
checkedAt: new Date(),
|
|
463
|
-
elapsed: Math.round(performance.now() - started),
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
/** Runtime keeps each sandbox's system current itself, so there is nothing
|
|
467
|
-
* to move to: this checks that the Sprite exists, as the vendor's call does. */
|
|
468
|
-
async upgradeSprite(name) {
|
|
469
|
-
await api(() => lookup(this.runtime, name));
|
|
470
|
-
}
|
|
471
|
-
async updateSprite(name, options) {
|
|
472
|
-
return (await this.getSprite(name)).update(options);
|
|
473
|
-
}
|
|
474
|
-
updateURLSettings(name, settings) {
|
|
475
|
-
return this.sprite(name).updateURLSettings(settings);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
refuse("Sprites", "SpritesClient", SpritesClient, {
|
|
479
|
-
watchSprites: "watch sandbox state with runtime.events or signed webhooks",
|
|
480
|
-
});
|
|
481
|
-
refuse("Sprites", "SpritesClient", { prototype: SpritesClient }, {
|
|
482
|
-
createToken: "Fly macaroons are not Runtime credentials; create a Runtime API key in the console",
|
|
483
|
-
});
|
|
484
|
-
export class Sprite {
|
|
485
|
-
name;
|
|
486
|
-
client;
|
|
487
|
-
id;
|
|
488
|
-
/** Runtime does not send the organization's name with a sandbox. */
|
|
489
|
-
organizationName;
|
|
490
|
-
status;
|
|
491
|
-
config;
|
|
492
|
-
/** Set by createSprite; Runtime keeps it in the sandbox, not in its listing. */
|
|
493
|
-
environment;
|
|
494
|
-
createdAt;
|
|
495
|
-
updatedAt;
|
|
496
|
-
url;
|
|
497
|
-
urlSettings;
|
|
498
|
-
/** Vendor storage and version fields; Runtime has no equivalent to report. */
|
|
499
|
-
bucketName;
|
|
500
|
-
primaryRegion;
|
|
501
|
-
version;
|
|
502
|
-
environmentVersion;
|
|
503
|
-
labels = [];
|
|
504
|
-
lastRunningAt;
|
|
505
|
-
lastWarmingAt;
|
|
506
|
-
constructor(name, client) {
|
|
507
|
-
this.name = name;
|
|
508
|
-
this.client = client;
|
|
509
|
-
}
|
|
510
|
-
hydrate(s) {
|
|
511
|
-
this.id = s.id;
|
|
512
|
-
this.status = s.state;
|
|
513
|
-
this.config = {
|
|
514
|
-
cpus: s.info.vcpu,
|
|
515
|
-
ramMB: s.info.memoryMiB,
|
|
516
|
-
region: s.info.region,
|
|
517
|
-
storageGB: (s.info.diskMiB * 1048576) / 1e9,
|
|
518
|
-
};
|
|
519
|
-
this.primaryRegion = s.info.region;
|
|
520
|
-
this.createdAt = new Date(s.info.createdAt);
|
|
521
|
-
this.updatedAt = this.createdAt;
|
|
522
|
-
this.labels = JSON.parse(s.info.labels["compat.labels"] ?? "[]");
|
|
523
|
-
}
|
|
524
|
-
async native() {
|
|
525
|
-
const s = await lookup(this.client.runtime, this.id ?? this.name);
|
|
526
|
-
this.hydrate(s);
|
|
527
|
-
return s;
|
|
528
|
-
}
|
|
529
|
-
spawn(command, args = [], options = {}) {
|
|
530
|
-
only("Sprites spawn", options, EXEC_KEYS);
|
|
531
|
-
return new SpriteCommand(this, command, args, options);
|
|
532
|
-
}
|
|
533
|
-
exec(command, options = {}) {
|
|
534
|
-
only("Sprites exec", options, EXEC_KEYS);
|
|
535
|
-
return this.execFile("bash", ["-c", command], options);
|
|
536
|
-
}
|
|
537
|
-
execFile(file, args = [], options = {}) {
|
|
538
|
-
only("Sprites exec", options, EXEC_KEYS);
|
|
539
|
-
return this.#execute(file, args, options);
|
|
540
|
-
}
|
|
541
|
-
/** Runtime's commands are HTTP calls already; `input` is written to stdin
|
|
542
|
-
* and stdin closed, and without it stdin is closed at once. */
|
|
543
|
-
execFileHTTP(file, args = [], options = {}) {
|
|
544
|
-
only("Sprites HTTP exec", options, [
|
|
545
|
-
"cwd",
|
|
546
|
-
"env",
|
|
547
|
-
"encoding",
|
|
548
|
-
"maxBuffer",
|
|
549
|
-
"signal",
|
|
550
|
-
"timeout",
|
|
551
|
-
"input",
|
|
552
|
-
]);
|
|
553
|
-
const { input, ...rest } = options;
|
|
554
|
-
return this.#execute(file, args, rest, input ?? "");
|
|
555
|
-
}
|
|
556
|
-
async #execute(file, args, options, input) {
|
|
557
|
-
options.signal?.throwIfAborted();
|
|
558
|
-
if (options.timeout !== undefined && (!Number.isFinite(options.timeout) || options.timeout < 0))
|
|
559
|
-
throw new TypeError("timeout must be a non-negative finite number");
|
|
560
|
-
if (options.encoding &&
|
|
561
|
-
options.encoding !== "buffer" &&
|
|
562
|
-
!Buffer.isEncoding(options.encoding))
|
|
563
|
-
throw new TypeError(`Unknown encoding: ${String(options.encoding)}`);
|
|
564
|
-
if (options.controlMode)
|
|
565
|
-
throw new CompatibilityError("Sprites", "control-mode wire protocol");
|
|
566
|
-
const cmd = this.spawn(file, args, options);
|
|
567
|
-
if (input !== undefined) {
|
|
568
|
-
if (input.length)
|
|
569
|
-
cmd.stdin.end(input);
|
|
570
|
-
else
|
|
571
|
-
cmd.stdin.end();
|
|
572
|
-
}
|
|
573
|
-
const out = [], err = [];
|
|
574
|
-
const maxBuffer = options.maxBuffer || 10 * 1024 * 1024;
|
|
575
|
-
let stdoutBytes = 0;
|
|
576
|
-
let stderrBytes = 0;
|
|
577
|
-
let failure;
|
|
578
|
-
let rejectFailure = () => undefined;
|
|
579
|
-
const failed = new Promise((_resolve, reject) => {
|
|
580
|
-
rejectFailure = reject;
|
|
581
|
-
});
|
|
582
|
-
const cancel = (error) => {
|
|
583
|
-
if (failure)
|
|
584
|
-
return;
|
|
585
|
-
failure = error;
|
|
586
|
-
cmd.kill("SIGTERM");
|
|
587
|
-
cmd.close();
|
|
588
|
-
rejectFailure(error);
|
|
589
|
-
};
|
|
590
|
-
const capture = (channel, target) => (chunk) => {
|
|
591
|
-
if (failure)
|
|
592
|
-
return;
|
|
593
|
-
if (channel === "stdout")
|
|
594
|
-
stdoutBytes += chunk.length;
|
|
595
|
-
else
|
|
596
|
-
stderrBytes += chunk.length;
|
|
597
|
-
if ((channel === "stdout" ? stdoutBytes : stderrBytes) > maxBuffer)
|
|
598
|
-
cancel(new Error(`${channel} maxBuffer exceeded`));
|
|
599
|
-
else
|
|
600
|
-
target.push(chunk);
|
|
601
|
-
};
|
|
602
|
-
cmd.stdout.on("data", capture("stdout", out));
|
|
603
|
-
cmd.stderr.on("data", capture("stderr", err));
|
|
604
|
-
const abort = () => cancel(new Error("Command aborted"));
|
|
605
|
-
options.signal?.addEventListener("abort", abort, { once: true });
|
|
606
|
-
if (options.signal?.aborted)
|
|
607
|
-
abort();
|
|
608
|
-
const timer = options.timeout
|
|
609
|
-
? setTimeout(() => cancel(new Error(`Command timed out after ${options.timeout} ms`)), options.timeout)
|
|
610
|
-
: undefined;
|
|
611
|
-
try {
|
|
612
|
-
const exitCode = await Promise.race([cmd.wait(), failed]);
|
|
613
|
-
if (failure)
|
|
614
|
-
throw failure;
|
|
615
|
-
const stdout = Buffer.concat(out), stderr = Buffer.concat(err);
|
|
616
|
-
const r = {
|
|
617
|
-
stdout: options.encoding === "buffer"
|
|
618
|
-
? stdout
|
|
619
|
-
: stdout.toString(options.encoding ?? "utf8"),
|
|
620
|
-
stderr: options.encoding === "buffer"
|
|
621
|
-
? stderr
|
|
622
|
-
: stderr.toString(options.encoding ?? "utf8"),
|
|
623
|
-
exitCode,
|
|
624
|
-
};
|
|
625
|
-
if (exitCode !== 0)
|
|
626
|
-
throw new ExecError(`Command exited with code ${exitCode}`, r);
|
|
627
|
-
return r;
|
|
628
|
-
}
|
|
629
|
-
finally {
|
|
630
|
-
if (timer)
|
|
631
|
-
clearTimeout(timer);
|
|
632
|
-
options.signal?.removeEventListener("abort", abort);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
createSession(command, args = [], options = {}) {
|
|
636
|
-
only("Sprites session", options, SPAWN_KEYS);
|
|
637
|
-
// The pinned SDK's session wrapper forces a terminal, even when a caller
|
|
638
|
-
// supplies tty:false. Attaching an existing session detects its own PTY.
|
|
639
|
-
return this.spawn(command, args, { ...options, detachable: true, tty: true });
|
|
640
|
-
}
|
|
641
|
-
attachSession(sessionId, options = {}) {
|
|
642
|
-
only("Sprites session", options, SPAWN_KEYS);
|
|
643
|
-
return this.spawn("", [], { ...options, sessionId });
|
|
644
|
-
}
|
|
645
|
-
async listSessions() {
|
|
646
|
-
return (await (await this.native()).processes.list())
|
|
647
|
-
.filter((p) => p.state === "running")
|
|
648
|
-
.map((p) => ({
|
|
649
|
-
id: p.id,
|
|
650
|
-
command: p.command,
|
|
651
|
-
created: new Date(p.startedAt),
|
|
652
|
-
workdir: p.cwd,
|
|
653
|
-
isActive: p.state === "running",
|
|
654
|
-
tty: p.pty,
|
|
655
|
-
}));
|
|
656
|
-
}
|
|
657
|
-
delete() {
|
|
658
|
-
return this.client.deleteSprite(this.id ?? this.name);
|
|
659
|
-
}
|
|
660
|
-
destroy() {
|
|
661
|
-
return this.delete();
|
|
662
|
-
}
|
|
663
|
-
restart() {
|
|
664
|
-
return this.client.restartSprite(this.id ?? this.name);
|
|
665
|
-
}
|
|
666
|
-
filesystem(workingDir = "/") {
|
|
667
|
-
return new SpriteFilesystem(() => this.native(), workingDir);
|
|
668
|
-
}
|
|
669
|
-
/** Ends a session: `signal` (SIGTERM by default; "TERM" works too), then
|
|
670
|
-
* SIGKILL if it has not exited within `timeout` ("10s" by default). */
|
|
671
|
-
async killSession(sessionId, signal = "SIGTERM", timeout = "10s") {
|
|
672
|
-
const name = signalName(signal);
|
|
673
|
-
const ms = duration(timeout, "timeout");
|
|
674
|
-
const process = await (await this.native()).processes.get(sessionId);
|
|
675
|
-
const kill = (async function* () {
|
|
676
|
-
try {
|
|
677
|
-
await process.kill(name);
|
|
678
|
-
yield { type: "signal", signal: name };
|
|
679
|
-
try {
|
|
680
|
-
const result = await process.wait({ signal: timeoutSignal(ms) });
|
|
681
|
-
yield { type: "exited", exitCode: result.exitCode ?? undefined };
|
|
682
|
-
}
|
|
683
|
-
catch (error) {
|
|
684
|
-
if (!(error instanceof Error) || !["TimeoutError", "AbortError"].includes(error.name))
|
|
685
|
-
throw error;
|
|
686
|
-
yield { type: "timeout", message: `Still running after ${timeout}` };
|
|
687
|
-
await process.kill("SIGKILL");
|
|
688
|
-
yield { type: "killed", signal: "SIGKILL" };
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
catch (error) {
|
|
692
|
-
if (!(error instanceof RuntimeError))
|
|
693
|
-
throw error;
|
|
694
|
-
yield { type: "error", message: error.message };
|
|
695
|
-
return;
|
|
696
|
-
}
|
|
697
|
-
yield { type: "complete" };
|
|
698
|
-
})();
|
|
699
|
-
return new SessionKillStream(kill);
|
|
700
|
-
}
|
|
701
|
-
/** Ports listening in the Sprite now, then each one opened or closed. */
|
|
702
|
-
async watchPorts() {
|
|
703
|
-
const watcher = new PortWatcher(this.client, this.id ?? this.name);
|
|
704
|
-
await watcher.connect();
|
|
705
|
-
return watcher;
|
|
706
|
-
}
|
|
707
|
-
/** Runtime keeps each sandbox's system current itself; this checks it exists. */
|
|
708
|
-
async upgrade() {
|
|
709
|
-
await this.client.upgradeSprite(this.id ?? this.name);
|
|
710
|
-
}
|
|
711
|
-
check() {
|
|
712
|
-
return this.client.checkSprite(this.id ?? this.name);
|
|
713
|
-
}
|
|
714
|
-
/** A checkpoint is a Runtime disk snapshot: the files, not the running
|
|
715
|
-
* processes. The Sprite is paused for the moment it takes, then woken.
|
|
716
|
-
* Progress arrives as the vendor's stream; a refusal is an `error` message. */
|
|
717
|
-
async createCheckpoint(comment) {
|
|
718
|
-
if (comment !== undefined && typeof comment !== "string")
|
|
719
|
-
throw new TypeError("comment must be a string");
|
|
720
|
-
const s = await this.native();
|
|
721
|
-
const taken = s.snapshot({
|
|
722
|
-
mode: "disk",
|
|
723
|
-
labels: { "compat.sprite": s.id, ...(comment ? { "compat.comment": comment } : {}) },
|
|
724
|
-
});
|
|
725
|
-
taken.catch(() => undefined);
|
|
726
|
-
return new CheckpointStream((async function* () {
|
|
727
|
-
yield { type: "info", data: "Creating checkpoint" };
|
|
728
|
-
try {
|
|
729
|
-
const snapshot = await taken;
|
|
730
|
-
yield { type: "info", data: `Checkpoint ${snapshot.id} created` };
|
|
731
|
-
}
|
|
732
|
-
catch (error) {
|
|
733
|
-
if (!(error instanceof RuntimeError))
|
|
734
|
-
throw error;
|
|
735
|
-
yield { type: "error", error: error.message };
|
|
736
|
-
return;
|
|
737
|
-
}
|
|
738
|
-
yield { type: "complete" };
|
|
739
|
-
})());
|
|
740
|
-
}
|
|
741
|
-
/** This Sprite's disk snapshots, newest first. */
|
|
742
|
-
async listCheckpoints(historyFilter) {
|
|
743
|
-
if (historyFilter !== undefined)
|
|
744
|
-
throw new CompatibilityError("Sprites", "checkpoint history filters");
|
|
745
|
-
const s = await this.native();
|
|
746
|
-
const found = [];
|
|
747
|
-
for await (const snapshot of await this.client.runtime.snapshots.list({
|
|
748
|
-
sandboxId: s.id,
|
|
749
|
-
state: "ready",
|
|
750
|
-
}))
|
|
751
|
-
if (snapshot.mode === "disk" && snapshot.sourceSandboxId === s.id)
|
|
752
|
-
found.push(checkpoint(snapshot));
|
|
753
|
-
return found.sort((a, b) => b.createTime.getTime() - a.createTime.getTime());
|
|
754
|
-
}
|
|
755
|
-
async getCheckpoint(id) {
|
|
756
|
-
const s = await this.native();
|
|
757
|
-
let snapshot;
|
|
758
|
-
try {
|
|
759
|
-
snapshot = await this.client.runtime.snapshots.get(id);
|
|
760
|
-
}
|
|
761
|
-
catch (error) {
|
|
762
|
-
if (error instanceof NotFoundError)
|
|
763
|
-
throw new Error(`Checkpoint not found: ${id}`);
|
|
764
|
-
throw error;
|
|
765
|
-
}
|
|
766
|
-
if (snapshot.mode !== "disk" || snapshot.sourceSandboxId !== s.id)
|
|
767
|
-
throw new Error(`Checkpoint not found: ${id}`);
|
|
768
|
-
return checkpoint(snapshot);
|
|
769
|
-
}
|
|
770
|
-
/** Forwards localhost:`localPort` here to `remotePort` in the Sprite. */
|
|
771
|
-
proxyPort(localPort, remotePort, remoteHost) {
|
|
772
|
-
return proxyPort(this.client, this.id ?? this.name, localPort, remotePort, remoteHost);
|
|
773
|
-
}
|
|
774
|
-
proxyPorts(mappings) {
|
|
775
|
-
return proxyPorts(this.client, this.id ?? this.name, mappings);
|
|
776
|
-
}
|
|
777
|
-
/** Runtime's network rules as Sprites rules: `* deny` closes the internet,
|
|
778
|
-
* allow rules are the only destinations reachable, deny rules are refused. */
|
|
779
|
-
async getNetworkPolicy() {
|
|
780
|
-
const policy = await (await this.native()).network.get();
|
|
781
|
-
if (!policy.internet)
|
|
782
|
-
return { rules: [{ domain: "*", action: "deny" }] };
|
|
783
|
-
const rules = [
|
|
784
|
-
...policy.allow.map((domain) => ({ domain, action: "allow" })),
|
|
785
|
-
...policy.deny.map((domain) => ({ domain, action: "deny" })),
|
|
786
|
-
];
|
|
787
|
-
if (policy.allow.length)
|
|
788
|
-
rules.push({ domain: "*", action: "deny" });
|
|
789
|
-
return { rules };
|
|
790
|
-
}
|
|
791
|
-
/** Replaces the rules, keeping any host:port openings set through Runtime. */
|
|
792
|
-
async updateNetworkPolicy(policy) {
|
|
793
|
-
const rules = networkRules(policy);
|
|
794
|
-
const s = await this.native();
|
|
795
|
-
const current = await s.network.get();
|
|
796
|
-
await s.network.set({ ...rules, connect: current.connect });
|
|
797
|
-
}
|
|
798
|
-
/** Control mode is never on: Runtime refuses `controlMode: true`. */
|
|
799
|
-
useControlMode() {
|
|
800
|
-
return false;
|
|
801
|
-
}
|
|
802
|
-
hasControlConnection() {
|
|
803
|
-
return false;
|
|
804
|
-
}
|
|
805
|
-
/** Nothing to close: no control connection is ever opened. */
|
|
806
|
-
closeControlConnection() { }
|
|
807
|
-
async updateURLSettings(settings) {
|
|
808
|
-
validateURLSettings(settings);
|
|
809
|
-
const p = await (await this.native()).previews.create(8080, { visibility: settings.auth === "public" ? "public" : "private" });
|
|
810
|
-
this.url = p.urlWithToken ?? p.url;
|
|
811
|
-
this.urlSettings = { auth: settings.auth };
|
|
812
|
-
}
|
|
813
|
-
async update(options) {
|
|
814
|
-
only("Sprites update", options, ["labels", "urlSettings"]);
|
|
815
|
-
if (options.labels === undefined && options.urlSettings === undefined)
|
|
816
|
-
throw new TypeError("urlSettings or labels is required");
|
|
817
|
-
if (options.urlSettings !== undefined)
|
|
818
|
-
validateURLSettings(options.urlSettings);
|
|
819
|
-
validateLabels(options.labels);
|
|
820
|
-
const s = await this.native();
|
|
821
|
-
if (options.labels)
|
|
822
|
-
await s.update({
|
|
823
|
-
labels: { ...s.info.labels, "compat.labels": JSON.stringify(options.labels) },
|
|
824
|
-
});
|
|
825
|
-
if (options.urlSettings)
|
|
826
|
-
await this.updateURLSettings(options.urlSettings);
|
|
827
|
-
this.hydrate(s);
|
|
828
|
-
return this;
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
const SERVICES = "Runtime has no service manager; run it as a process with spawn, or as an image's start command";
|
|
832
|
-
refuse("Sprites", "Sprite", Sprite, {
|
|
833
|
-
restoreCheckpoint: "Runtime has no in-place restore; start a new sandbox from the checkpoint with runtime.sandboxes.create({ snapshot: id })",
|
|
834
|
-
getControlConnection: CONTROL,
|
|
835
|
-
listServices: SERVICES,
|
|
836
|
-
getService: SERVICES,
|
|
837
|
-
createService: SERVICES,
|
|
838
|
-
deleteService: SERVICES,
|
|
839
|
-
startService: SERVICES,
|
|
840
|
-
stopService: SERVICES,
|
|
841
|
-
restartService: SERVICES,
|
|
842
|
-
getServiceLogs: SERVICES,
|
|
843
|
-
signalService: SERVICES,
|
|
844
|
-
getPrivilegesPolicy: "Runtime sets one privilege profile for every sandbox: root through sudo",
|
|
845
|
-
updatePrivilegesPolicy: "Runtime sets one privilege profile for every sandbox: root through sudo",
|
|
846
|
-
deletePrivilegesPolicy: "Runtime sets one privilege profile for every sandbox: root through sudo",
|
|
847
|
-
getResourcesPolicy: "read the sandbox's memory size from runtime.sandboxes.get",
|
|
848
|
-
updateResourcesPolicy: "change memory with the native sandbox's resize(), which restarts its programs",
|
|
849
|
-
deleteResourcesPolicy: "change memory with the native sandbox's resize(), which restarts its programs",
|
|
850
|
-
});
|
|
851
|
-
function checkpoint(snapshot) {
|
|
852
|
-
const labels = (snapshot.labels ?? {});
|
|
853
|
-
return {
|
|
854
|
-
id: snapshot.id,
|
|
855
|
-
createTime: new Date(snapshot.createdAt),
|
|
856
|
-
comment: labels["compat.comment"],
|
|
857
|
-
isAuto: false,
|
|
858
|
-
health: snapshot.state === "ready" ? "" : snapshot.state,
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
/** Sprites lets the more specific rule win and reads `rules: []` as no
|
|
862
|
-
* limit; Runtime's allow list is the only destinations reachable and its deny
|
|
863
|
-
* list always wins. A policy whose meaning would differ is refused. */
|
|
864
|
-
function networkRules(policy) {
|
|
865
|
-
if (!policy || typeof policy !== "object" || !Array.isArray(policy.rules))
|
|
866
|
-
throw new TypeError("policy.rules must be an array");
|
|
867
|
-
only("Sprites network policy", policy, ["rules"]);
|
|
868
|
-
const allow = [];
|
|
869
|
-
const deny = [];
|
|
870
|
-
let everything;
|
|
871
|
-
for (const rule of policy.rules) {
|
|
872
|
-
if (!rule || typeof rule !== "object")
|
|
873
|
-
throw new TypeError("Each rule must be an object");
|
|
874
|
-
only("Sprites network rule", rule, ["domain", "action", "include"]);
|
|
875
|
-
if (rule.include !== undefined)
|
|
876
|
-
throw new CompatibilityError("Sprites", `the network preset ${String(rule.include)}; list its domains as allow rules`);
|
|
877
|
-
if (typeof rule.domain !== "string" || !rule.domain.trim())
|
|
878
|
-
throw new TypeError("Each rule needs a domain");
|
|
879
|
-
if (rule.action !== "allow" && rule.action !== "deny")
|
|
880
|
-
throw new TypeError("action must be allow or deny");
|
|
881
|
-
const domain = rule.domain.trim().toLowerCase();
|
|
882
|
-
if (domain === "*") {
|
|
883
|
-
if (everything && everything !== rule.action)
|
|
884
|
-
throw new TypeError("* is both allowed and denied");
|
|
885
|
-
everything = rule.action;
|
|
886
|
-
}
|
|
887
|
-
else
|
|
888
|
-
(rule.action === "allow" ? allow : deny).push(domain);
|
|
889
|
-
}
|
|
890
|
-
const covers = (wide, narrow) => wide === narrow || (wide.startsWith("*.") && narrow.endsWith(wide.slice(1)));
|
|
891
|
-
for (const allowed of allow)
|
|
892
|
-
for (const denied of deny)
|
|
893
|
-
if (covers(denied, allowed))
|
|
894
|
-
throw new CompatibilityError("Sprites", `allowing ${allowed} inside the denied ${denied}; Runtime's deny rules always win`);
|
|
895
|
-
if (everything === "deny" && !allow.length)
|
|
896
|
-
return { internet: false, allow: [], deny };
|
|
897
|
-
return { internet: true, allow: everything === "allow" ? [] : allow, deny };
|
|
898
|
-
}
|
|
899
|
-
/** A local listener that carries each connection to a port in the Sprite,
|
|
900
|
-
* over Runtime's tunnel. Node and Bun. */
|
|
901
|
-
export class ProxySession extends EventEmitter {
|
|
902
|
-
localPort;
|
|
903
|
-
remotePort;
|
|
904
|
-
remoteHost;
|
|
905
|
-
#sprite;
|
|
906
|
-
#forward;
|
|
907
|
-
#closed = false;
|
|
908
|
-
#done;
|
|
909
|
-
#finish;
|
|
910
|
-
constructor(client, spriteName, mapping) {
|
|
911
|
-
super();
|
|
912
|
-
only("Sprites port mapping", mapping, ["localPort", "remotePort", "remoteHost"]);
|
|
913
|
-
for (const [name, port] of [
|
|
914
|
-
["localPort", mapping.localPort],
|
|
915
|
-
["remotePort", mapping.remotePort],
|
|
916
|
-
])
|
|
917
|
-
if (!Number.isInteger(port) ||
|
|
918
|
-
port < 0 ||
|
|
919
|
-
port > 65535 ||
|
|
920
|
-
(name === "remotePort" && port === 0))
|
|
921
|
-
throw new TypeError(`${name} must be a port number`);
|
|
922
|
-
const host = mapping.remoteHost ?? "localhost";
|
|
923
|
-
if (!["localhost", "127.0.0.1", "::1"].includes(host))
|
|
924
|
-
throw new CompatibilityError("Sprites", `proxying to ${host}; forward a port of the Sprite itself (localhost)`);
|
|
925
|
-
this.localPort = mapping.localPort;
|
|
926
|
-
this.remotePort = mapping.remotePort;
|
|
927
|
-
this.remoteHost = host;
|
|
928
|
-
const owner = client instanceof SpritesClient
|
|
929
|
-
? client
|
|
930
|
-
: new SpritesClient(client.token, { baseURL: client.baseURL });
|
|
931
|
-
this.#sprite = owner.sprite(spriteName);
|
|
932
|
-
this.#done = new Promise((resolve) => (this.#finish = resolve));
|
|
933
|
-
}
|
|
934
|
-
async start() {
|
|
935
|
-
if (this.#closed)
|
|
936
|
-
throw new Error("Proxy session is closed");
|
|
937
|
-
try {
|
|
938
|
-
const s = await ready(await this.#sprite.native());
|
|
939
|
-
this.#forward = await s.forwardPort(this.remotePort, {
|
|
940
|
-
localPort: this.localPort,
|
|
941
|
-
host: "localhost",
|
|
942
|
-
});
|
|
943
|
-
}
|
|
944
|
-
catch (error) {
|
|
945
|
-
if (this.listenerCount("error"))
|
|
946
|
-
this.emit("error", error);
|
|
947
|
-
throw error;
|
|
948
|
-
}
|
|
949
|
-
if (this.#closed)
|
|
950
|
-
await this.#forward.close();
|
|
951
|
-
}
|
|
952
|
-
localAddr() {
|
|
953
|
-
return this.#forward && !this.#closed ? `localhost:${this.#forward.localPort}` : null;
|
|
954
|
-
}
|
|
955
|
-
close() {
|
|
956
|
-
if (this.#closed)
|
|
957
|
-
return;
|
|
958
|
-
this.#closed = true;
|
|
959
|
-
void this.#forward?.close().catch(() => undefined);
|
|
960
|
-
this.#finish();
|
|
961
|
-
this.emit("close");
|
|
962
|
-
}
|
|
963
|
-
wait() {
|
|
964
|
-
return this.#done;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
export class ProxyManager {
|
|
968
|
-
#sessions = [];
|
|
969
|
-
addSession(session) {
|
|
970
|
-
this.#sessions.push(session);
|
|
971
|
-
}
|
|
972
|
-
closeAll() {
|
|
973
|
-
for (const session of this.#sessions)
|
|
974
|
-
session.close();
|
|
975
|
-
}
|
|
976
|
-
async waitAll() {
|
|
977
|
-
await Promise.all(this.#sessions.map((session) => session.wait()));
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
export async function proxyPort(client, spriteName, localPort, remotePort, remoteHost) {
|
|
981
|
-
const session = new ProxySession(client, spriteName, { localPort, remotePort, remoteHost });
|
|
982
|
-
await session.start();
|
|
983
|
-
return session;
|
|
984
|
-
}
|
|
985
|
-
/** All or none: a mapping that cannot start closes the ones before it. */
|
|
986
|
-
export async function proxyPorts(client, spriteName, mappings) {
|
|
987
|
-
const sessions = [];
|
|
988
|
-
try {
|
|
989
|
-
for (const mapping of mappings) {
|
|
990
|
-
const session = new ProxySession(client, spriteName, mapping);
|
|
991
|
-
sessions.push(session);
|
|
992
|
-
await session.start();
|
|
993
|
-
}
|
|
994
|
-
return sessions;
|
|
995
|
-
}
|
|
996
|
-
catch (error) {
|
|
997
|
-
for (const session of sessions)
|
|
998
|
-
session.close();
|
|
999
|
-
throw error;
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
/** Polls the Sprite's listening TCP sockets once a second with `ss` (as
|
|
1003
|
-
* Sprites' own watcher keeps a connection open, this keeps it awake). */
|
|
1004
|
-
export class PortWatcher extends Feed {
|
|
1005
|
-
#timer;
|
|
1006
|
-
#stopped = false;
|
|
1007
|
-
#sprite;
|
|
1008
|
-
constructor(client, spriteName) {
|
|
1009
|
-
super();
|
|
1010
|
-
this.#sprite = client.sprite(spriteName);
|
|
1011
|
-
}
|
|
1012
|
-
async connect() {
|
|
1013
|
-
const s = await ready(await this.#sprite.native());
|
|
1014
|
-
let known = await listening(s);
|
|
1015
|
-
this.push({ type: "port_list", ports: [...known.values()] });
|
|
1016
|
-
const tick = async () => {
|
|
1017
|
-
if (this.#stopped)
|
|
1018
|
-
return;
|
|
1019
|
-
try {
|
|
1020
|
-
const now = await listening(s);
|
|
1021
|
-
for (const [key, port] of known)
|
|
1022
|
-
if (!now.has(key))
|
|
1023
|
-
this.push({ ...port, type: "port_closed" });
|
|
1024
|
-
for (const [key, port] of now)
|
|
1025
|
-
if (!known.has(key))
|
|
1026
|
-
this.push(port);
|
|
1027
|
-
known = now;
|
|
1028
|
-
}
|
|
1029
|
-
catch (error) {
|
|
1030
|
-
this.end(error);
|
|
1031
|
-
return;
|
|
1032
|
-
}
|
|
1033
|
-
if (!this.#stopped)
|
|
1034
|
-
this.#timer = setTimeout(() => void tick(), 1000);
|
|
1035
|
-
};
|
|
1036
|
-
this.#timer = setTimeout(() => void tick(), 1000);
|
|
1037
|
-
}
|
|
1038
|
-
stop() {
|
|
1039
|
-
this.#stopped = true;
|
|
1040
|
-
if (this.#timer)
|
|
1041
|
-
clearTimeout(this.#timer);
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
async function listening(s) {
|
|
1045
|
-
const result = await s.exec(["ss", "-Hltnp"]);
|
|
1046
|
-
if (result.exitCode !== 0)
|
|
1047
|
-
throw new Error(`Cannot list ports in the Sprite: ${result.stderr.trim() || "ss failed"}`);
|
|
1048
|
-
const ports = new Map();
|
|
1049
|
-
for (const line of result.stdout.split("\n")) {
|
|
1050
|
-
const local = line.trim().split(/\s+/)[3];
|
|
1051
|
-
if (!local)
|
|
1052
|
-
continue;
|
|
1053
|
-
const at = local.lastIndexOf(":");
|
|
1054
|
-
const port = Number(local.slice(at + 1));
|
|
1055
|
-
if (!Number.isInteger(port))
|
|
1056
|
-
continue;
|
|
1057
|
-
const address = local
|
|
1058
|
-
.slice(0, at)
|
|
1059
|
-
.replace(/^\[|\]$/g, "")
|
|
1060
|
-
.replace(/%.*$/, "");
|
|
1061
|
-
const pid = Number(/pid=(\d+)/.exec(line)?.[1] ?? 0);
|
|
1062
|
-
ports.set(`${address}:${port}`, { type: "port_opened", port, address, pid });
|
|
1063
|
-
}
|
|
1064
|
-
return ports;
|
|
1065
|
-
}
|
|
1066
|
-
/** Runtime's file watch, one per path, as Sprites' watch events. */
|
|
1067
|
-
export class FilesystemWatcher extends Feed {
|
|
1068
|
-
sandbox;
|
|
1069
|
-
paths;
|
|
1070
|
-
recursive;
|
|
1071
|
-
#handles = [];
|
|
1072
|
-
#stopped = false;
|
|
1073
|
-
#files;
|
|
1074
|
-
constructor(sandbox, paths, workingDir, recursive) {
|
|
1075
|
-
super();
|
|
1076
|
-
this.sandbox = sandbox;
|
|
1077
|
-
this.paths = paths;
|
|
1078
|
-
this.recursive = recursive;
|
|
1079
|
-
this.#files = new GuestFiles(sandbox, workingDir);
|
|
1080
|
-
}
|
|
1081
|
-
async connect() {
|
|
1082
|
-
const s = await this.sandbox();
|
|
1083
|
-
const paths = this.paths.map((path) => this.#files.path(path));
|
|
1084
|
-
try {
|
|
1085
|
-
for (const path of paths) {
|
|
1086
|
-
const handle = await s.files.watch(path, (event) => {
|
|
1087
|
-
if (event.type === "access")
|
|
1088
|
-
return;
|
|
1089
|
-
this.push({
|
|
1090
|
-
type: "event",
|
|
1091
|
-
path: event.path,
|
|
1092
|
-
event: event.type,
|
|
1093
|
-
isDir: event.isDir,
|
|
1094
|
-
timestamp: new Date().toISOString(),
|
|
1095
|
-
});
|
|
1096
|
-
}, { recursive: this.recursive, timeoutMs: 0 });
|
|
1097
|
-
this.#handles.push(handle);
|
|
1098
|
-
if (this.#stopped)
|
|
1099
|
-
void handle.stop().catch(() => undefined);
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
catch (error) {
|
|
1103
|
-
this.stop();
|
|
1104
|
-
throw error;
|
|
1105
|
-
}
|
|
1106
|
-
this.push({ type: "subscribed", paths });
|
|
1107
|
-
}
|
|
1108
|
-
stop() {
|
|
1109
|
-
this.#stopped = true;
|
|
1110
|
-
for (const handle of this.#handles.splice(0))
|
|
1111
|
-
void handle.stop().catch(() => undefined);
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
export class SpriteCommand extends EventEmitter {
|
|
1115
|
-
stdout = new PassThrough();
|
|
1116
|
-
stderr = new PassThrough();
|
|
1117
|
-
stdin;
|
|
1118
|
-
process;
|
|
1119
|
-
completion;
|
|
1120
|
-
code = -1;
|
|
1121
|
-
controller = new AbortController();
|
|
1122
|
-
constructor(sprite, command, args = [], options = {}) {
|
|
1123
|
-
super();
|
|
1124
|
-
only("Sprites spawn", options, EXEC_KEYS);
|
|
1125
|
-
if (options.controlMode)
|
|
1126
|
-
throw new CompatibilityError("Sprites", "control-mode wire protocol");
|
|
1127
|
-
this.process = (async () => {
|
|
1128
|
-
const s = await ready(await sprite.native());
|
|
1129
|
-
return options.sessionId
|
|
1130
|
-
? s.processes.get(options.sessionId)
|
|
1131
|
-
: s.spawn([command, ...args], {
|
|
1132
|
-
...(await execOptions(s, { cwd: options.cwd, env: options.env })),
|
|
1133
|
-
stdin: "pipe",
|
|
1134
|
-
outputEncoding: "base64",
|
|
1135
|
-
pty: options.tty ? { rows: options.rows, cols: options.cols } : undefined,
|
|
1136
|
-
});
|
|
1137
|
-
})();
|
|
1138
|
-
this.stdin = new Writable({
|
|
1139
|
-
write: (chunk, _encoding, callback) => {
|
|
1140
|
-
void this.process.then((p) => p.write(chunk)).then(() => callback(), callback);
|
|
1141
|
-
},
|
|
1142
|
-
final: (callback) => {
|
|
1143
|
-
void this.process.then((p) => p.write("", { eof: true })).then(() => callback(), callback);
|
|
1144
|
-
},
|
|
1145
|
-
});
|
|
1146
|
-
this.completion = this.follow();
|
|
1147
|
-
this.completion.catch((error) => {
|
|
1148
|
-
if (this.listenerCount("error"))
|
|
1149
|
-
this.emit("error", error);
|
|
1150
|
-
});
|
|
1151
|
-
}
|
|
1152
|
-
async follow() {
|
|
1153
|
-
try {
|
|
1154
|
-
const p = await this.process;
|
|
1155
|
-
this.emit("spawn");
|
|
1156
|
-
this.emit("session", p.id);
|
|
1157
|
-
for await (const e of p.outputBytes({ signal: this.controller.signal })) {
|
|
1158
|
-
if (e.type === "stdout")
|
|
1159
|
-
this.stdout.write(e.data);
|
|
1160
|
-
else if (e.type === "stderr")
|
|
1161
|
-
this.stderr.write(e.data);
|
|
1162
|
-
else if (e.type === "truncated")
|
|
1163
|
-
throw new Error("Sprite command output was truncated");
|
|
1164
|
-
else if (e.type === "exit")
|
|
1165
|
-
this.code = e.exitCode ?? -1;
|
|
1166
|
-
}
|
|
1167
|
-
this.emit("exit", this.code);
|
|
1168
|
-
this.emit("close", this.code);
|
|
1169
|
-
return this.code;
|
|
1170
|
-
}
|
|
1171
|
-
finally {
|
|
1172
|
-
this.stdout.end();
|
|
1173
|
-
this.stderr.end();
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
async start() {
|
|
1177
|
-
await this.process;
|
|
1178
|
-
}
|
|
1179
|
-
wait() {
|
|
1180
|
-
return this.completion;
|
|
1181
|
-
}
|
|
1182
|
-
kill(signal = "SIGTERM") {
|
|
1183
|
-
this.signal(signal);
|
|
1184
|
-
}
|
|
1185
|
-
signal(signal) {
|
|
1186
|
-
if (!["SIGTERM", "SIGKILL", "SIGINT", "SIGHUP", "SIGQUIT", "SIGUSR1", "SIGUSR2"].includes(signal))
|
|
1187
|
-
throw new TypeError(`Unsupported signal ${signal}`);
|
|
1188
|
-
void this.process
|
|
1189
|
-
.then((p) => p.kill(signal))
|
|
1190
|
-
.catch((error) => {
|
|
1191
|
-
if (this.listenerCount("error"))
|
|
1192
|
-
this.emit("error", error);
|
|
1193
|
-
});
|
|
1194
|
-
}
|
|
1195
|
-
resize(cols, rows) {
|
|
1196
|
-
void this.process
|
|
1197
|
-
.then((p) => p.resize(cols, rows))
|
|
1198
|
-
.catch((error) => {
|
|
1199
|
-
if (this.listenerCount("error"))
|
|
1200
|
-
this.emit("error", error);
|
|
1201
|
-
});
|
|
1202
|
-
}
|
|
1203
|
-
close() {
|
|
1204
|
-
this.controller.abort();
|
|
1205
|
-
}
|
|
1206
|
-
exitCode() {
|
|
1207
|
-
return this.code;
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
export class SpriteFilesystem {
|
|
1211
|
-
get;
|
|
1212
|
-
cwd;
|
|
1213
|
-
files;
|
|
1214
|
-
constructor(get, cwd = "/") {
|
|
1215
|
-
this.get = get;
|
|
1216
|
-
this.cwd = cwd;
|
|
1217
|
-
this.files = new GuestFiles(get, cwd);
|
|
1218
|
-
}
|
|
1219
|
-
async readFile(path, encoding) {
|
|
1220
|
-
const bytes = Buffer.from(await fileOperation(path, "read", () => this.files.readFile(path)));
|
|
1221
|
-
return encoding === "utf8" ? bytes.toString("utf8") : bytes;
|
|
1222
|
-
}
|
|
1223
|
-
writeFile(path, data, options) {
|
|
1224
|
-
return fileOperation(path, "write", () => this.files.writeFile(path, data, options));
|
|
1225
|
-
}
|
|
1226
|
-
async readdir(path, options = {}) {
|
|
1227
|
-
only("Sprites readdir", options, ["withFileTypes", "recursive", "pattern", "encoding"]);
|
|
1228
|
-
if (options.encoding && options.encoding !== "utf8")
|
|
1229
|
-
throw new CompatibilityError("Sprites", "directory name encodings other than utf8");
|
|
1230
|
-
if (options.recursive && options.pattern)
|
|
1231
|
-
throw new CompatibilityError("Sprites", "recursive listing with a glob pattern");
|
|
1232
|
-
const entries = await fileOperation(path, "readdir", async () => {
|
|
1233
|
-
const s = await this.get();
|
|
1234
|
-
const entries = await s.files.list(this.files.path(path), {
|
|
1235
|
-
hidden: true,
|
|
1236
|
-
glob: options.pattern,
|
|
1237
|
-
});
|
|
1238
|
-
if (options.recursive)
|
|
1239
|
-
for (let i = 0; i < entries.length; i++)
|
|
1240
|
-
if (entries[i].type === "directory")
|
|
1241
|
-
entries.push(...(await s.files.list(entries[i].path, { hidden: true })));
|
|
1242
|
-
return entries;
|
|
1243
|
-
});
|
|
1244
|
-
return entries.map((e) => options.withFileTypes
|
|
1245
|
-
? {
|
|
1246
|
-
name: e.name,
|
|
1247
|
-
parentPath: path,
|
|
1248
|
-
isDirectory: () => e.type === "directory",
|
|
1249
|
-
isFile: () => e.type === "file",
|
|
1250
|
-
isSymbolicLink: () => e.type === "symlink",
|
|
1251
|
-
}
|
|
1252
|
-
: e.name);
|
|
1253
|
-
}
|
|
1254
|
-
async mkdir(path, options = {}) {
|
|
1255
|
-
await fileOperation(path, "mkdir", () => this.files.mkdir(path, options.recursive));
|
|
1256
|
-
if (options.mode !== undefined)
|
|
1257
|
-
await this.files.chmod(path, options.mode);
|
|
1258
|
-
}
|
|
1259
|
-
async rm(path, options = {}) {
|
|
1260
|
-
if (!options.force && !(await this.files.exists(path)))
|
|
1261
|
-
throw new FilesystemError(`Path not found: ${path}`, "ENOENT", path, "rm");
|
|
1262
|
-
if (options.asRoot)
|
|
1263
|
-
return this.#root(path, "rm", ["rm", "-f", ...(options.recursive ? ["-r"] : []), "--", this.files.path(path)], true);
|
|
1264
|
-
await fileOperation(path, "rm", () => this.files.remove(path, options.recursive));
|
|
1265
|
-
}
|
|
1266
|
-
async stat(path) {
|
|
1267
|
-
const e = await fileOperation(path, "stat", () => this.files.stat(path));
|
|
1268
|
-
return {
|
|
1269
|
-
size: e.size,
|
|
1270
|
-
mode: parseInt(e.mode, 8),
|
|
1271
|
-
mtime: new Date(e.modifiedAt),
|
|
1272
|
-
atime: new Date(e.modifiedAt),
|
|
1273
|
-
birthtime: new Date(e.modifiedAt),
|
|
1274
|
-
isDirectory: () => e.type === "directory",
|
|
1275
|
-
isFile: () => e.type === "file",
|
|
1276
|
-
isSymbolicLink: () => e.type === "symlink",
|
|
1277
|
-
};
|
|
1278
|
-
}
|
|
1279
|
-
async rename(from, to, options = {}) {
|
|
1280
|
-
if (options.asRoot)
|
|
1281
|
-
return this.#root(from, "rename", ["mv", "-f", "-T", "--", this.files.path(from), this.files.path(to)], true);
|
|
1282
|
-
return fileOperation(from, "rename", () => this.files.rename(from, to, true));
|
|
1283
|
-
}
|
|
1284
|
-
async copyFile(from, to, options = {}) {
|
|
1285
|
-
if (options.asRoot || options.preserveAttrs)
|
|
1286
|
-
return this.#root(from, "copyFile", [
|
|
1287
|
-
"cp",
|
|
1288
|
-
...(options.recursive ? ["-R"] : []),
|
|
1289
|
-
...(options.preserveAttrs ? ["--preserve=mode,ownership,timestamps"] : []),
|
|
1290
|
-
"--",
|
|
1291
|
-
this.files.path(from),
|
|
1292
|
-
this.files.path(to),
|
|
1293
|
-
], options.asRoot === true);
|
|
1294
|
-
return fileOperation(from, "copyFile", () => this.files.copy(from, to, options.recursive, true));
|
|
1295
|
-
}
|
|
1296
|
-
async chmod(path, mode, options = {}) {
|
|
1297
|
-
if (options.asRoot) {
|
|
1298
|
-
if (!Number.isInteger(mode) || mode < 0)
|
|
1299
|
-
throw new TypeError("mode must be a file mode");
|
|
1300
|
-
return this.#root(path, "chmod", [
|
|
1301
|
-
"chmod",
|
|
1302
|
-
...(options.recursive ? ["-R"] : []),
|
|
1303
|
-
(mode & 0o7777).toString(8),
|
|
1304
|
-
"--",
|
|
1305
|
-
this.files.path(path),
|
|
1306
|
-
], true);
|
|
1307
|
-
}
|
|
1308
|
-
return fileOperation(path, "chmod", () => this.files.chmod(path, mode, options.recursive));
|
|
1309
|
-
}
|
|
1310
|
-
/** By number or name, as the Sprite's user unless `asRoot` (sudo). */
|
|
1311
|
-
async chown(path, options) {
|
|
1312
|
-
only("Sprites chown", options ?? {}, ["uid", "gid", "recursive", "asRoot"]);
|
|
1313
|
-
if (options?.uid === undefined && options?.gid === undefined)
|
|
1314
|
-
throw new TypeError("uid or gid is required");
|
|
1315
|
-
for (const id of [options.uid, options.gid])
|
|
1316
|
-
if (id !== undefined &&
|
|
1317
|
-
!(typeof id === "number" ? Number.isInteger(id) && id >= 0 : /^[A-Za-z0-9._-]+$/.test(id)))
|
|
1318
|
-
throw new TypeError("uid and gid must be ids or user and group names");
|
|
1319
|
-
const owner = `${options.uid ?? ""}${options.gid === undefined ? "" : `:${options.gid}`}`;
|
|
1320
|
-
return this.#root(path, "chown", ["chown", ...(options.recursive ? ["-R"] : []), owner, "--", this.files.path(path)], options.asRoot === true);
|
|
1321
|
-
}
|
|
1322
|
-
/** Changes to these paths until the watcher is closed. */
|
|
1323
|
-
async watch(paths, options = {}) {
|
|
1324
|
-
only("Sprites watch", options, ["recursive"]);
|
|
1325
|
-
const list = Array.isArray(paths) ? paths : [paths];
|
|
1326
|
-
if (!list.length || list.some((path) => typeof path !== "string" || !path))
|
|
1327
|
-
throw new TypeError("paths must name at least one path");
|
|
1328
|
-
const watcher = new FilesystemWatcher(this.get, list, this.cwd, options.recursive === true);
|
|
1329
|
-
await watcher.connect();
|
|
1330
|
-
return watcher;
|
|
1331
|
-
}
|
|
1332
|
-
/** A guest command for what the file API does not offer: as root through
|
|
1333
|
-
* sudo when asked, and its failure as the vendor's FilesystemError. */
|
|
1334
|
-
async #root(path, syscall, argv, asRoot) {
|
|
1335
|
-
const result = await (await this.get()).exec(asRoot ? ["sudo", "-n", "--", ...argv] : argv);
|
|
1336
|
-
if (result.exitCode === 0)
|
|
1337
|
-
return;
|
|
1338
|
-
const message = result.stderr.trim() || `${syscall} failed`;
|
|
1339
|
-
const code = /No such file/i.test(message)
|
|
1340
|
-
? "ENOENT"
|
|
1341
|
-
: /File exists/i.test(message)
|
|
1342
|
-
? "EEXIST"
|
|
1343
|
-
: /Not a directory/i.test(message)
|
|
1344
|
-
? "ENOTDIR"
|
|
1345
|
-
: /Is a directory/i.test(message)
|
|
1346
|
-
? "EISDIR"
|
|
1347
|
-
: /Directory not empty/i.test(message)
|
|
1348
|
-
? "ENOTEMPTY"
|
|
1349
|
-
: /Operation not permitted|password is required|sudo:/i.test(message)
|
|
1350
|
-
? "EPERM"
|
|
1351
|
-
: /Permission denied/i.test(message)
|
|
1352
|
-
? "EACCES"
|
|
1353
|
-
: /invalid/i.test(message)
|
|
1354
|
-
? "EINVAL"
|
|
1355
|
-
: "UNKNOWN";
|
|
1356
|
-
throw new FilesystemError(message, code, path, syscall);
|
|
1357
|
-
}
|
|
1358
|
-
exists(path) {
|
|
1359
|
-
return this.files.exists(path);
|
|
1360
|
-
}
|
|
1361
|
-
appendFile(path, data) {
|
|
1362
|
-
return fileOperation(path, "appendFile", () => this.files.appendFile(path, data));
|
|
1363
|
-
}
|
|
1364
|
-
async readJSON(path) {
|
|
1365
|
-
return JSON.parse(await this.readFile(path, "utf8"));
|
|
1366
|
-
}
|
|
1367
|
-
writeJSON(path, data, options = {}) {
|
|
1368
|
-
return this.writeFile(path, JSON.stringify(data, null, options.spaces));
|
|
1369
|
-
}
|
|
1370
|
-
}
|