@wildo-ai/wildo-cli 1.1.14 → 1.1.16
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/src/commands/context/journey.command.d.ts.map +1 -1
- package/dist/src/commands/context/journey.command.js +12 -0
- package/dist/src/commands/context/journey.command.js.map +1 -1
- package/dist/src/commands/creation/drive.command.d.ts.map +1 -1
- package/dist/src/commands/creation/drive.command.js +2 -1
- package/dist/src/commands/creation/drive.command.js.map +1 -1
- package/dist/src/commands/generate/email-command.utils.d.ts +2 -0
- package/dist/src/commands/generate/email-command.utils.d.ts.map +1 -1
- package/dist/src/commands/generate/email-command.utils.js +5 -0
- package/dist/src/commands/generate/email-command.utils.js.map +1 -1
- package/dist/src/commands/init.command.d.ts.map +1 -1
- package/dist/src/commands/init.command.js +7 -2
- package/dist/src/commands/init.command.js.map +1 -1
- package/dist/src/commands/local/deregister.command.d.ts.map +1 -1
- package/dist/src/commands/local/deregister.command.js +4 -0
- package/dist/src/commands/local/deregister.command.js.map +1 -1
- package/dist/src/commands/local/dev.command.d.ts +50 -0
- package/dist/src/commands/local/dev.command.d.ts.map +1 -1
- package/dist/src/commands/local/dev.command.js +144 -1
- package/dist/src/commands/local/dev.command.js.map +1 -1
- package/dist/src/commands/local/jobs-command.utils.d.ts +24 -0
- package/dist/src/commands/local/jobs-command.utils.d.ts.map +1 -0
- package/dist/src/commands/local/jobs-command.utils.js +44 -0
- package/dist/src/commands/local/jobs-command.utils.js.map +1 -0
- package/dist/src/commands/local/jobs-run.command.d.ts +7 -0
- package/dist/src/commands/local/jobs-run.command.d.ts.map +1 -0
- package/dist/src/commands/local/jobs-run.command.js +92 -0
- package/dist/src/commands/local/jobs-run.command.js.map +1 -0
- package/dist/src/commands/local/jobs.command.d.ts +7 -0
- package/dist/src/commands/local/jobs.command.d.ts.map +1 -0
- package/dist/src/commands/local/jobs.command.js +59 -0
- package/dist/src/commands/local/jobs.command.js.map +1 -0
- package/dist/src/commands/local/tunnel.command.d.ts +84 -0
- package/dist/src/commands/local/tunnel.command.d.ts.map +1 -0
- package/dist/src/commands/local/tunnel.command.js +274 -0
- package/dist/src/commands/local/tunnel.command.js.map +1 -0
- package/dist/src/commands/providers/grant-export.command.d.ts +16 -0
- package/dist/src/commands/providers/grant-export.command.d.ts.map +1 -0
- package/dist/src/commands/providers/grant-export.command.js +78 -0
- package/dist/src/commands/providers/grant-export.command.js.map +1 -0
- package/dist/src/commands/providers/grant-import.command.d.ts +15 -0
- package/dist/src/commands/providers/grant-import.command.d.ts.map +1 -0
- package/dist/src/commands/providers/grant-import.command.js +78 -0
- package/dist/src/commands/providers/grant-import.command.js.map +1 -0
- package/dist/src/kernel/command-runner.d.ts.map +1 -1
- package/dist/src/kernel/command-runner.js +4 -6
- package/dist/src/kernel/command-runner.js.map +1 -1
- package/dist/src/kernel/hooks.d.ts.map +1 -1
- package/dist/src/kernel/hooks.js +2 -1
- package/dist/src/kernel/hooks.js.map +1 -1
- package/dist/src/kernel/json-document-output.d.ts +7 -0
- package/dist/src/kernel/json-document-output.d.ts.map +1 -1
- package/dist/src/kernel/json-document-output.js +8 -0
- package/dist/src/kernel/json-document-output.js.map +1 -1
- package/dist/src/kernel/types.d.ts +8 -0
- package/dist/src/kernel/types.d.ts.map +1 -1
- package/dist/src/kernel/types.js.map +1 -1
- package/dist/src/services/application/app-bootstrap.service.d.ts +65 -7
- package/dist/src/services/application/app-bootstrap.service.d.ts.map +1 -1
- package/dist/src/services/application/app-bootstrap.service.js +94 -15
- package/dist/src/services/application/app-bootstrap.service.js.map +1 -1
- package/dist/src/services/application/app-local-runtime-addresses.service.d.ts +1 -1
- package/dist/src/services/application/app-local-runtime-addresses.service.d.ts.map +1 -1
- package/dist/src/services/application/app-local-runtime-addresses.service.js.map +1 -1
- package/dist/src/services/application/app-runtime-targets.service.d.ts.map +1 -1
- package/dist/src/services/application/app-runtime-targets.service.js +16 -2
- package/dist/src/services/application/app-runtime-targets.service.js.map +1 -1
- package/dist/src/services/application/application-dependency-alignment.service.d.ts +20 -0
- package/dist/src/services/application/application-dependency-alignment.service.d.ts.map +1 -1
- package/dist/src/services/application/application-dependency-alignment.service.js +32 -2
- package/dist/src/services/application/application-dependency-alignment.service.js.map +1 -1
- package/dist/src/services/application/application-runtime-bootstrap.service.d.ts +13 -0
- package/dist/src/services/application/application-runtime-bootstrap.service.d.ts.map +1 -1
- package/dist/src/services/application/application-runtime-bootstrap.service.js +32 -0
- package/dist/src/services/application/application-runtime-bootstrap.service.js.map +1 -1
- package/dist/src/services/application/environment-provider-configurations.service.d.ts +7 -0
- package/dist/src/services/application/environment-provider-configurations.service.d.ts.map +1 -1
- package/dist/src/services/application/environment-provider-configurations.service.js +1 -1
- package/dist/src/services/application/environment-provider-configurations.service.js.map +1 -1
- package/dist/src/services/application/local-tunnel.service.d.ts +153 -0
- package/dist/src/services/application/local-tunnel.service.d.ts.map +1 -0
- package/dist/src/services/application/local-tunnel.service.js +295 -0
- package/dist/src/services/application/local-tunnel.service.js.map +1 -0
- package/dist/src/services/application/provider-runtime-sync.service.d.ts.map +1 -1
- package/dist/src/services/application/provider-runtime-sync.service.js +3 -0
- package/dist/src/services/application/provider-runtime-sync.service.js.map +1 -1
- package/dist/src/services/application/saas-skeleton.service.d.ts +7 -0
- package/dist/src/services/application/saas-skeleton.service.d.ts.map +1 -1
- package/dist/src/services/application/saas-skeleton.service.js +2 -0
- package/dist/src/services/application/saas-skeleton.service.js.map +1 -1
- package/dist/src/services/catalog/service-address-resolver.service.d.ts +7 -1
- package/dist/src/services/catalog/service-address-resolver.service.d.ts.map +1 -1
- package/dist/src/services/catalog/service-address-resolver.service.js +6 -3
- package/dist/src/services/catalog/service-address-resolver.service.js.map +1 -1
- package/dist/src/services/companion/companion-client.service.d.ts +17 -0
- package/dist/src/services/companion/companion-client.service.d.ts.map +1 -1
- package/dist/src/services/companion/companion-client.service.js +21 -0
- package/dist/src/services/companion/companion-client.service.js.map +1 -1
- package/dist/src/services/companion/creation-drive.service.d.ts +18 -0
- package/dist/src/services/companion/creation-drive.service.d.ts.map +1 -1
- package/dist/src/services/companion/creation-drive.service.js +70 -1
- package/dist/src/services/companion/creation-drive.service.js.map +1 -1
- package/dist/src/services/credentials/application-secrets.service.d.ts +6 -0
- package/dist/src/services/credentials/application-secrets.service.d.ts.map +1 -1
- package/dist/src/services/credentials/application-secrets.service.js +1 -1
- package/dist/src/services/credentials/application-secrets.service.js.map +1 -1
- package/dist/src/services/credentials/provider-env-vars.utils.d.ts.map +1 -1
- package/dist/src/services/credentials/provider-env-vars.utils.js +3 -1
- package/dist/src/services/credentials/provider-env-vars.utils.js.map +1 -1
- package/dist/src/services/credentials/secrets-writer.service.d.ts +11 -2
- package/dist/src/services/credentials/secrets-writer.service.d.ts.map +1 -1
- package/dist/src/services/credentials/secrets-writer.service.js +12 -3
- package/dist/src/services/credentials/secrets-writer.service.js.map +1 -1
- package/dist/src/services/deployment/ci-deploy-generator.service.d.ts.map +1 -1
- package/dist/src/services/deployment/ci-deploy-generator.service.js +3 -3
- package/dist/src/services/deployment/ci-deploy-generator.service.js.map +1 -1
- package/dist/src/services/deployment/docker/docker-compose-generator.service.d.ts +12 -3
- package/dist/src/services/deployment/docker/docker-compose-generator.service.d.ts.map +1 -1
- package/dist/src/services/deployment/docker/docker-compose-generator.service.js +40 -22
- package/dist/src/services/deployment/docker/docker-compose-generator.service.js.map +1 -1
- package/dist/src/services/deployment/framework-pod-network-membership.d.ts +6 -0
- package/dist/src/services/deployment/framework-pod-network-membership.d.ts.map +1 -1
- package/dist/src/services/deployment/framework-pod-network-membership.js +17 -3
- package/dist/src/services/deployment/framework-pod-network-membership.js.map +1 -1
- package/dist/src/services/deployment/k8s/k8s-manifest-generator.service.d.ts +4 -1
- package/dist/src/services/deployment/k8s/k8s-manifest-generator.service.d.ts.map +1 -1
- package/dist/src/services/deployment/k8s/k8s-manifest-generator.service.js +17 -7
- package/dist/src/services/deployment/k8s/k8s-manifest-generator.service.js.map +1 -1
- package/dist/src/services/deployment/k8s/k8s-manifest.schemas.d.ts +7 -0
- package/dist/src/services/deployment/k8s/k8s-manifest.schemas.d.ts.map +1 -1
- package/dist/src/services/deployment/k8s/k8s-manifest.schemas.js.map +1 -1
- package/dist/src/services/deployment/k8s/k8s-secrets-generator.service.d.ts.map +1 -1
- package/dist/src/services/deployment/k8s/k8s-secrets-generator.service.js +15 -9
- package/dist/src/services/deployment/k8s/k8s-secrets-generator.service.js.map +1 -1
- package/dist/src/services/deployment/k8s/kind-pod-host-gateway.d.ts +43 -0
- package/dist/src/services/deployment/k8s/kind-pod-host-gateway.d.ts.map +1 -0
- package/dist/src/services/deployment/k8s/kind-pod-host-gateway.js +12 -0
- package/dist/src/services/deployment/k8s/kind-pod-host-gateway.js.map +1 -0
- package/dist/src/services/deployment/k8s/off-cluster-backing-services.d.ts +3 -1
- package/dist/src/services/deployment/k8s/off-cluster-backing-services.d.ts.map +1 -1
- package/dist/src/services/deployment/k8s/off-cluster-backing-services.js.map +1 -1
- package/dist/src/services/deployment/local-dev-late-workspace-members.service.d.ts +163 -0
- package/dist/src/services/deployment/local-dev-late-workspace-members.service.d.ts.map +1 -0
- package/dist/src/services/deployment/local-dev-late-workspace-members.service.js +356 -0
- package/dist/src/services/deployment/local-dev-late-workspace-members.service.js.map +1 -0
- package/dist/src/services/environment/authored-infra-config.utils.d.ts +13 -3
- package/dist/src/services/environment/authored-infra-config.utils.d.ts.map +1 -1
- package/dist/src/services/environment/authored-infra-config.utils.js +24 -4
- package/dist/src/services/environment/authored-infra-config.utils.js.map +1 -1
- package/dist/src/services/environment/container-host-gateway-listen-host.d.ts +6 -0
- package/dist/src/services/environment/container-host-gateway-listen-host.d.ts.map +1 -1
- package/dist/src/services/environment/container-host-gateway-listen-host.js +6 -0
- package/dist/src/services/environment/container-host-gateway-listen-host.js.map +1 -1
- package/dist/src/services/environment/env-configuration-generator.service.d.ts +12 -0
- package/dist/src/services/environment/env-configuration-generator.service.d.ts.map +1 -1
- package/dist/src/services/environment/env-configuration-generator.service.js +37 -5
- package/dist/src/services/environment/env-configuration-generator.service.js.map +1 -1
- package/dist/src/services/environment/env-vars-builder.service.d.ts +2 -1
- package/dist/src/services/environment/env-vars-builder.service.d.ts.map +1 -1
- package/dist/src/services/environment/env-vars-builder.service.js +47 -32
- package/dist/src/services/environment/env-vars-builder.service.js.map +1 -1
- package/dist/src/services/environment/environment-lifecycle.service.d.ts +7 -4
- package/dist/src/services/environment/environment-lifecycle.service.d.ts.map +1 -1
- package/dist/src/services/environment/environment-lifecycle.service.js +14 -18
- package/dist/src/services/environment/environment-lifecycle.service.js.map +1 -1
- package/dist/src/services/environment/environment-setup.service.d.ts.map +1 -1
- package/dist/src/services/environment/environment-setup.service.js +17 -6
- package/dist/src/services/environment/environment-setup.service.js.map +1 -1
- package/dist/src/services/environment/environment.service.d.ts +4 -3
- package/dist/src/services/environment/environment.service.d.ts.map +1 -1
- package/dist/src/services/environment/environment.service.js +0 -1
- package/dist/src/services/environment/environment.service.js.map +1 -1
- package/dist/src/services/framework/framework-docker-publish.service.d.ts +55 -15
- package/dist/src/services/framework/framework-docker-publish.service.d.ts.map +1 -1
- package/dist/src/services/framework/framework-docker-publish.service.js +115 -25
- package/dist/src/services/framework/framework-docker-publish.service.js.map +1 -1
- package/dist/src/services/framework/package-install.service.d.ts +7 -0
- package/dist/src/services/framework/package-install.service.d.ts.map +1 -1
- package/dist/src/services/framework/package-install.service.js +8 -1
- package/dist/src/services/framework/package-install.service.js.map +1 -1
- package/dist/src/services/registry/application-provider-connection.service.d.ts +16 -1
- package/dist/src/services/registry/application-provider-connection.service.d.ts.map +1 -1
- package/dist/src/services/registry/application-provider-connection.service.js +23 -0
- package/dist/src/services/registry/application-provider-connection.service.js.map +1 -1
- package/dist/src/services/registry/provider-grant-transfer.service.d.ts +48 -0
- package/dist/src/services/registry/provider-grant-transfer.service.d.ts.map +1 -0
- package/dist/src/services/registry/provider-grant-transfer.service.js +144 -0
- package/dist/src/services/registry/provider-grant-transfer.service.js.map +1 -0
- package/dist/src/services/registry/provider-module-scaffold.service.d.ts.map +1 -1
- package/dist/src/services/registry/provider-module-scaffold.service.js +10 -3
- package/dist/src/services/registry/provider-module-scaffold.service.js.map +1 -1
- package/dist/src/services/security/csp-sync.service.d.ts.map +1 -1
- package/dist/src/services/security/csp-sync.service.js +21 -2
- package/dist/src/services/security/csp-sync.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +19 -19
- package/templates/infra/docker-compose/docker-compose.wildo-platform.yml.hbs +16 -7
- package/templates/infra/k8s/platform/platform-crontabs-batches-manager/deployment.yaml.hbs +13 -0
- package/templates/saas/i18n/email/system/remote-agent-task-updated/labels.en.ts +11 -0
- package/templates/saas/i18n/email/system/remote-agent-task-updated/template.tsx +56 -0
- package/templates/saas/i18n/engine/components/APP_LAYOUTS_AGENT_ACTIVITY_SETTINGS.en.ts +61 -0
- package/templates/saas/i18n/engine/components/APP_LAYOUTS_AGENT_ACTIVITY_SETTINGS.fr.ts +61 -0
- package/templates/saas/scenarios/add-technical-doc/files/technical-doc/docusaurus.config.ts.hbs +5 -4
- package/templates/saas/scenarios/add-technical-doc/files/technical-doc/package.json.hbs +1 -1
- package/templates/saas/scenarios/add-technical-doc/files/technical-doc/scripts/substitute-api-origin.mjs +97 -32
- package/templates/saas/scenarios/add-technical-doc/files/technical-doc/src/plugins/api-reference-pages.ts +7 -6
- package/templates/saas/skeleton/.wildo-saas/wildo-dev-companion/scripts/dev-supervised.sh +18 -4
- package/templates/saas/skeleton/frontend/nginx-config/default.conf.hbs +1 -1
- package/templates/saas/skeleton/frontend/src/generated/csp.generated.json.hbs +4 -4
- package/templates/saas/skeleton/infrastructure/local/wildo.infra.local.config.ts.hbs +2 -0
- package/wildo-framework.info.json +1 -1
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, utimesSync, writeFileSync } from 'fs';
|
|
2
|
+
import { join, resolve } from 'path';
|
|
3
|
+
import { WorkspaceScope, loadSaasConfig } from '@wildo-ai/platform-config-lib';
|
|
4
|
+
import { AppFrontendType } from '@wildo-ai/saas-models';
|
|
5
|
+
import { BaseCommand } from '../../kernel/base-command.js';
|
|
6
|
+
import { CommandCategory } from '../../kernel/types.js';
|
|
7
|
+
import { ErrorUtils } from '../../infrastructure/errors/error.utils.js';
|
|
8
|
+
import { regenerateEnvFiles, runtimeSignalFiles } from '../../services/credentials/application-secrets.service.js';
|
|
9
|
+
import { buildTunnelIngressYaml, cloudflaredReadiness, credentialsFileOf, ensureNamedTunnel, machineTunnelDirectory, processIsTunnel, readApplicationTunnelState, readMachineTunnelState, removeApplicationTunnelState, routeHostname, systemCloudflaredRunner, tunnelIdOfCredentialsFile, waitForTunnelConnection, waitForTunnelExit, writeApplicationTunnelState, writeMachineTunnelState, } from '../../services/application/local-tunnel.service.js';
|
|
10
|
+
/** The verbs of `wildo local tunnel`. */
|
|
11
|
+
export var LocalTunnelAction;
|
|
12
|
+
(function (LocalTunnelAction) {
|
|
13
|
+
LocalTunnelAction["UP"] = "up";
|
|
14
|
+
LocalTunnelAction["DOWN"] = "down";
|
|
15
|
+
LocalTunnelAction["STATUS"] = "status";
|
|
16
|
+
})(LocalTunnelAction || (LocalTunnelAction = {}));
|
|
17
|
+
export const systemLocalTunnelEnvironment = {
|
|
18
|
+
runner: systemCloudflaredRunner,
|
|
19
|
+
directory: machineTunnelDirectory(),
|
|
20
|
+
isTunnel: processIsTunnel,
|
|
21
|
+
cloudflaredHome: undefined,
|
|
22
|
+
credentialsExist: existsSync,
|
|
23
|
+
waitForConnection: (logPath, pid, configPath) => waitForTunnelConnection(logPath, pid, configPath),
|
|
24
|
+
waitForExit: (pid, configPath) => waitForTunnelExit(pid, configPath),
|
|
25
|
+
loadConfig: async (appRoot) => await loadSaasConfig(join(appRoot, 'wildo.saas.config.ts')),
|
|
26
|
+
regenerate: regenerateEnvFiles,
|
|
27
|
+
async signal(appRoot, runtimes) {
|
|
28
|
+
const now = new Date();
|
|
29
|
+
const signalled = [];
|
|
30
|
+
for (const [folder, file] of await runtimeSignalFiles(appRoot, runtimes)) {
|
|
31
|
+
utimesSync(file, now, now);
|
|
32
|
+
signalled.push(folder);
|
|
33
|
+
}
|
|
34
|
+
return signalled;
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
/** The application's backend port and its interactive frontend, from its own `wildo.saas.config.ts`. */
|
|
38
|
+
export function resolveApplicationTargets(config, frontendFlag) {
|
|
39
|
+
const services = Object.values(config.services ?? {});
|
|
40
|
+
const backends = services.filter((service) => service.frontendType === undefined && typeof service.defaultPort === 'number');
|
|
41
|
+
if (backends.length !== 1)
|
|
42
|
+
throw new Error(`Expected one backend service with a defaultPort, found ${backends.length}.`);
|
|
43
|
+
const interactive = services.filter((service) => service.frontendType === AppFrontendType.SAAS_APP && service.serviceName);
|
|
44
|
+
const frontend = frontendFlag
|
|
45
|
+
? interactive.find((service) => service.serviceName === frontendFlag)
|
|
46
|
+
: interactive.length === 1 ? interactive[0] : undefined;
|
|
47
|
+
if (!frontend?.serviceName) {
|
|
48
|
+
throw new Error(frontendFlag
|
|
49
|
+
? `No interactive frontend service is named '${frontendFlag}'.`
|
|
50
|
+
: `This application has ${interactive.length} interactive frontends: name the one whose public origin follows the tunnel with --frontend (it must be the backend's default frontend).`);
|
|
51
|
+
}
|
|
52
|
+
return { backendPort: backends[0].defaultPort, frontendServiceName: frontend.serviceName };
|
|
53
|
+
}
|
|
54
|
+
/** `host=url` pairs, each a local service. */
|
|
55
|
+
export function parseTunnelExtras(values) {
|
|
56
|
+
return values.map((value) => {
|
|
57
|
+
const [hostname, service] = value.split('=', 2);
|
|
58
|
+
if (!hostname || !service || !/^http:\/\/127\.0\.0\.1:\d+$/.test(service)) {
|
|
59
|
+
throw new Error(`--extra takes host=http://127.0.0.1:<port>, got '${value}'.`);
|
|
60
|
+
}
|
|
61
|
+
return { hostname, service };
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* `wildo local tunnel up | down | status` — give this application a public HTTPS origin through this machine's
|
|
66
|
+
* locally-managed Cloudflare tunnel, while it runs (#3907).
|
|
67
|
+
*
|
|
68
|
+
* - `up --hostname <app>-<machine>.wildo.ai [--tunnel <name>] [--frontend <service>] [--extra host=http://127.0.0.1:<port>]`:
|
|
69
|
+
* ensures the named tunnel (created on the first use with this machine's `cloudflared tunnel login`), routes the
|
|
70
|
+
* hostname to it (refusing a hostname whose record points elsewhere), writes the machine's ingress, (re)starts the ONE
|
|
71
|
+
* `cloudflared` process and waits for a registered connection, and only then records the state, regenerates the env
|
|
72
|
+
* files and restarts the backend, minions and workers through their supervisors. The companion is not restarted: its
|
|
73
|
+
* endpoints never follow the tunnel.
|
|
74
|
+
* - `down`: removes this application from the machine's tunnel, stops `cloudflared` when nothing is left (otherwise
|
|
75
|
+
* restarts it with the rest), regenerates and restarts the same runtimes, so the stack is back on localhost.
|
|
76
|
+
* - `status`: the application's and the machine's state, and whether the process is the live tunnel.
|
|
77
|
+
*
|
|
78
|
+
* When the recorded process is not the live tunnel (a crash, a reboot), `up` starts from this application alone: an
|
|
79
|
+
* entry another application left behind is never revived by someone else's `up` (#3907 review F3).
|
|
80
|
+
*
|
|
81
|
+
* Fail closed: only the protocol paths are forwarded (`TUNNEL_FORWARDED_API_PATHS`); everything else answers 404. Nothing
|
|
82
|
+
* here prints a credential. Exit codes: 0 done, 1 refused or failed.
|
|
83
|
+
*/
|
|
84
|
+
export default class LocalTunnelCommand extends BaseCommand {
|
|
85
|
+
meta = {
|
|
86
|
+
name: 'local tunnel',
|
|
87
|
+
description: 'Give this application a public HTTPS origin through this machine\'s Cloudflare tunnel (up | down | status)',
|
|
88
|
+
category: CommandCategory.Local,
|
|
89
|
+
minimumScope: WorkspaceScope.SAAS_APP,
|
|
90
|
+
args: [{ name: 'action', description: 'up | down | status', required: true }],
|
|
91
|
+
flags: {
|
|
92
|
+
hostname: { type: 'string', description: 'The application\'s public hostname, e.g. todos-paul.wildo.ai (remembered after the first up)', default: undefined },
|
|
93
|
+
tunnel: { type: 'string', description: 'The machine\'s named tunnel (remembered while it runs)', default: undefined },
|
|
94
|
+
frontend: { type: 'string', description: 'The interactive frontend whose public origin follows the tunnel (needed when there are several)', default: undefined },
|
|
95
|
+
extra: { type: 'string[]', description: 'Another hostname the tunnel serves while it runs: host=http://127.0.0.1:<port> (a test receiver)', default: undefined },
|
|
96
|
+
env: { type: 'string', description: 'The environment whose env files are regenerated', default: 'local' },
|
|
97
|
+
'credentials-file': {
|
|
98
|
+
type: 'string',
|
|
99
|
+
description: 'Run an existing tunnel from its credentials file, on a machine with no Cloudflare login (the QA VM). Its hostnames must already be routed by the machine that created it.',
|
|
100
|
+
default: undefined,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
/** Overridable for tests. */
|
|
105
|
+
environment = systemLocalTunnelEnvironment;
|
|
106
|
+
async run(ctx) {
|
|
107
|
+
try {
|
|
108
|
+
const appRoot = ctx.cliContext.resolvedHomes.app.declarationRoot;
|
|
109
|
+
if (!appRoot)
|
|
110
|
+
throw new Error('Run `wildo local tunnel` from an application root (a directory with wildo.saas.config.ts).');
|
|
111
|
+
const action = ctx.args.action;
|
|
112
|
+
switch (action) {
|
|
113
|
+
case LocalTunnelAction.UP: return await this.up(ctx, appRoot);
|
|
114
|
+
case LocalTunnelAction.DOWN: return await this.down(ctx, appRoot);
|
|
115
|
+
case LocalTunnelAction.STATUS: return this.status(ctx, appRoot);
|
|
116
|
+
default: throw new Error(`Unknown action '${action ?? ''}': use up, down or status.`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
ctx.log.error(ErrorUtils.extractErrorMessage(error));
|
|
121
|
+
return { success: false, exitCode: 1 };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** The machine state, or `null` when its process is not the live tunnel (its entries are then not trusted). */
|
|
125
|
+
liveMachine() {
|
|
126
|
+
const machine = readMachineTunnelState(this.environment.directory);
|
|
127
|
+
return machine && this.environment.isTunnel(machine.pid, machine.configPath) ? machine : null;
|
|
128
|
+
}
|
|
129
|
+
async up(ctx, appRoot) {
|
|
130
|
+
// #3907 item 3: a machine with no Cloudflare login (the QA VM) is GIVEN the tunnel's credentials file. It cannot ask
|
|
131
|
+
// the account for the tunnel nor route a hostname, so both are the creating machine's job, done once; this machine
|
|
132
|
+
// only runs the tunnel. cloudflared needs no login for that: the credentials file names the tunnel (measured
|
|
133
|
+
// 2026-11-17, by id and by name, with an empty home).
|
|
134
|
+
const givenCredentials = ctx.flags['credentials-file'] ?? readMachineTunnelState(this.environment.directory)?.givenCredentialsFile;
|
|
135
|
+
if (!givenCredentials) {
|
|
136
|
+
const notReady = cloudflaredReadiness(this.environment.cloudflaredHome);
|
|
137
|
+
if (notReady)
|
|
138
|
+
throw new Error(notReady);
|
|
139
|
+
}
|
|
140
|
+
const saasConfig = await this.environment.loadConfig(appRoot);
|
|
141
|
+
const previous = readApplicationTunnelState(appRoot);
|
|
142
|
+
const live = this.liveMachine();
|
|
143
|
+
const hostname = ctx.flags.hostname ?? previous?.hostname;
|
|
144
|
+
const tunnelName = ctx.flags.tunnel ?? live?.tunnelName ?? previous?.tunnelName;
|
|
145
|
+
if (!hostname)
|
|
146
|
+
throw new Error('Name the application\'s public hostname with --hostname (e.g. todos-paul.wildo.ai).');
|
|
147
|
+
if (!tunnelName)
|
|
148
|
+
throw new Error('Name this machine\'s tunnel with --tunnel (e.g. wildo-paul).');
|
|
149
|
+
if (live && live.tunnelName !== tunnelName) {
|
|
150
|
+
throw new Error(`This machine's tunnel '${live.tunnelName}' is running for ${Object.values(live.applications).map((app) => app.hostname).join(', ')}; one machine runs one tunnel. Use it, or bring those applications down first.`);
|
|
151
|
+
}
|
|
152
|
+
const { backendPort, frontendServiceName } = resolveApplicationTargets(saasConfig, ctx.flags.frontend);
|
|
153
|
+
const extras = [...(live?.extras ?? []), ...parseTunnelExtras(ctx.flags.extra ?? [])]
|
|
154
|
+
.filter((extra, index, all) => all.findIndex((other) => other.hostname === extra.hostname) === index);
|
|
155
|
+
let credentialsFile;
|
|
156
|
+
if (givenCredentials) {
|
|
157
|
+
credentialsFile = resolve(givenCredentials);
|
|
158
|
+
if (!this.environment.credentialsExist(credentialsFile))
|
|
159
|
+
throw new Error(`No credentials file at ${credentialsFile}.`);
|
|
160
|
+
const id = tunnelIdOfCredentialsFile(credentialsFile);
|
|
161
|
+
ctx.log.info(` Running tunnel ${id} from its credentials file. Its hostnames are routed by the machine that created it; this one does not route ${[hostname, ...extras.map((extra) => extra.hostname)].join(', ')}.`);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
const { id } = await ensureNamedTunnel(this.environment.runner, tunnelName);
|
|
165
|
+
credentialsFile = credentialsFileOf(id, this.environment.cloudflaredHome);
|
|
166
|
+
if (!this.environment.credentialsExist(credentialsFile)) {
|
|
167
|
+
throw new Error(`The tunnel '${tunnelName}' has no credentials file on this machine (${credentialsFile}): it was created elsewhere. Pass it with --credentials-file, or use a tunnel this machine created.`);
|
|
168
|
+
}
|
|
169
|
+
await routeHostname(this.environment.runner, tunnelName, hostname);
|
|
170
|
+
for (const extra of extras)
|
|
171
|
+
await routeHostname(this.environment.runner, tunnelName, extra.hostname);
|
|
172
|
+
}
|
|
173
|
+
const applications = { ...(live?.applications ?? {}), [appRoot]: { hostname, backendPort } };
|
|
174
|
+
const next = await this.restart(live, { tunnelName, credentialsFile, applications, extras, givenCredentialsFile: givenCredentials ? credentialsFile : undefined });
|
|
175
|
+
writeMachineTunnelState(next, this.environment.directory);
|
|
176
|
+
writeApplicationTunnelState(appRoot, {
|
|
177
|
+
schemaVersion: 1, tunnelName, hostname, publicOrigin: `https://${hostname}`, frontendServiceName, backendPort,
|
|
178
|
+
});
|
|
179
|
+
ctx.log.success(` The tunnel serves https://${hostname} (pid ${next.pid}); its protocol paths reach :${backendPort}, everything else answers 404.`);
|
|
180
|
+
await this.applyToRuntimes(ctx, appRoot, saasConfig);
|
|
181
|
+
return { success: true };
|
|
182
|
+
}
|
|
183
|
+
async down(ctx, appRoot) {
|
|
184
|
+
const saasConfig = await this.environment.loadConfig(appRoot);
|
|
185
|
+
const recorded = readMachineTunnelState(this.environment.directory);
|
|
186
|
+
const live = this.liveMachine();
|
|
187
|
+
removeApplicationTunnelState(appRoot);
|
|
188
|
+
if (recorded) {
|
|
189
|
+
const { [appRoot]: _removed, ...applications } = recorded.applications;
|
|
190
|
+
if (!live || Object.keys(applications).length === 0) {
|
|
191
|
+
if (live?.pid) {
|
|
192
|
+
this.environment.runner.stop(live.pid);
|
|
193
|
+
if (!await this.environment.waitForExit(live.pid, live.configPath)) {
|
|
194
|
+
// Keep the pid on record: a process still forwarding the protocol paths must stay visible to `status`.
|
|
195
|
+
writeMachineTunnelState({ ...recorded, applications: {}, extras: [] }, this.environment.directory);
|
|
196
|
+
ctx.log.warn(` The tunnel process (pid ${live.pid}) did not exit; it may still forward. Stop it yourself, then run \`wildo local tunnel status\`.`);
|
|
197
|
+
await this.applyToRuntimes(ctx, appRoot, saasConfig);
|
|
198
|
+
return { success: false, exitCode: 1 };
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Nothing left: no application, no extras, no process. The next `up` starts clean.
|
|
202
|
+
writeMachineTunnelState({ ...recorded, pid: null, applications: {}, extras: [] }, this.environment.directory);
|
|
203
|
+
ctx.log.success(' The tunnel is stopped.');
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const credentialsFile = live.givenCredentialsFile
|
|
207
|
+
?? credentialsFileOf((await ensureNamedTunnel(this.environment.runner, live.tunnelName)).id, this.environment.cloudflaredHome);
|
|
208
|
+
writeMachineTunnelState(await this.restart(live, { tunnelName: live.tunnelName, credentialsFile, applications, extras: live.extras, givenCredentialsFile: live.givenCredentialsFile }), this.environment.directory);
|
|
209
|
+
ctx.log.success(' This application left the tunnel; the others still use it.');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
await this.applyToRuntimes(ctx, appRoot, saasConfig);
|
|
213
|
+
return { success: true };
|
|
214
|
+
}
|
|
215
|
+
status(ctx, appRoot) {
|
|
216
|
+
const state = readApplicationTunnelState(appRoot);
|
|
217
|
+
const machine = readMachineTunnelState(this.environment.directory);
|
|
218
|
+
const live = machine !== null && this.environment.isTunnel(machine.pid, machine.configPath);
|
|
219
|
+
if (!state)
|
|
220
|
+
ctx.log.info(' This application has no tunnel: its public origin is local.');
|
|
221
|
+
else
|
|
222
|
+
ctx.log.info(` This application's public origin: ${state.publicOrigin} (frontend ${state.frontendServiceName}, backend :${state.backendPort}).`);
|
|
223
|
+
if (machine) {
|
|
224
|
+
ctx.log.info(` Machine tunnel '${machine.tunnelName}': ${live ? `running (pid ${machine.pid})` : 'not running'}, serving ${Object.values(machine.applications).map((app) => app.hostname).join(', ') || 'no application'}${machine.extras.length ? ` and ${machine.extras.map((extra) => extra.hostname).join(', ')}` : ''}.`);
|
|
225
|
+
}
|
|
226
|
+
if (state && !live)
|
|
227
|
+
ctx.log.warn(' The state names a tunnel whose process is not running: env generation ignores it. Run `wildo local tunnel up` or `down`.');
|
|
228
|
+
return { success: true };
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Write the ingress and (re)start the machine's one `cloudflared` process: the old one is stopped and has EXITED before
|
|
232
|
+
* the new one starts, so two connectors with different ingress never serve at once (review F12), and the new one has
|
|
233
|
+
* registered a connection before anything is recorded (review F5).
|
|
234
|
+
*/
|
|
235
|
+
async restart(live, input) {
|
|
236
|
+
const configPath = join(this.environment.directory, `${input.tunnelName}.yml`);
|
|
237
|
+
const logPath = join(this.environment.directory, 'cloudflared.log');
|
|
238
|
+
const yaml = buildTunnelIngressYaml({ tunnelName: input.tunnelName, credentialsFile: input.credentialsFile, applications: Object.values(input.applications), extras: input.extras });
|
|
239
|
+
if (live?.pid) {
|
|
240
|
+
this.environment.runner.stop(live.pid);
|
|
241
|
+
if (!await this.environment.waitForExit(live.pid, live.configPath)) {
|
|
242
|
+
throw new Error(`The running tunnel (pid ${live.pid}) did not exit; nothing was changed. Stop it, then run this again.`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
mkdirSync(this.environment.directory, { recursive: true });
|
|
246
|
+
writeFileSync(configPath, yaml);
|
|
247
|
+
const pid = this.environment.runner.startDetached(['tunnel', '--no-autoupdate', '--config', configPath, 'run', input.tunnelName], logPath);
|
|
248
|
+
if (!await this.environment.waitForConnection(logPath, pid, configPath)) {
|
|
249
|
+
this.environment.runner.stop(pid);
|
|
250
|
+
const others = Object.entries(input.applications).filter(([root]) => live?.applications[root]).map(([root, app]) => `${app.hostname} (${root})`);
|
|
251
|
+
throw new Error(`cloudflared registered no connection (see ${logPath}); nothing was recorded and this application's public origin stays local.`
|
|
252
|
+
+ (others.length > 0 ? ` The tunnel these applications used is now stopped, and their backends advertise it until they regenerate: ${others.join(', ')}. Run \`wildo local tunnel up\` or \`down\` in each.` : ''));
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
schemaVersion: 1, tunnelName: input.tunnelName, pid, configPath, logPath, applications: input.applications, extras: [...input.extras],
|
|
256
|
+
...(input.givenCredentialsFile ? { givenCredentialsFile: input.givenCredentialsFile } : {}),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/** Regenerate the env files and restart every runtime that reads the public origin, never the companion. */
|
|
260
|
+
async applyToRuntimes(ctx, appRoot, config) {
|
|
261
|
+
const env = ctx.flags.env ?? 'local';
|
|
262
|
+
const regeneration = this.environment.regenerate(appRoot, env);
|
|
263
|
+
if (!regeneration.regenerated) {
|
|
264
|
+
ctx.log.warn(` The env files could not be regenerated, so the runtimes still advertise the previous public origin: run \`wildo config sync --domain env-files\`, then restart the backend.${regeneration.failure ? ` (${regeneration.failure})` : ''}`);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const runtimes = ['backend', ...Object.keys(config.minions ?? {}).map((key) => `minions.${key}`), ...Object.keys(config.workers ?? {}).map((key) => `workers.${key}`)];
|
|
268
|
+
const signalled = await this.environment.signal(appRoot, runtimes);
|
|
269
|
+
ctx.log.info(signalled.length > 0
|
|
270
|
+
? ` Restarted through their supervisors: ${signalled.join(', ')}.`
|
|
271
|
+
: ' No supervised runtime is running: the change takes effect at the next `wildo local dev`.');
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=tunnel.command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tunnel.command.js","sourceRoot":"","sources":["../../../../src/commands/local/tunnel.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,6DAA6D,CAAC;AACrH,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,0BAA0B,EAC1B,sBAAsB,EACtB,4BAA4B,EAC5B,aAAa,EACb,uBAAuB,EACvB,yBAAyB,EACzB,uBAAuB,EACvB,iBAAiB,EACjB,2BAA2B,EAC3B,uBAAuB,GAIxB,MAAM,sDAAsD,CAAC;AAE9D,yCAAyC;AACzC,MAAM,CAAN,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,8BAAS,CAAA;IACT,kCAAa,CAAA;IACb,sCAAiB,CAAA;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C,OAAO,EAAE,GAAG,CAAC,CAAC;QAC/D,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;YAC9B,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,gLAAgL,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACzP,OAAO;QACT,CAAC;QACD,MAAM,QAAQ,GAAG,CAAC,SAAS,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,GAAG,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,GAAG,EAAE,CAAC,CAAC,CAAC;QACvK,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACnE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC;YAC/B,CAAC,CAAC,0CAA0C,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YACnE,CAAC,CAAC,4FAA4F,CAAC,CAAC;IACpG,CAAC;CACF","sourcesContent":["import { existsSync, mkdirSync, utimesSync, writeFileSync } from 'fs';\nimport { join, resolve } from 'path';\nimport { WorkspaceScope, loadSaasConfig } from '@wildo-ai/platform-config-lib';\nimport { AppFrontendType } from '@wildo-ai/saas-models';\n\nimport { BaseCommand } from '~wildo-cli/kernel/base-command';\nimport { CommandCategory } from '~wildo-cli/kernel/types';\nimport type { CommandContext, CommandMeta, CommandResult } from '~wildo-cli/kernel/types';\nimport { ErrorUtils } from '~wildo-cli/infrastructure/errors/error.utils';\nimport { regenerateEnvFiles, runtimeSignalFiles } from '~wildo-cli/services/credentials/application-secrets.service';\nimport {\n buildTunnelIngressYaml,\n cloudflaredReadiness,\n credentialsFileOf,\n ensureNamedTunnel,\n machineTunnelDirectory,\n processIsTunnel,\n readApplicationTunnelState,\n readMachineTunnelState,\n removeApplicationTunnelState,\n routeHostname,\n systemCloudflaredRunner,\n tunnelIdOfCredentialsFile,\n waitForTunnelConnection,\n waitForTunnelExit,\n writeApplicationTunnelState,\n writeMachineTunnelState,\n type CloudflaredRunner,\n type MachineTunnelState,\n type TunnelExtraRoute,\n} from '~wildo-cli/services/application/local-tunnel.service';\n\n/** The verbs of `wildo local tunnel`. */\nexport enum LocalTunnelAction {\n UP = 'up',\n DOWN = 'down',\n STATUS = 'status',\n}\n\ninterface SaasServices {\n services?: Record<string, { path?: string; serviceName?: string; defaultPort?: number; frontendType?: string }>;\n minions?: Record<string, unknown>;\n workers?: Record<string, unknown>;\n}\n\n/** What the command reaches outside itself, injectable for tests. */\nexport interface LocalTunnelEnvironment {\n readonly runner: CloudflaredRunner;\n readonly directory: string;\n readonly isTunnel: typeof processIsTunnel;\n readonly cloudflaredHome: string | undefined;\n readonly credentialsExist: (path: string) => boolean;\n readonly waitForConnection: (logPath: string, pid: number, configPath: string) => Promise<boolean>;\n readonly waitForExit: (pid: number, configPath: string) => Promise<boolean>;\n readonly loadConfig: (appRoot: string) => Promise<SaasServices>;\n readonly regenerate: (appRoot: string, envName: string) => { readonly regenerated: boolean; readonly failure: string | null };\n readonly signal: (appRoot: string, runtimes: readonly string[]) => Promise<string[]>;\n}\n\nexport const systemLocalTunnelEnvironment: LocalTunnelEnvironment = {\n runner: systemCloudflaredRunner,\n directory: machineTunnelDirectory(),\n isTunnel: processIsTunnel,\n cloudflaredHome: undefined,\n credentialsExist: existsSync,\n waitForConnection: (logPath, pid, configPath) => waitForTunnelConnection(logPath, pid, configPath),\n waitForExit: (pid, configPath) => waitForTunnelExit(pid, configPath),\n loadConfig: async (appRoot) => await loadSaasConfig(join(appRoot, 'wildo.saas.config.ts')) as SaasServices,\n regenerate: regenerateEnvFiles,\n async signal(appRoot, runtimes) {\n const now = new Date();\n const signalled: string[] = [];\n for (const [folder, file] of await runtimeSignalFiles(appRoot, runtimes)) {\n utimesSync(file, now, now);\n signalled.push(folder);\n }\n return signalled;\n },\n};\n\n/** The application's backend port and its interactive frontend, from its own `wildo.saas.config.ts`. */\nexport function resolveApplicationTargets(config: SaasServices, frontendFlag: string | undefined): { backendPort: number; frontendServiceName: string } {\n const services = Object.values(config.services ?? {});\n const backends = services.filter((service) => service.frontendType === undefined && typeof service.defaultPort === 'number');\n if (backends.length !== 1) throw new Error(`Expected one backend service with a defaultPort, found ${backends.length}.`);\n const interactive = services.filter((service) => service.frontendType === AppFrontendType.SAAS_APP && service.serviceName);\n const frontend = frontendFlag\n ? interactive.find((service) => service.serviceName === frontendFlag)\n : interactive.length === 1 ? interactive[0] : undefined;\n if (!frontend?.serviceName) {\n throw new Error(frontendFlag\n ? `No interactive frontend service is named '${frontendFlag}'.`\n : `This application has ${interactive.length} interactive frontends: name the one whose public origin follows the tunnel with --frontend (it must be the backend's default frontend).`);\n }\n return { backendPort: backends[0]!.defaultPort!, frontendServiceName: frontend.serviceName };\n}\n\n/** `host=url` pairs, each a local service. */\nexport function parseTunnelExtras(values: readonly string[]): TunnelExtraRoute[] {\n return values.map((value) => {\n const [hostname, service] = value.split('=', 2) as [string, string | undefined];\n if (!hostname || !service || !/^http:\\/\\/127\\.0\\.0\\.1:\\d+$/.test(service)) {\n throw new Error(`--extra takes host=http://127.0.0.1:<port>, got '${value}'.`);\n }\n return { hostname, service };\n });\n}\n\n/**\n * `wildo local tunnel up | down | status` — give this application a public HTTPS origin through this machine's\n * locally-managed Cloudflare tunnel, while it runs (#3907).\n *\n * - `up --hostname <app>-<machine>.wildo.ai [--tunnel <name>] [--frontend <service>] [--extra host=http://127.0.0.1:<port>]`:\n * ensures the named tunnel (created on the first use with this machine's `cloudflared tunnel login`), routes the\n * hostname to it (refusing a hostname whose record points elsewhere), writes the machine's ingress, (re)starts the ONE\n * `cloudflared` process and waits for a registered connection, and only then records the state, regenerates the env\n * files and restarts the backend, minions and workers through their supervisors. The companion is not restarted: its\n * endpoints never follow the tunnel.\n * - `down`: removes this application from the machine's tunnel, stops `cloudflared` when nothing is left (otherwise\n * restarts it with the rest), regenerates and restarts the same runtimes, so the stack is back on localhost.\n * - `status`: the application's and the machine's state, and whether the process is the live tunnel.\n *\n * When the recorded process is not the live tunnel (a crash, a reboot), `up` starts from this application alone: an\n * entry another application left behind is never revived by someone else's `up` (#3907 review F3).\n *\n * Fail closed: only the protocol paths are forwarded (`TUNNEL_FORWARDED_API_PATHS`); everything else answers 404. Nothing\n * here prints a credential. Exit codes: 0 done, 1 refused or failed.\n */\nexport default class LocalTunnelCommand extends BaseCommand {\n readonly meta: CommandMeta = {\n name: 'local tunnel',\n description: 'Give this application a public HTTPS origin through this machine\\'s Cloudflare tunnel (up | down | status)',\n category: CommandCategory.Local,\n minimumScope: WorkspaceScope.SAAS_APP,\n args: [{ name: 'action', description: 'up | down | status', required: true }],\n flags: {\n hostname: { type: 'string', description: 'The application\\'s public hostname, e.g. todos-paul.wildo.ai (remembered after the first up)', default: undefined },\n tunnel: { type: 'string', description: 'The machine\\'s named tunnel (remembered while it runs)', default: undefined },\n frontend: { type: 'string', description: 'The interactive frontend whose public origin follows the tunnel (needed when there are several)', default: undefined },\n extra: { type: 'string[]', description: 'Another hostname the tunnel serves while it runs: host=http://127.0.0.1:<port> (a test receiver)', default: undefined },\n env: { type: 'string', description: 'The environment whose env files are regenerated', default: 'local' },\n 'credentials-file': {\n type: 'string',\n description: 'Run an existing tunnel from its credentials file, on a machine with no Cloudflare login (the QA VM). Its hostnames must already be routed by the machine that created it.',\n default: undefined,\n },\n },\n };\n\n /** Overridable for tests. */\n protected environment: LocalTunnelEnvironment = systemLocalTunnelEnvironment;\n\n async run(ctx: CommandContext): Promise<CommandResult> {\n try {\n const appRoot = ctx.cliContext.resolvedHomes.app.declarationRoot;\n if (!appRoot) throw new Error('Run `wildo local tunnel` from an application root (a directory with wildo.saas.config.ts).');\n const action = ctx.args.action as LocalTunnelAction | undefined;\n switch (action) {\n case LocalTunnelAction.UP: return await this.up(ctx, appRoot);\n case LocalTunnelAction.DOWN: return await this.down(ctx, appRoot);\n case LocalTunnelAction.STATUS: return this.status(ctx, appRoot);\n default: throw new Error(`Unknown action '${action ?? ''}': use up, down or status.`);\n }\n } catch (error) {\n ctx.log.error(ErrorUtils.extractErrorMessage(error));\n return { success: false, exitCode: 1 };\n }\n }\n\n /** The machine state, or `null` when its process is not the live tunnel (its entries are then not trusted). */\n private liveMachine(): MachineTunnelState | null {\n const machine = readMachineTunnelState(this.environment.directory);\n return machine && this.environment.isTunnel(machine.pid, machine.configPath) ? machine : null;\n }\n\n private async up(ctx: CommandContext, appRoot: string): Promise<CommandResult> {\n // #3907 item 3: a machine with no Cloudflare login (the QA VM) is GIVEN the tunnel's credentials file. It cannot ask\n // the account for the tunnel nor route a hostname, so both are the creating machine's job, done once; this machine\n // only runs the tunnel. cloudflared needs no login for that: the credentials file names the tunnel (measured\n // 2026-11-17, by id and by name, with an empty home).\n const givenCredentials = (ctx.flags['credentials-file'] as string | undefined) ?? readMachineTunnelState(this.environment.directory)?.givenCredentialsFile;\n if (!givenCredentials) {\n const notReady = cloudflaredReadiness(this.environment.cloudflaredHome);\n if (notReady) throw new Error(notReady);\n }\n const saasConfig = await this.environment.loadConfig(appRoot);\n const previous = readApplicationTunnelState(appRoot);\n const live = this.liveMachine();\n const hostname = (ctx.flags.hostname as string | undefined) ?? previous?.hostname;\n const tunnelName = (ctx.flags.tunnel as string | undefined) ?? live?.tunnelName ?? previous?.tunnelName;\n if (!hostname) throw new Error('Name the application\\'s public hostname with --hostname (e.g. todos-paul.wildo.ai).');\n if (!tunnelName) throw new Error('Name this machine\\'s tunnel with --tunnel (e.g. wildo-paul).');\n if (live && live.tunnelName !== tunnelName) {\n throw new Error(`This machine's tunnel '${live.tunnelName}' is running for ${Object.values(live.applications).map((app) => app.hostname).join(', ')}; one machine runs one tunnel. Use it, or bring those applications down first.`);\n }\n const { backendPort, frontendServiceName } = resolveApplicationTargets(saasConfig, ctx.flags.frontend as string | undefined);\n const extras = [...(live?.extras ?? []), ...parseTunnelExtras((ctx.flags.extra as string[] | undefined) ?? [])]\n .filter((extra, index, all) => all.findIndex((other) => other.hostname === extra.hostname) === index);\n\n let credentialsFile: string;\n if (givenCredentials) {\n credentialsFile = resolve(givenCredentials);\n if (!this.environment.credentialsExist(credentialsFile)) throw new Error(`No credentials file at ${credentialsFile}.`);\n const id = tunnelIdOfCredentialsFile(credentialsFile);\n ctx.log.info(` Running tunnel ${id} from its credentials file. Its hostnames are routed by the machine that created it; this one does not route ${[hostname, ...extras.map((extra) => extra.hostname)].join(', ')}.`);\n } else {\n const { id } = await ensureNamedTunnel(this.environment.runner, tunnelName);\n credentialsFile = credentialsFileOf(id, this.environment.cloudflaredHome);\n if (!this.environment.credentialsExist(credentialsFile)) {\n throw new Error(`The tunnel '${tunnelName}' has no credentials file on this machine (${credentialsFile}): it was created elsewhere. Pass it with --credentials-file, or use a tunnel this machine created.`);\n }\n await routeHostname(this.environment.runner, tunnelName, hostname);\n for (const extra of extras) await routeHostname(this.environment.runner, tunnelName, extra.hostname);\n }\n\n const applications = { ...(live?.applications ?? {}), [appRoot]: { hostname, backendPort } };\n const next = await this.restart(live, { tunnelName, credentialsFile, applications, extras, givenCredentialsFile: givenCredentials ? credentialsFile : undefined });\n writeMachineTunnelState(next, this.environment.directory);\n writeApplicationTunnelState(appRoot, {\n schemaVersion: 1, tunnelName, hostname, publicOrigin: `https://${hostname}`, frontendServiceName, backendPort,\n });\n ctx.log.success(` The tunnel serves https://${hostname} (pid ${next.pid}); its protocol paths reach :${backendPort}, everything else answers 404.`);\n await this.applyToRuntimes(ctx, appRoot, saasConfig);\n return { success: true };\n }\n\n private async down(ctx: CommandContext, appRoot: string): Promise<CommandResult> {\n const saasConfig = await this.environment.loadConfig(appRoot);\n const recorded = readMachineTunnelState(this.environment.directory);\n const live = this.liveMachine();\n removeApplicationTunnelState(appRoot);\n if (recorded) {\n const { [appRoot]: _removed, ...applications } = recorded.applications;\n if (!live || Object.keys(applications).length === 0) {\n if (live?.pid) {\n this.environment.runner.stop(live.pid);\n if (!await this.environment.waitForExit(live.pid, live.configPath)) {\n // Keep the pid on record: a process still forwarding the protocol paths must stay visible to `status`.\n writeMachineTunnelState({ ...recorded, applications: {}, extras: [] }, this.environment.directory);\n ctx.log.warn(` The tunnel process (pid ${live.pid}) did not exit; it may still forward. Stop it yourself, then run \\`wildo local tunnel status\\`.`);\n await this.applyToRuntimes(ctx, appRoot, saasConfig);\n return { success: false, exitCode: 1 };\n }\n }\n // Nothing left: no application, no extras, no process. The next `up` starts clean.\n writeMachineTunnelState({ ...recorded, pid: null, applications: {}, extras: [] }, this.environment.directory);\n ctx.log.success(' The tunnel is stopped.');\n } else {\n const credentialsFile = live.givenCredentialsFile\n ?? credentialsFileOf((await ensureNamedTunnel(this.environment.runner, live.tunnelName)).id, this.environment.cloudflaredHome);\n writeMachineTunnelState(await this.restart(live, { tunnelName: live.tunnelName, credentialsFile, applications, extras: live.extras, givenCredentialsFile: live.givenCredentialsFile }), this.environment.directory);\n ctx.log.success(' This application left the tunnel; the others still use it.');\n }\n }\n await this.applyToRuntimes(ctx, appRoot, saasConfig);\n return { success: true };\n }\n\n private status(ctx: CommandContext, appRoot: string): CommandResult {\n const state = readApplicationTunnelState(appRoot);\n const machine = readMachineTunnelState(this.environment.directory);\n const live = machine !== null && this.environment.isTunnel(machine.pid, machine.configPath);\n if (!state) ctx.log.info(' This application has no tunnel: its public origin is local.');\n else ctx.log.info(` This application's public origin: ${state.publicOrigin} (frontend ${state.frontendServiceName}, backend :${state.backendPort}).`);\n if (machine) {\n ctx.log.info(` Machine tunnel '${machine.tunnelName}': ${live ? `running (pid ${machine.pid})` : 'not running'}, serving ${Object.values(machine.applications).map((app) => app.hostname).join(', ') || 'no application'}${machine.extras.length ? ` and ${machine.extras.map((extra) => extra.hostname).join(', ')}` : ''}.`);\n }\n if (state && !live) ctx.log.warn(' The state names a tunnel whose process is not running: env generation ignores it. Run `wildo local tunnel up` or `down`.');\n return { success: true };\n }\n\n /**\n * Write the ingress and (re)start the machine's one `cloudflared` process: the old one is stopped and has EXITED before\n * the new one starts, so two connectors with different ingress never serve at once (review F12), and the new one has\n * registered a connection before anything is recorded (review F5).\n */\n private async restart(\n live: MachineTunnelState | null,\n input: { tunnelName: string; credentialsFile: string; applications: MachineTunnelState['applications']; extras: readonly TunnelExtraRoute[]; givenCredentialsFile?: string },\n ): Promise<MachineTunnelState> {\n const configPath = join(this.environment.directory, `${input.tunnelName}.yml`);\n const logPath = join(this.environment.directory, 'cloudflared.log');\n const yaml = buildTunnelIngressYaml({ tunnelName: input.tunnelName, credentialsFile: input.credentialsFile, applications: Object.values(input.applications), extras: input.extras });\n if (live?.pid) {\n this.environment.runner.stop(live.pid);\n if (!await this.environment.waitForExit(live.pid, live.configPath)) {\n throw new Error(`The running tunnel (pid ${live.pid}) did not exit; nothing was changed. Stop it, then run this again.`);\n }\n }\n mkdirSync(this.environment.directory, { recursive: true });\n writeFileSync(configPath, yaml);\n const pid = this.environment.runner.startDetached(['tunnel', '--no-autoupdate', '--config', configPath, 'run', input.tunnelName], logPath);\n if (!await this.environment.waitForConnection(logPath, pid, configPath)) {\n this.environment.runner.stop(pid);\n const others = Object.entries(input.applications).filter(([root]) => live?.applications[root]).map(([root, app]) => `${app.hostname} (${root})`);\n throw new Error(`cloudflared registered no connection (see ${logPath}); nothing was recorded and this application's public origin stays local.`\n + (others.length > 0 ? ` The tunnel these applications used is now stopped, and their backends advertise it until they regenerate: ${others.join(', ')}. Run \\`wildo local tunnel up\\` or \\`down\\` in each.` : ''));\n }\n return {\n schemaVersion: 1, tunnelName: input.tunnelName, pid, configPath, logPath, applications: input.applications, extras: [...input.extras],\n ...(input.givenCredentialsFile ? { givenCredentialsFile: input.givenCredentialsFile } : {}),\n };\n }\n\n /** Regenerate the env files and restart every runtime that reads the public origin, never the companion. */\n private async applyToRuntimes(ctx: CommandContext, appRoot: string, config: SaasServices): Promise<void> {\n const env = (ctx.flags.env as string | undefined) ?? 'local';\n const regeneration = this.environment.regenerate(appRoot, env);\n if (!regeneration.regenerated) {\n ctx.log.warn(` The env files could not be regenerated, so the runtimes still advertise the previous public origin: run \\`wildo config sync --domain env-files\\`, then restart the backend.${regeneration.failure ? ` (${regeneration.failure})` : ''}`);\n return;\n }\n const runtimes = ['backend', ...Object.keys(config.minions ?? {}).map((key) => `minions.${key}`), ...Object.keys(config.workers ?? {}).map((key) => `workers.${key}`)];\n const signalled = await this.environment.signal(appRoot, runtimes);\n ctx.log.info(signalled.length > 0\n ? ` Restarted through their supervisors: ${signalled.join(', ')}.`\n : ' No supervised runtime is running: the change takes effect at the next `wildo local dev`.');\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseCommand } from '../../kernel/base-command';
|
|
2
|
+
import type { CommandMeta, CommandContext, CommandResult } from '../../kernel/types';
|
|
3
|
+
/**
|
|
4
|
+
* Export one stored OAuth2 grant of the LOCAL running application in its portable form (grant seeding, development and
|
|
5
|
+
* test only), so another development or test stack can import it with `wildo providers grant import`.
|
|
6
|
+
*
|
|
7
|
+
* The application opens the sealed grant (only it holds the key), refuses unless it runs as `development` or `test`,
|
|
8
|
+
* admits only a super-administrator, and records `provider_grant_exported` by owner and connection, never the token.
|
|
9
|
+
* This command signs in as the local administrator, refuses an application that does not answer on this machine, and
|
|
10
|
+
* writes the document only where it was told.
|
|
11
|
+
*/
|
|
12
|
+
export default class ProvidersGrantExportCommand extends BaseCommand {
|
|
13
|
+
readonly meta: CommandMeta;
|
|
14
|
+
run(ctx: CommandContext): Promise<CommandResult>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=grant-export.command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grant-export.command.d.ts","sourceRoot":"","sources":["../../../../src/commands/providers/grant-export.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAG7D,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAkB,MAAM,yBAAyB,CAAC;AA6B1G;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,OAAO,2BAA4B,SAAQ,WAAW;IAClE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAUxB;IAEI,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;CAsCvD"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { BaseCommand } from '../../kernel/base-command.js';
|
|
2
|
+
import { CommandCategory } from '../../kernel/types.js';
|
|
3
|
+
import { ErrorUtils } from '../../infrastructure/errors/error.utils.js';
|
|
4
|
+
import { ApplicationConnectionRequestRefusedError, openApplicationConnectionSession, resolveApplicationApiTarget, } from '../../services/registry/application-provider-connection.service.js';
|
|
5
|
+
import { assertLocalGrantTransferTarget, describeGrantTransferOwner, grantTransferRefusalHint, parseGrantTransferOwner, writeGrantTransferDocument, } from '../../services/registry/provider-grant-transfer.service.js';
|
|
6
|
+
const FLAG_CONNECTION = 'connection';
|
|
7
|
+
const FLAG_OWNER = 'owner';
|
|
8
|
+
const FLAG_SLOT = 'slot';
|
|
9
|
+
const FLAG_OUT = 'out';
|
|
10
|
+
const FLAG_TO_TERMINAL = 'to-terminal';
|
|
11
|
+
const FLAGS = {
|
|
12
|
+
[FLAG_CONNECTION]: { type: 'string', description: 'The connection whose grant to export (`asana`).', required: true },
|
|
13
|
+
[FLAG_OWNER]: { type: 'string', description: 'Whose grant: `user:<email>`, `organization:<id or slug>` or `application`.', required: true },
|
|
14
|
+
[FLAG_SLOT]: { type: 'string', description: 'The credential slot, when the connection holds several for that owner.' },
|
|
15
|
+
[FLAG_OUT]: { type: 'string', description: 'Write the document to this file, created with mode 0600. `-` or absent: stdout, refused when stdout is a terminal.' },
|
|
16
|
+
[FLAG_TO_TERMINAL]: { type: 'boolean', description: 'Allow printing the document (which holds tokens) on a terminal.', default: false },
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Export one stored OAuth2 grant of the LOCAL running application in its portable form (grant seeding, development and
|
|
20
|
+
* test only), so another development or test stack can import it with `wildo providers grant import`.
|
|
21
|
+
*
|
|
22
|
+
* The application opens the sealed grant (only it holds the key), refuses unless it runs as `development` or `test`,
|
|
23
|
+
* admits only a super-administrator, and records `provider_grant_exported` by owner and connection, never the token.
|
|
24
|
+
* This command signs in as the local administrator, refuses an application that does not answer on this machine, and
|
|
25
|
+
* writes the document only where it was told.
|
|
26
|
+
*/
|
|
27
|
+
export default class ProvidersGrantExportCommand extends BaseCommand {
|
|
28
|
+
meta = {
|
|
29
|
+
name: 'providers grant export',
|
|
30
|
+
description: 'Development and test only: export one OAuth2 grant the local running application holds (a person\'s, an organization\'s or its own) '
|
|
31
|
+
+ 'as a portable document, so another local or QA stack can import it instead of repeating the vendor\'s consent. The document holds '
|
|
32
|
+
+ 'tokens: it is written to a 0600 file or piped, never printed on a terminal unless --to-terminal. Recorded as provider_grant_exported.',
|
|
33
|
+
category: CommandCategory.Core,
|
|
34
|
+
flags: FLAGS,
|
|
35
|
+
// The document on stdout must be the only thing there: the seed script parses it.
|
|
36
|
+
emitsDocumentOnStdout: (flags) => flags[FLAG_OUT] === undefined || flags[FLAG_OUT] === '-',
|
|
37
|
+
};
|
|
38
|
+
async run(ctx) {
|
|
39
|
+
let session;
|
|
40
|
+
try {
|
|
41
|
+
const owner = parseGrantTransferOwner(String(ctx.flags[FLAG_OWNER] ?? ''));
|
|
42
|
+
const connectionRef = String(ctx.flags[FLAG_CONNECTION] ?? '').trim();
|
|
43
|
+
if (connectionRef.length === 0)
|
|
44
|
+
throw new Error('Name the connection: --connection <ref>.');
|
|
45
|
+
const out = ctx.flags[FLAG_OUT];
|
|
46
|
+
const toTerminal = ctx.flags[FLAG_TO_TERMINAL] === true;
|
|
47
|
+
// Refused before signing in: a document that would land on the screen is not asked for.
|
|
48
|
+
if ((out === undefined || out === '-') && process.stdout.isTTY === true && !toTerminal) {
|
|
49
|
+
throw new Error('The grant document holds tokens and stdout is a terminal: pass --out <file> (created 0600), pipe the output, or --to-terminal.');
|
|
50
|
+
}
|
|
51
|
+
// Only the LOCAL stack of an application root: there is no --api-url here, by design.
|
|
52
|
+
if (!ctx.cliContext.resolvedHomes.app.declarationRoot)
|
|
53
|
+
throw new Error('Run it from the application root of a local stack (where wildo.saas.config.ts is): a grant moves only between local development stacks.');
|
|
54
|
+
// The fence BEFORE signing in: the local administrator's password goes nowhere but this machine.
|
|
55
|
+
assertLocalGrantTransferTarget((await resolveApplicationApiTarget(ctx.cliContext.resolvedHomes.app.declarationRoot)).apiBaseUrl);
|
|
56
|
+
session = await openApplicationConnectionSession({
|
|
57
|
+
appRoot: ctx.cliContext.resolvedHomes.app.declarationRoot ?? null,
|
|
58
|
+
frameworkRoot: ctx.cliContext.resolvedHomes.framework.repositoryRoot ?? null,
|
|
59
|
+
});
|
|
60
|
+
const secretSlug = ctx.flags[FLAG_SLOT];
|
|
61
|
+
const document = await session.exportGrant({ owner, connectionRef, ...(secretSlug === undefined ? {} : { secretSlug }) });
|
|
62
|
+
const where = writeGrantTransferDocument(document, { ...(out === undefined ? {} : { out }), stdoutIsTerminal: process.stdout.isTTY === true, toTerminal });
|
|
63
|
+
// On stderr, so a piped document stays the only thing on stdout.
|
|
64
|
+
process.stderr.write(`Exported ${describeGrantTransferOwner(owner)}'s '${document.connectionRef}' grant (slot ${document.secretSlug}, transfer ${document.transferId}) to ${where}. `
|
|
65
|
+
+ `${document.grant.refreshToken === undefined ? 'It carries no refresh token: it stops working when its access token expires.' : 'It shares its authorization with this stack: a disconnect on either side may end it on both.'}\n`);
|
|
66
|
+
return { success: true };
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const hint = error instanceof ApplicationConnectionRequestRefusedError ? grantTransferRefusalHint(error.code) : undefined;
|
|
70
|
+
ctx.log.error(`${ErrorUtils.extractErrorMessage(error)}${hint === undefined ? '' : ` ${hint}`}`);
|
|
71
|
+
return { success: false };
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
await session?.signOut();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=grant-export.command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grant-export.command.js","sourceRoot":"","sources":["../../../../src/commands/providers/grant-export.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAE1E,OAAO,EACL,wCAAwC,EACxC,gCAAgC,EAChC,2BAA2B,GAE5B,MAAM,sEAAsE,CAAC;AAC9E,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,8DAA8D,CAAC;AAEtE,MAAM,eAAe,GAAG,YAAY,CAAC;AACrC,MAAM,UAAU,GAAG,OAAO,CAAC;AAC3B,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,MAAM,QAAQ,GAAG,KAAK,CAAC;AACvB,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAEvC,MAAM,KAAK,GAAmC;IAC5C,CAAC,eAAe,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,iDAAiD,EAAE,QAAQ,EAAE,IAAI,EAAE;IACrH,CAAC,UAAU,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,4EAA4E,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC3I,CAAC,SAAS,CAAC,EAAE,EA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AAE,CAAC,CAAC;YAC3J,iEAAiE;YACjE,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,YAAY,0BAA0B,CAAC,KAAK,CAAC,OAAO,QAAQ,CAAC,aAAa,iBAAiB,QAAQ,CAAC,UAAU,cAAc,QAAQ,CAAC,UAAU,QAAQ,KAAK,IAAI;kBAC9J,GAAG,QAAQ,CAAC,KAAK,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,8EAA8E,CAAC,CAAC,CAAC,8FAA8F,IAAI,CACrO,CAAC;YACF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,GAAG,KAAK,YAAY,wCAAwC,CAAC,CAAC,CAAC,wBAAwB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAC1H,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,mBAAmB,CAAC,KAAK,CAAC,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;YACjG,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAC5B,CAAC;gBAAS,CAAC;YACT,MAAM,OAAO,EAAE,OAAO,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;CACF","sourcesContent":["import { BaseCommand } from '~wildo-cli/kernel/base-command';\nimport { CommandCategory } from '~wildo-cli/kernel/types';\nimport { ErrorUtils } from '~wildo-cli/infrastructure/errors/error.utils';\nimport type { CommandMeta, CommandContext, CommandResult, FlagDefinition } from '~wildo-cli/kernel/types';\nimport {\n ApplicationConnectionRequestRefusedError,\n openApplicationConnectionSession,\n resolveApplicationApiTarget,\n type ApplicationProviderConnectionClient,\n} from '~wildo-cli/services/registry/application-provider-connection.service';\nimport {\n assertLocalGrantTransferTarget,\n describeGrantTransferOwner,\n grantTransferRefusalHint,\n parseGrantTransferOwner,\n writeGrantTransferDocument,\n} from '~wildo-cli/services/registry/provider-grant-transfer.service';\n\nconst FLAG_CONNECTION = 'connection';\nconst FLAG_OWNER = 'owner';\nconst FLAG_SLOT = 'slot';\nconst FLAG_OUT = 'out';\nconst FLAG_TO_TERMINAL = 'to-terminal';\n\nconst FLAGS: Record<string, FlagDefinition> = {\n [FLAG_CONNECTION]: { type: 'string', description: 'The connection whose grant to export (`asana`).', required: true },\n [FLAG_OWNER]: { type: 'string', description: 'Whose grant: `user:<email>`, `organization:<id or slug>` or `application`.', required: true },\n [FLAG_SLOT]: { type: 'string', description: 'The credential slot, when the connection holds several for that owner.' },\n [FLAG_OUT]: { type: 'string', description: 'Write the document to this file, created with mode 0600. `-` or absent: stdout, refused when stdout is a terminal.' },\n [FLAG_TO_TERMINAL]: { type: 'boolean', description: 'Allow printing the document (which holds tokens) on a terminal.', default: false },\n};\n\n/**\n * Export one stored OAuth2 grant of the LOCAL running application in its portable form (grant seeding, development and\n * test only), so another development or test stack can import it with `wildo providers grant import`.\n *\n * The application opens the sealed grant (only it holds the key), refuses unless it runs as `development` or `test`,\n * admits only a super-administrator, and records `provider_grant_exported` by owner and connection, never the token.\n * This command signs in as the local administrator, refuses an application that does not answer on this machine, and\n * writes the document only where it was told.\n */\nexport default class ProvidersGrantExportCommand extends BaseCommand {\n readonly meta: CommandMeta = {\n name: 'providers grant export',\n description:\n 'Development and test only: export one OAuth2 grant the local running application holds (a person\\'s, an organization\\'s or its own) '\n + 'as a portable document, so another local or QA stack can import it instead of repeating the vendor\\'s consent. The document holds '\n + 'tokens: it is written to a 0600 file or piped, never printed on a terminal unless --to-terminal. Recorded as provider_grant_exported.',\n category: CommandCategory.Core,\n flags: FLAGS,\n // The document on stdout must be the only thing there: the seed script parses it.\n emitsDocumentOnStdout: (flags) => flags[FLAG_OUT] === undefined || flags[FLAG_OUT] === '-',\n };\n\n async run(ctx: CommandContext): Promise<CommandResult> {\n let session: ApplicationProviderConnectionClient | undefined;\n try {\n const owner = parseGrantTransferOwner(String(ctx.flags[FLAG_OWNER] ?? ''));\n const connectionRef = String(ctx.flags[FLAG_CONNECTION] ?? '').trim();\n if (connectionRef.length === 0) throw new Error('Name the connection: --connection <ref>.');\n const out = ctx.flags[FLAG_OUT] as string | undefined;\n const toTerminal = ctx.flags[FLAG_TO_TERMINAL] === true;\n // Refused before signing in: a document that would land on the screen is not asked for.\n if ((out === undefined || out === '-') && process.stdout.isTTY === true && !toTerminal) {\n throw new Error('The grant document holds tokens and stdout is a terminal: pass --out <file> (created 0600), pipe the output, or --to-terminal.');\n }\n\n // Only the LOCAL stack of an application root: there is no --api-url here, by design.\n if (!ctx.cliContext.resolvedHomes.app.declarationRoot) throw new Error('Run it from the application root of a local stack (where wildo.saas.config.ts is): a grant moves only between local development stacks.');\n // The fence BEFORE signing in: the local administrator's password goes nowhere but this machine.\n assertLocalGrantTransferTarget((await resolveApplicationApiTarget(ctx.cliContext.resolvedHomes.app.declarationRoot)).apiBaseUrl);\n session = await openApplicationConnectionSession({\n appRoot: ctx.cliContext.resolvedHomes.app.declarationRoot ?? null,\n frameworkRoot: ctx.cliContext.resolvedHomes.framework.repositoryRoot ?? null,\n });\n const secretSlug = ctx.flags[FLAG_SLOT] as string | undefined;\n const document = await session.exportGrant({ owner, connectionRef, ...(secretSlug === undefined ? {} : { secretSlug }) });\n const where = writeGrantTransferDocument(document, { ...(out === undefined ? {} : { out }), stdoutIsTerminal: process.stdout.isTTY === true, toTerminal });\n // On stderr, so a piped document stays the only thing on stdout.\n process.stderr.write(\n `Exported ${describeGrantTransferOwner(owner)}'s '${document.connectionRef}' grant (slot ${document.secretSlug}, transfer ${document.transferId}) to ${where}. `\n + `${document.grant.refreshToken === undefined ? 'It carries no refresh token: it stops working when its access token expires.' : 'It shares its authorization with this stack: a disconnect on either side may end it on both.'}\\n`,\n );\n return { success: true };\n } catch (error) {\n const hint = error instanceof ApplicationConnectionRequestRefusedError ? grantTransferRefusalHint(error.code) : undefined;\n ctx.log.error(`${ErrorUtils.extractErrorMessage(error)}${hint === undefined ? '' : ` ${hint}`}`);\n return { success: false };\n } finally {\n await session?.signOut();\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseCommand } from '../../kernel/base-command';
|
|
2
|
+
import type { CommandMeta, CommandContext, CommandResult } from '../../kernel/types';
|
|
3
|
+
/**
|
|
4
|
+
* Import a grant another development or test stack exported (grant seeding) into the LOCAL running application, for an
|
|
5
|
+
* owner named here.
|
|
6
|
+
*
|
|
7
|
+
* The application renews the grant at the vendor for its own client before storing it (a revoked or aged-out refresh
|
|
8
|
+
* token is refused here, by name), stores it through the door a completed connect writes into, and records the ordinary
|
|
9
|
+
* GRANTED event marked `grantImport`. A disconnect afterwards revokes it like any connected account.
|
|
10
|
+
*/
|
|
11
|
+
export default class ProvidersGrantImportCommand extends BaseCommand {
|
|
12
|
+
readonly meta: CommandMeta;
|
|
13
|
+
run(ctx: CommandContext): Promise<CommandResult>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=grant-import.command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grant-import.command.d.ts","sourceRoot":"","sources":["../../../../src/commands/providers/grant-import.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAI7D,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAkB,MAAM,yBAAyB,CAAC;AA6B1G;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,2BAA4B,SAAQ,WAAW;IAClE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAOxB;IAEI,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;CAyCvD"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { BaseCommand } from '../../kernel/base-command.js';
|
|
2
|
+
import { CommandCategory } from '../../kernel/types.js';
|
|
3
|
+
import { ErrorUtils } from '../../infrastructure/errors/error.utils.js';
|
|
4
|
+
import { printJsonPayload } from '../../commands/context/context-command.utils.js';
|
|
5
|
+
import { ApplicationConnectionRequestRefusedError, openApplicationConnectionSession, resolveApplicationApiTarget, } from '../../services/registry/application-provider-connection.service.js';
|
|
6
|
+
import { assertLocalGrantTransferTarget, describeGrantTransferOwner, grantTransferRefusalHint, parseGrantTransferOwner, readGrantTransferDocument, } from '../../services/registry/provider-grant-transfer.service.js';
|
|
7
|
+
const FLAG_CONNECTION = 'connection';
|
|
8
|
+
const FLAG_OWNER = 'owner';
|
|
9
|
+
const FLAG_FROM = 'from';
|
|
10
|
+
const FLAG_REPLACE = 'replace';
|
|
11
|
+
const FLAG_JSON = 'json';
|
|
12
|
+
const FLAGS = {
|
|
13
|
+
[FLAG_CONNECTION]: { type: 'string', description: 'The connection the document must be for (`asana`): a document for another one is refused.', required: true },
|
|
14
|
+
[FLAG_OWNER]: { type: 'string', description: 'Whose account to store it for here: `user:<email>`, `organization:<id or slug>` or `application`. Same scope as the export.', required: true },
|
|
15
|
+
[FLAG_FROM]: { type: 'string', description: 'The document `wildo providers grant export` wrote; `-` reads stdin.', required: true },
|
|
16
|
+
[FLAG_REPLACE]: { type: 'boolean', description: 'Replace a grant the owner already holds for the connection (default: refuse).', default: false },
|
|
17
|
+
[FLAG_JSON]: { type: 'boolean', description: 'Print the answer as JSON (never a token).', default: false },
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Import a grant another development or test stack exported (grant seeding) into the LOCAL running application, for an
|
|
21
|
+
* owner named here.
|
|
22
|
+
*
|
|
23
|
+
* The application renews the grant at the vendor for its own client before storing it (a revoked or aged-out refresh
|
|
24
|
+
* token is refused here, by name), stores it through the door a completed connect writes into, and records the ordinary
|
|
25
|
+
* GRANTED event marked `grantImport`. A disconnect afterwards revokes it like any connected account.
|
|
26
|
+
*/
|
|
27
|
+
export default class ProvidersGrantImportCommand extends BaseCommand {
|
|
28
|
+
meta = {
|
|
29
|
+
name: 'providers grant import',
|
|
30
|
+
description: 'Development and test only: store a grant `wildo providers grant export` wrote, in the local running application, for the owner you name '
|
|
31
|
+
+ '(same scope as the export). The application renews it at the vendor first, stores it as a connect would, and records it as imported.',
|
|
32
|
+
category: CommandCategory.Core,
|
|
33
|
+
flags: FLAGS,
|
|
34
|
+
};
|
|
35
|
+
async run(ctx) {
|
|
36
|
+
let session;
|
|
37
|
+
try {
|
|
38
|
+
const owner = parseGrantTransferOwner(String(ctx.flags[FLAG_OWNER] ?? ''));
|
|
39
|
+
const connectionRef = String(ctx.flags[FLAG_CONNECTION] ?? '').trim();
|
|
40
|
+
const from = String(ctx.flags[FLAG_FROM] ?? '').trim();
|
|
41
|
+
if (connectionRef.length === 0 || from.length === 0)
|
|
42
|
+
throw new Error('Name the connection and the document: --connection <ref> --from <file|->.');
|
|
43
|
+
const document = readGrantTransferDocument(from);
|
|
44
|
+
if (document.connectionRef !== connectionRef) {
|
|
45
|
+
throw new Error(`The document is for connection '${document.connectionRef}', not '${connectionRef}'.`);
|
|
46
|
+
}
|
|
47
|
+
// Only the LOCAL stack of an application root: there is no --api-url here, by design.
|
|
48
|
+
if (!ctx.cliContext.resolvedHomes.app.declarationRoot)
|
|
49
|
+
throw new Error('Run it from the application root of a local stack (where wildo.saas.config.ts is): a grant moves only between local development stacks.');
|
|
50
|
+
// The fence BEFORE signing in: the local administrator's password goes nowhere but this machine.
|
|
51
|
+
assertLocalGrantTransferTarget((await resolveApplicationApiTarget(ctx.cliContext.resolvedHomes.app.declarationRoot)).apiBaseUrl);
|
|
52
|
+
session = await openApplicationConnectionSession({
|
|
53
|
+
appRoot: ctx.cliContext.resolvedHomes.app.declarationRoot ?? null,
|
|
54
|
+
frameworkRoot: ctx.cliContext.resolvedHomes.framework.repositoryRoot ?? null,
|
|
55
|
+
});
|
|
56
|
+
const answer = await session.importGrant({ owner, document, replaceExisting: ctx.flags[FLAG_REPLACE] === true });
|
|
57
|
+
if (ctx.flags[FLAG_JSON] === true) {
|
|
58
|
+
printJsonPayload(ctx, answer);
|
|
59
|
+
return { success: true };
|
|
60
|
+
}
|
|
61
|
+
ctx.log.success(`Imported the '${answer.connectionRef}' grant for ${describeGrantTransferOwner(owner)} (credential ${answer.credentialId}, slot ${answer.secretSlug})`
|
|
62
|
+
+ `${answer.replacedExistingConnection ? ', replacing the one it held' : ''}.`);
|
|
63
|
+
ctx.log.info(answer.renewedAtImport
|
|
64
|
+
? 'The vendor renewed it for this application before it was stored.'
|
|
65
|
+
: 'It was stored as exported (no refresh token, or no refresher in this application): it works until its access token expires.');
|
|
66
|
+
return { success: true };
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const hint = error instanceof ApplicationConnectionRequestRefusedError ? grantTransferRefusalHint(error.code) : undefined;
|
|
70
|
+
ctx.log.error(`${ErrorUtils.extractErrorMessage(error)}${hint === undefined ? '' : ` ${hint}`}`);
|
|
71
|
+
return { success: false };
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
await session?.signOut();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=grant-import.command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grant-import.command.js","sourceRoot":"","sources":["../../../../src/commands/providers/grant-import.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,mDAAmD,CAAC;AAErF,OAAO,EACL,wCAAwC,EACxC,gCAAgC,EAChC,2BAA2B,GAE5B,MAAM,sEAAsE,CAAC;AAC9E,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,wBAAwB,EACxB,uBAAuB,E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CommandCategory } from '~wildo-cli/kernel/types';\nimport { ErrorUtils } from '~wildo-cli/infrastructure/errors/error.utils';\nimport { printJsonPayload } from '~wildo-cli/commands/context/context-command.utils';\nimport type { CommandMeta, CommandContext, CommandResult, FlagDefinition } from '~wildo-cli/kernel/types';\nimport {\n ApplicationConnectionRequestRefusedError,\n openApplicationConnectionSession,\n resolveApplicationApiTarget,\n type ApplicationProviderConnectionClient,\n} from '~wildo-cli/services/registry/application-provider-connection.service';\nimport {\n assertLocalGrantTransferTarget,\n describeGrantTransferOwner,\n grantTransferRefusalHint,\n parseGrantTransferOwner,\n readGrantTransferDocument,\n} from '~wildo-cli/services/registry/provider-grant-transfer.service';\n\nconst FLAG_CONNECTION = 'connection';\nconst FLAG_OWNER = 'owner';\nconst FLAG_FROM = 'from';\nconst FLAG_REPLACE = 'replace';\nconst FLAG_JSON = 'json';\n\nconst FLAGS: Record<string, FlagDefinition> = {\n [FLAG_CONNECTION]: { type: 'string', description: 'The connection the document must be for (`asana`): a document for another one is refused.', required: true },\n [FLAG_OWNER]: { type: 'string', description: 'Whose account to store it for here: `user:<email>`, `organization:<id or slug>` or `application`. Same scope as the export.', required: true },\n [FLAG_FROM]: { type: 'string', description: 'The document `wildo providers grant export` wrote; `-` reads stdin.', required: true },\n [FLAG_REPLACE]: { type: 'boolean', description: 'Replace a grant the owner already holds for the connection (default: refuse).', default: false },\n [FLAG_JSON]: { type: 'boolean', description: 'Print the answer as JSON (never a token).', default: false },\n};\n\n/**\n * Import a grant another development or test stack exported (grant seeding) into the LOCAL running application, for an\n * owner named here.\n *\n * The application renews the grant at the vendor for its own client before storing it (a revoked or aged-out refresh\n * token is refused here, by name), stores it through the door a completed connect writes into, and records the ordinary\n * GRANTED event marked `grantImport`. A disconnect afterwards revokes it like any connected account.\n */\nexport default class ProvidersGrantImportCommand extends BaseCommand {\n readonly meta: CommandMeta = {\n name: 'providers grant import',\n description:\n 'Development and test only: store a grant `wildo providers grant export` wrote, in the local running application, for the owner you name '\n + '(same scope as the export). The application renews it at the vendor first, stores it as a connect would, and records it as imported.',\n category: CommandCategory.Core,\n flags: FLAGS,\n };\n\n async run(ctx: CommandContext): Promise<CommandResult> {\n let session: ApplicationProviderConnectionClient | undefined;\n try {\n const owner = parseGrantTransferOwner(String(ctx.flags[FLAG_OWNER] ?? ''));\n const connectionRef = String(ctx.flags[FLAG_CONNECTION] ?? '').trim();\n const from = String(ctx.flags[FLAG_FROM] ?? '').trim();\n if (connectionRef.length === 0 || from.length === 0) throw new Error('Name the connection and the document: --connection <ref> --from <file|->.');\n const document = readGrantTransferDocument(from);\n if (document.connectionRef !== connectionRef) {\n throw new Error(`The document is for connection '${document.connectionRef}', not '${connectionRef}'.`);\n }\n\n // Only the LOCAL stack of an application root: there is no --api-url here, by design.\n if (!ctx.cliContext.resolvedHomes.app.declarationRoot) throw new Error('Run it from the application root of a local stack (where wildo.saas.config.ts is): a grant moves only between local development stacks.');\n // The fence BEFORE signing in: the local administrator's password goes nowhere but this machine.\n assertLocalGrantTransferTarget((await resolveApplicationApiTarget(ctx.cliContext.resolvedHomes.app.declarationRoot)).apiBaseUrl);\n session = await openApplicationConnectionSession({\n appRoot: ctx.cliContext.resolvedHomes.app.declarationRoot ?? null,\n frameworkRoot: ctx.cliContext.resolvedHomes.framework.repositoryRoot ?? null,\n });\n const answer = await session.importGrant({ owner, document, replaceExisting: ctx.flags[FLAG_REPLACE] === true });\n if (ctx.flags[FLAG_JSON] === true) {\n printJsonPayload(ctx, answer);\n return { success: true };\n }\n ctx.log.success(\n `Imported the '${answer.connectionRef}' grant for ${describeGrantTransferOwner(owner)} (credential ${answer.credentialId}, slot ${answer.secretSlug})`\n + `${answer.replacedExistingConnection ? ', replacing the one it held' : ''}.`,\n );\n ctx.log.info(answer.renewedAtImport\n ? 'The vendor renewed it for this application before it was stored.'\n : 'It was stored as exported (no refresh token, or no refresher in this application): it works until its access token expires.');\n return { success: true };\n } catch (error) {\n const hint = error instanceof ApplicationConnectionRequestRefusedError ? grantTransferRefusalHint(error.code) : undefined;\n ctx.log.error(`${ErrorUtils.extractErrorMessage(error)}${hint === undefined ? '' : ` ${hint}`}`);\n return { success: false };\n } finally {\n await session?.signOut();\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-runner.d.ts","sourceRoot":"","sources":["../../../src/kernel/command-runner.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EACV,WAAW,EAEX,aAAa,EACb,MAAM,EACN,UAAU,EACV,gCAAgC,EAChC,gBAAgB,EAChB,WAAW,EACZ,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"command-runner.d.ts","sourceRoot":"","sources":["../../../src/kernel/command-runner.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EACV,WAAW,EAEX,aAAa,EACb,MAAM,EACN,UAAU,EACV,gCAAgC,EAChC,gBAAgB,EAChB,WAAW,EACZ,MAAM,SAAS,CAAC;AAiBjB;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,EAAE,CAOjE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG;IAAE,WAAW,EAAE,WAAW,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,CAAA;CAAE,CAgCzG;AAMD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,WAAW,EACjB,OAAO,E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