@ory/argus 0.14.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +31 -46
  2. package/assets/commands/temporal-up.md +1 -1
  3. package/assets/skills/auth-setup/SKILL.md +1 -1
  4. package/assets/skills/local-dev/SKILL.md +17 -7
  5. package/assets/skills/ory-build-agent/SKILL.md +39 -91
  6. package/assets/skills/ory-e2b-sandbox/SKILL.md +18 -17
  7. package/assets/skills/ory-temporal-worker/SKILL.md +31 -33
  8. package/assets/skills/permissions-onboarding/SKILL.md +131 -104
  9. package/dist/adapters.d.ts +88 -32
  10. package/dist/adapters.js +443 -164
  11. package/dist/agent-auth.d.ts +226 -67
  12. package/dist/agent-auth.js +951 -205
  13. package/dist/auth-store.d.ts +37 -2
  14. package/dist/auth-store.js +37 -3
  15. package/dist/auth.d.ts +33 -4
  16. package/dist/auth.js +163 -20
  17. package/dist/bash-parser.d.ts +98 -0
  18. package/dist/bash-parser.js +396 -0
  19. package/dist/branding.d.ts +77 -16
  20. package/dist/branding.js +93 -23
  21. package/dist/build-info.json +4 -4
  22. package/dist/cli-invocation.d.ts +1 -1
  23. package/dist/cli-invocation.js +2 -1
  24. package/dist/cli.d.ts +20 -29
  25. package/dist/cli.js +271 -239
  26. package/dist/client.d.ts +175 -138
  27. package/dist/client.js +672 -391
  28. package/dist/config.d.ts +217 -54
  29. package/dist/config.js +461 -42
  30. package/dist/context.d.ts +10 -0
  31. package/dist/context.js +21 -0
  32. package/dist/contract-suite.d.ts +3 -5
  33. package/dist/contract-suite.js +75 -47
  34. package/dist/denial.d.ts +36 -3
  35. package/dist/denial.js +79 -10
  36. package/dist/event-reporter.d.ts +77 -0
  37. package/dist/event-reporter.js +776 -0
  38. package/dist/external-registrations-main.d.ts +10 -0
  39. package/dist/external-registrations-main.js +38 -0
  40. package/dist/external-registrations.d.ts +79 -0
  41. package/dist/external-registrations.js +188 -0
  42. package/dist/help-cli.d.ts +39 -0
  43. package/dist/help-cli.js +55 -0
  44. package/dist/hook-timeout.d.ts +64 -0
  45. package/dist/hook-timeout.js +88 -0
  46. package/dist/index.d.ts +28 -23
  47. package/dist/index.js +173 -58
  48. package/dist/lifecycle.d.ts +3 -3
  49. package/dist/lifecycle.js +38 -6
  50. package/dist/local/cli.js +11 -6
  51. package/dist/local/configs.d.ts +74 -18
  52. package/dist/local/configs.js +291 -84
  53. package/dist/local/health.js +7 -7
  54. package/dist/local/index.d.ts +2 -2
  55. package/dist/local/index.js +24 -10
  56. package/dist/local/manager.d.ts +20 -1
  57. package/dist/local/manager.js +159 -36
  58. package/dist/local/ports.d.ts +158 -0
  59. package/dist/local/ports.js +443 -0
  60. package/dist/local/seed.d.ts +13 -5
  61. package/dist/local/seed.js +62 -38
  62. package/dist/logger.d.ts +54 -25
  63. package/dist/logger.js +329 -63
  64. package/dist/mcp.d.ts +2 -2
  65. package/dist/mcp.js +10 -5
  66. package/dist/mirror-bootstrap.d.ts +48 -0
  67. package/dist/mirror-bootstrap.js +254 -0
  68. package/dist/opl.d.ts +289 -0
  69. package/dist/opl.js +446 -0
  70. package/dist/permission-mode.d.ts +87 -0
  71. package/dist/permission-mode.js +307 -0
  72. package/dist/permissions-cli.d.ts +13 -49
  73. package/dist/permissions-cli.js +154 -348
  74. package/dist/permissions.d.ts +148 -38
  75. package/dist/permissions.js +591 -45
  76. package/dist/post-install.d.ts +33 -0
  77. package/dist/post-install.js +127 -0
  78. package/dist/read-credential.d.ts +65 -0
  79. package/dist/read-credential.js +86 -0
  80. package/dist/registry/cli.js +5 -2
  81. package/dist/registry/config.d.ts +0 -17
  82. package/dist/registry/config.js +0 -23
  83. package/dist/registry/index.d.ts +1 -1
  84. package/dist/registry/index.js +2 -2
  85. package/dist/registry/manager.d.ts +4 -21
  86. package/dist/registry/manager.js +21 -37
  87. package/dist/runtime-credential.d.ts +140 -0
  88. package/dist/runtime-credential.js +572 -0
  89. package/dist/runtime.d.ts +413 -0
  90. package/dist/runtime.js +825 -0
  91. package/dist/setup.d.ts +23 -47
  92. package/dist/setup.js +59 -116
  93. package/dist/skills.js +0 -7
  94. package/dist/status-cli.d.ts +27 -11
  95. package/dist/status-cli.js +121 -115
  96. package/dist/status-data.d.ts +116 -17
  97. package/dist/status-data.js +121 -38
  98. package/dist/subject.d.ts +126 -20
  99. package/dist/subject.js +215 -30
  100. package/dist/testing.d.ts +74 -38
  101. package/dist/testing.js +185 -68
  102. package/dist/tool-catalog.d.ts +53 -11
  103. package/dist/tool-catalog.js +164 -13
  104. package/dist/tool-metadata.d.ts +7 -6
  105. package/dist/tool-metadata.js +6 -5
  106. package/dist/types.d.ts +11 -1
  107. package/dist/uninstall.d.ts +71 -34
  108. package/dist/uninstall.js +217 -85
  109. package/dist/user-login.d.ts +9 -10
  110. package/dist/user-login.js +56 -75
  111. package/dist/watch-cli.d.ts +6 -0
  112. package/dist/watch-cli.js +217 -0
  113. package/package.json +4 -27
  114. package/assets/commands/dashboard.md +0 -34
  115. package/dist/dashboard-cli.d.ts +0 -8
  116. package/dist/dashboard-cli.js +0 -70
  117. package/dist/dev.d.ts +0 -103
  118. package/dist/dev.js +0 -583
  119. package/dist/interactive-setup.d.ts +0 -286
  120. package/dist/interactive-setup.js +0 -1734
  121. package/dist/local/jaeger-main.d.ts +0 -13
  122. package/dist/local/jaeger-main.js +0 -85
  123. package/dist/local/jaeger.d.ts +0 -50
  124. package/dist/local/jaeger.js +0 -162
  125. package/dist/otel/exporter.d.ts +0 -17
  126. package/dist/otel/exporter.js +0 -12
  127. package/dist/otel/index.d.ts +0 -2
  128. package/dist/otel/index.js +0 -8
  129. package/dist/otel/otlp.d.ts +0 -103
  130. package/dist/otel/otlp.js +0 -385
  131. package/dist/project-api-key.d.ts +0 -69
  132. package/dist/project-api-key.js +0 -147
  133. package/dist/setup-actions.d.ts +0 -232
  134. package/dist/setup-actions.js +0 -507
  135. package/dist/tracer.d.ts +0 -190
  136. package/dist/tracer.js +0 -481
  137. package/dist/watch-sandbox.d.ts +0 -9
  138. package/dist/watch-sandbox.js +0 -81
  139. package/dist/web/api.d.ts +0 -33
  140. package/dist/web/api.js +0 -294
  141. package/dist/web/launch.d.ts +0 -11
  142. package/dist/web/launch.js +0 -96
  143. package/dist/web/server.d.ts +0 -20
  144. package/dist/web/server.js +0 -233
  145. package/dist/web/types.d.ts +0 -65
  146. package/dist/web/types.js +0 -2
  147. package/dist/webapp/assets/index-Wucl4SZs.css +0 -1
  148. package/dist/webapp/assets/index-m-GtEdq0.js +0 -49
  149. package/dist/webapp/favicon.ico +0 -0
  150. package/dist/webapp/index.html +0 -15
@@ -1,81 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- /**
4
- * Live trace watcher for the dev sandbox.
5
- *
6
- * Tails the NDJSON trace file produced by `pnpm dev:<harness>` and prints
7
- * a colorized line per span as they arrive. Run in a second terminal
8
- * alongside the dev launcher.
9
- */
10
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- var desc = Object.getOwnPropertyDescriptor(m, k);
13
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
- desc = { enumerable: true, get: function() { return m[k]; } };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }) : (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- o[k2] = m[k];
20
- }));
21
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
- Object.defineProperty(o, "default", { enumerable: true, value: v });
23
- }) : function(o, v) {
24
- o["default"] = v;
25
- });
26
- var __importStar = (this && this.__importStar) || (function () {
27
- var ownKeys = function(o) {
28
- ownKeys = Object.getOwnPropertyNames || function (o) {
29
- var ar = [];
30
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
- return ar;
32
- };
33
- return ownKeys(o);
34
- };
35
- return function (mod) {
36
- if (mod && mod.__esModule) return mod;
37
- var result = {};
38
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
- __setModuleDefault(result, mod);
40
- return result;
41
- };
42
- })();
43
- Object.defineProperty(exports, "__esModule", { value: true });
44
- const fs = __importStar(require("node:fs"));
45
- const path = __importStar(require("node:path"));
46
- const tracer_js_1 = require("./tracer.js");
47
- function workspaceRoot() {
48
- // This file ships at packages/core/dist/watch-sandbox.js.
49
- // Walk up to the workspace root.
50
- return path.resolve(__dirname, "..", "..", "..");
51
- }
52
- function resolveTraceFile(arg) {
53
- if (arg && (arg.includes("/") || arg.includes("\\") || arg.endsWith(".ndjson"))) {
54
- return path.resolve(arg);
55
- }
56
- const harness = arg ?? process.env.ORY_DEV_HARNESS;
57
- if (!harness) {
58
- console.error("Usage: ory-watch-sandbox <harness>\n" +
59
- " e.g. ory-watch-sandbox claude-code\n" +
60
- " Or pass an explicit trace file path.");
61
- process.exit(1);
62
- }
63
- return path.resolve(workspaceRoot(), ".sandbox", harness, "ory-agent-trace.ndjson");
64
- }
65
- function main() {
66
- const traceFile = resolveTraceFile(process.argv[2]);
67
- console.log(`Watching traces: ${traceFile}`);
68
- if (!fs.existsSync(traceFile)) {
69
- console.log("(file does not exist yet — waiting for the dev launcher to start producing spans)");
70
- }
71
- console.log("Press Ctrl+C to stop.\n");
72
- const stop = (0, tracer_js_1.watchTraceFile)(traceFile, (span) => {
73
- console.log((0, tracer_js_1.formatSpan)(span));
74
- });
75
- process.on("SIGINT", () => {
76
- stop();
77
- console.log("\nStopped watching.");
78
- process.exit(0);
79
- });
80
- }
81
- main();
package/dist/web/api.d.ts DELETED
@@ -1,33 +0,0 @@
1
- /**
2
- * JSON API for the local web installer / status dashboard. Each route is a
3
- * thin wrapper over a headless action in {@link file://../setup-actions.ts} or
4
- * the status data in {@link file://../status-data.ts}. All state for one
5
- * install run (the resolved `ory` runner, the selected workspace/project, and
6
- * the in-flight browser sub-flows) lives in a single {@link SetupSession} held
7
- * by the server for its lifetime.
8
- *
9
- * Handlers never throw for expected failures — they return an `{ error }`
10
- * envelope with an appropriate HTTP status so the SPA can surface it and the
11
- * user can retry, exactly like the TTY wizard's fail-open steps.
12
- */
13
- import { type SetupActionDeps } from "../setup-actions.js";
14
- import type { WebAppMode } from "./types.js";
15
- export interface ApiResult {
16
- status: number;
17
- json: unknown;
18
- }
19
- export interface ApiContext {
20
- mode: WebAppMode;
21
- harness: string;
22
- binName: string;
23
- deps: SetupActionDeps;
24
- /** Called when the SPA POSTs /api/shutdown. */
25
- onShutdown: () => void;
26
- }
27
- /**
28
- * Build the API request handler bound to one server run. Returns
29
- * `handle(method, path, body)` producing an {@link ApiResult}.
30
- */
31
- export declare function createApi(ctx: ApiContext): {
32
- handle: (method: string, path: string, body: Record<string, unknown>) => Promise<ApiResult>;
33
- };
package/dist/web/api.js DELETED
@@ -1,294 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createApi = createApi;
4
- /**
5
- * JSON API for the local web installer / status dashboard. Each route is a
6
- * thin wrapper over a headless action in {@link file://../setup-actions.ts} or
7
- * the status data in {@link file://../status-data.ts}. All state for one
8
- * install run (the resolved `ory` runner, the selected workspace/project, and
9
- * the in-flight browser sub-flows) lives in a single {@link SetupSession} held
10
- * by the server for its lifetime.
11
- *
12
- * Handlers never throw for expected failures — they return an `{ error }`
13
- * envelope with an appropriate HTTP status so the SPA can surface it and the
14
- * user can retry, exactly like the TTY wizard's fail-open steps.
15
- */
16
- const setup_actions_js_1 = require("../setup-actions.js");
17
- const status_data_js_1 = require("../status-data.js");
18
- const config_js_1 = require("../config.js");
19
- const version_cli_js_1 = require("../version-cli.js");
20
- const ok = (json = { ok: true }) => ({ status: 200, json });
21
- const bad = (error, status = 400) => ({ status, json: { error } });
22
- /**
23
- * Build the API request handler bound to one server run. Returns
24
- * `handle(method, path, body)` producing an {@link ApiResult}.
25
- */
26
- function createApi(ctx) {
27
- const session = {
28
- runner: ctx.deps.runner ?? null,
29
- subject: null,
30
- };
31
- /** The runner to use, failing loudly if `POST /api/ory-cli` hasn't run. */
32
- function runner() {
33
- return session.runner;
34
- }
35
- async function handle(method, path, body) {
36
- const route = `${method} ${path}`;
37
- switch (route) {
38
- case "GET /api/bootstrap": {
39
- const cfg = (0, config_js_1.resolveConfig)();
40
- const payload = {
41
- mode: ctx.mode,
42
- harness: ctx.harness,
43
- binName: ctx.binName,
44
- version: (0, version_cli_js_1.resolveCoreVersion)(),
45
- alreadyConfigured: !!cfg.projectUrl || cfg.auditOnly,
46
- auditOnly: cfg.auditOnly,
47
- projectUrl: cfg.projectUrl,
48
- };
49
- return ok(payload);
50
- }
51
- case "GET /api/status":
52
- return ok(await (0, status_data_js_1.collectStatusReport)(ctx.harness));
53
- case "POST /api/ory-cli": {
54
- const res = await (0, setup_actions_js_1.ensureOryCli)(ctx.deps);
55
- session.runner = res.runner;
56
- return ok({ present: res.present, installed: res.installed });
57
- }
58
- case "GET /api/signin": {
59
- const r = runner();
60
- return ok({ signedIn: r ? (0, setup_actions_js_1.isSignedIn)(r) : false });
61
- }
62
- case "POST /api/signin": {
63
- const r = runner();
64
- if (!r)
65
- return bad("Ory CLI is not ready", 409);
66
- if ((0, setup_actions_js_1.isSignedIn)(r))
67
- return ok({ started: false, signedIn: true });
68
- const handle = (0, setup_actions_js_1.startSignIn)(r);
69
- const task = { handle, state: "running" };
70
- session.signIn = task;
71
- handle.done.then((success) => {
72
- task.state = success ? "done" : "failed";
73
- });
74
- return ok({ started: true, signedIn: false });
75
- }
76
- case "GET /api/signin/status": {
77
- const r = runner();
78
- const task = session.signIn;
79
- const state = task?.state ?? "idle";
80
- // Treat a live session as done even if we never launched `ory auth`
81
- // (the CLI may already have been signed in).
82
- const signedIn = state === "done" || (!!r && (0, setup_actions_js_1.isSignedIn)(r));
83
- return ok({ state: signedIn ? "done" : state, signedIn });
84
- }
85
- case "GET /api/workspaces": {
86
- const r = runner();
87
- if (!r)
88
- return bad("Ory CLI is not ready", 409);
89
- const workspaces = (0, setup_actions_js_1.listWorkspaces)(r);
90
- if (workspaces === null)
91
- return bad("Could not list workspaces", 502);
92
- session.workspaces = workspaces;
93
- return ok({ workspaces });
94
- }
95
- case "POST /api/workspaces": {
96
- const r = runner();
97
- if (!r)
98
- return bad("Ory CLI is not ready", 409);
99
- const name = str(body.name);
100
- if (!name)
101
- return bad("A workspace name is required");
102
- const res = (0, setup_actions_js_1.createWorkspace)(r, name);
103
- if (!res.ok)
104
- return bad(res.error ?? "Could not create workspace", 502);
105
- return ok({ workspace: res.value });
106
- }
107
- case "GET /api/projects": {
108
- const r = runner();
109
- if (!r)
110
- return bad("Ory CLI is not ready", 409);
111
- const workspaceId = str(body.workspaceId);
112
- if (!workspaceId)
113
- return bad("A workspaceId is required");
114
- session.workspaceId = workspaceId;
115
- session.workspaceName = session.workspaces?.find((w) => w.id === workspaceId)?.name;
116
- const projects = (0, setup_actions_js_1.listProjects)(r, workspaceId);
117
- if (projects === null)
118
- return bad("Could not list projects", 502);
119
- return ok({ projects, cap: setup_actions_js_1.PROJECT_CAP, canCreate: projects.length < setup_actions_js_1.PROJECT_CAP });
120
- }
121
- case "POST /api/projects": {
122
- const r = runner();
123
- if (!r)
124
- return bad("Ory CLI is not ready", 409);
125
- const workspaceId = str(body.workspaceId) ?? session.workspaceId;
126
- const name = str(body.name);
127
- if (!workspaceId || !name)
128
- return bad("workspaceId and name are required");
129
- const res = (0, setup_actions_js_1.createProject)(r, workspaceId, name);
130
- if (!res.ok)
131
- return bad(res.error ?? "Could not create project", 502);
132
- return ok({ project: res.value });
133
- }
134
- case "POST /api/select-project": {
135
- const r = runner();
136
- if (!r)
137
- return bad("Ory CLI is not ready", 409);
138
- const project = body.project;
139
- if (!project?.id)
140
- return bad("A project is required");
141
- const url = (0, setup_actions_js_1.resolveProjectUrl)(project);
142
- if (!url.ok)
143
- return bad(url.error ?? "Could not resolve project URL", 422);
144
- session.project = project;
145
- session.projectUrl = url.value;
146
- // Ensure the OAuth2 login/consent UI is the Ory Managed Account
147
- // Experience so the PKCE user login (step 7) renders a working page —
148
- // a CLI-created project defaults these to the localhost:3000 sample.
149
- const loginUi = (0, setup_actions_js_1.ensureManagedLoginUi)(r, project.id);
150
- return ok({ projectUrl: url.value, dcrEnabled: (0, setup_actions_js_1.getDcrState)(r, project.id), loginUi });
151
- }
152
- case "POST /api/enable-dcr": {
153
- const r = runner();
154
- if (!r || !session.project)
155
- return bad("No project selected", 409);
156
- return ok({ ok: (0, setup_actions_js_1.enableDcrAction)(r, session.project.id) });
157
- }
158
- case "POST /api/oauth2-client": {
159
- const r = runner();
160
- if (!r || !session.project)
161
- return bad("No project selected", 409);
162
- const res = (0, setup_actions_js_1.provisionOAuth2Client)(r, session.project.id);
163
- if (!res.ok || !res.clientId)
164
- return bad("Could not provision the OAuth2 client", 502);
165
- session.oauth2ClientId = res.clientId;
166
- return ok({ clientId: res.clientId, reused: res.reused, name: res.name });
167
- }
168
- case "POST /api/save": {
169
- if (!session.project || !session.projectUrl || !session.oauth2ClientId) {
170
- return bad("Setup is incomplete (missing project / client)", 409);
171
- }
172
- (0, setup_actions_js_1.saveNetworkConfig)({
173
- projectUrl: session.projectUrl,
174
- projectId: session.project.id,
175
- oauth2ClientId: session.oauth2ClientId,
176
- projectName: session.project.name ?? session.project.slug,
177
- workspaceName: session.workspaceName,
178
- });
179
- return ok();
180
- }
181
- case "POST /api/login": {
182
- if (session.login?.state === "running")
183
- return ok({ started: false });
184
- // Pin the project the wizard resolved so a stale ORY_PROJECT_URL in the
185
- // user's shell can't send the login to the wrong URL (e.g. :3000).
186
- const task = {
187
- promise: (0, setup_actions_js_1.runFullSetup)(ctx.binName, ctx.harness, ctx.deps, {
188
- projectUrl: session.projectUrl,
189
- oauth2ClientId: session.oauth2ClientId,
190
- }),
191
- state: "running",
192
- };
193
- session.login = task;
194
- task.promise.then((result) => {
195
- task.state = result.authenticated ? "done" : "failed";
196
- task.result = result;
197
- if (result.subject) {
198
- session.subject = result.subject;
199
- // The login only resolves an opaque subject id; look the identity up
200
- // via the admin CLI to show a readable name (email) instead of a UUID.
201
- const sid = "subjectId" in result.subject
202
- ? result.subject.subjectId
203
- : result.subject.subjectSet.object;
204
- const r = session.runner;
205
- if (r && session.project && sid) {
206
- const name = (0, setup_actions_js_1.resolveIdentityName)(r, session.project.id, sid);
207
- if (name)
208
- task.result = { ...result, subjectLabel: name };
209
- }
210
- }
211
- });
212
- return ok({ started: true });
213
- }
214
- case "GET /api/login/status": {
215
- const task = session.login;
216
- return ok({
217
- state: task?.state ?? "idle",
218
- authenticated: task?.result?.authenticated ?? false,
219
- subjectLabel: task?.result?.subjectLabel ?? null,
220
- });
221
- }
222
- case "GET /api/permissions/model": {
223
- const r = runner();
224
- if (!r || !session.project)
225
- return bad("No project selected", 409);
226
- return ok(await (0, setup_actions_js_1.inspectPermissions)(r, session.project.id));
227
- }
228
- case "POST /api/permissions/provision": {
229
- const r = runner();
230
- if (!r || !session.project)
231
- return bad("No project selected", 409);
232
- const opl = str(body.opl);
233
- return ok({ ok: (0, setup_actions_js_1.provisionPermissions)(r, session.project.id, undefined, opl) });
234
- }
235
- case "POST /api/permissions/grant": {
236
- const r = runner();
237
- if (!r || !session.project)
238
- return bad("No project selected", 409);
239
- if (!session.subject)
240
- return bad("Sign in first so permissions can be granted to you", 409);
241
- const res = (0, setup_actions_js_1.grantToolPermissions)(r, session.project.id, ctx.harness, session.subject);
242
- return ok(res);
243
- }
244
- case "POST /api/api-key": {
245
- if (!session.project || !session.projectUrl)
246
- return bad("No project selected", 409);
247
- const res = await (0, setup_actions_js_1.provisionProjectApiKey)({
248
- projectId: session.project.id,
249
- projectUrl: session.projectUrl,
250
- harness: ctx.harness,
251
- user: session.subject
252
- ? (0, setup_actions_js_1.resourceUserLabel)(runner(), session.project.id, session.subject)
253
- : undefined,
254
- }, ctx.deps);
255
- return ok(res);
256
- }
257
- case "POST /api/audit-only": {
258
- (0, setup_actions_js_1.configureAuditOnly)();
259
- return ok();
260
- }
261
- // Live toggle from the dashboard (permission posture).
262
- case "POST /api/config": {
263
- const patch = {};
264
- if ("permissionMode" in body) {
265
- if (body.permissionMode !== "observe" && body.permissionMode !== "enforce") {
266
- return bad("permissionMode must be 'observe' or 'enforce'");
267
- }
268
- (0, setup_actions_js_1.setPermissionMode)(body.permissionMode);
269
- patch.permissionMode = body.permissionMode;
270
- }
271
- if (Object.keys(patch).length === 0)
272
- return bad("No supported config fields in request");
273
- return ok(patch);
274
- }
275
- case "POST /api/local": {
276
- const res = await (0, setup_actions_js_1.configureLocalStack)(ctx.deps);
277
- // Record the local connection so the subsequent login pins to it too.
278
- session.projectUrl = res.projectUrl;
279
- session.oauth2ClientId = res.oauth2ClientId;
280
- return ok(res);
281
- }
282
- case "POST /api/shutdown": {
283
- ctx.onShutdown();
284
- return ok();
285
- }
286
- default:
287
- return bad(`Unknown route: ${route}`, 404);
288
- }
289
- }
290
- return { handle };
291
- }
292
- function str(v) {
293
- return typeof v === "string" && v.trim() ? v.trim() : undefined;
294
- }
@@ -1,11 +0,0 @@
1
- import type { SetupActionDeps } from "../setup-actions.js";
2
- /**
3
- * Heuristic for whether we can meaningfully open a browser for the user:
4
- * an interactive TTY, not CI, not opted-out, and — on Linux — an actual
5
- * display server. macOS/Windows are assumed to have a default browser.
6
- */
7
- export declare function canLaunchBrowser(): boolean;
8
- /** Open the guided install/setup wizard in the browser. */
9
- export declare function launchWebInstaller(binName: string, harness: string, deps?: SetupActionDeps): Promise<boolean>;
10
- /** Open the status dashboard in the browser. */
11
- export declare function launchWebDashboard(binName: string, harness: string, deps?: SetupActionDeps): Promise<boolean>;
@@ -1,96 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.canLaunchBrowser = canLaunchBrowser;
4
- exports.launchWebInstaller = launchWebInstaller;
5
- exports.launchWebDashboard = launchWebDashboard;
6
- /**
7
- * Deciding whether to open the browser, and doing it. `canLaunchBrowser()`
8
- * gates the web UI on an interactive, non-CI environment with a usable display;
9
- * `launchWebInstaller` / `launchWebDashboard` start the local server, open the
10
- * browser, and block until the SPA signals it is done (or the user hits
11
- * Ctrl+C). Every entry point is fail-open: a launch that can't start returns
12
- * `false` so the caller falls back to the TTY wizard / text readout.
13
- */
14
- const server_js_1 = require("./server.js");
15
- /** Whether the environment opts out of the web UI. */
16
- function webDisabledByEnv() {
17
- const off = (v) => v === "1" || v === "true" || v === "yes";
18
- return off(process.env.ORY_NO_WEB?.trim()) || off(process.env.ORY_SETUP_NO_WEB?.trim());
19
- }
20
- /**
21
- * Heuristic for whether we can meaningfully open a browser for the user:
22
- * an interactive TTY, not CI, not opted-out, and — on Linux — an actual
23
- * display server. macOS/Windows are assumed to have a default browser.
24
- */
25
- function canLaunchBrowser() {
26
- if (webDisabledByEnv())
27
- return false;
28
- if (process.env.CI)
29
- return false;
30
- if (!process.stdout.isTTY)
31
- return false;
32
- if (process.platform === "linux") {
33
- return !!(process.env.DISPLAY || process.env.WAYLAND_DISPLAY);
34
- }
35
- return process.platform === "darwin" || process.platform === "win32";
36
- }
37
- async function openBrowser(url) {
38
- try {
39
- const mod = (await import("open"));
40
- await mod.default(url);
41
- }
42
- catch {
43
- /* the URL is also printed to stderr; the user can open it manually */
44
- }
45
- }
46
- /**
47
- * Start the server, open the browser, and wait until the SPA POSTs
48
- * `/api/shutdown` or the user interrupts. Returns true once handled; false if
49
- * the server could not start (caller falls back).
50
- */
51
- async function launch(opts) {
52
- let server;
53
- try {
54
- server = await (0, server_js_1.startServer)({
55
- mode: opts.mode,
56
- harness: opts.harness,
57
- binName: opts.binName,
58
- deps: opts.deps,
59
- });
60
- }
61
- catch {
62
- return false;
63
- }
64
- // All human-facing output goes to stderr — stdout stays clean for any harness
65
- // that parses it.
66
- console.error("");
67
- console.error(` Ory Agent ${opts.label} is running in your browser:`);
68
- console.error(` ${server.url}`);
69
- console.error(` Leave this terminal open; press Ctrl+C when you're done.`);
70
- console.error("");
71
- await openBrowser(server.url);
72
- const onSigint = () => server.close();
73
- process.once("SIGINT", onSigint);
74
- try {
75
- await server.closed;
76
- // The shutdown request resolves `closed` before its HTTP response has
77
- // flushed; give the browser a beat to receive it before we tear down the
78
- // sockets (otherwise the SPA's final fetch just errors — harmless, but
79
- // this keeps the "done" confirmation clean).
80
- await new Promise((r) => setTimeout(r, 150));
81
- }
82
- finally {
83
- process.removeListener("SIGINT", onSigint);
84
- await server.close();
85
- }
86
- console.error(" Done — you can close the browser tab.");
87
- return true;
88
- }
89
- /** Open the guided install/setup wizard in the browser. */
90
- function launchWebInstaller(binName, harness, deps) {
91
- return launch({ mode: "install", binName, harness, deps, label: "setup" });
92
- }
93
- /** Open the status dashboard in the browser. */
94
- function launchWebDashboard(binName, harness, deps) {
95
- return launch({ mode: "status", binName, harness, deps, label: "status" });
96
- }
@@ -1,20 +0,0 @@
1
- import type { SetupActionDeps } from "../setup-actions.js";
2
- import type { WebAppMode } from "./types.js";
3
- export interface StartServerOptions {
4
- mode: WebAppMode;
5
- harness: string;
6
- binName: string;
7
- deps?: SetupActionDeps;
8
- /** Override the static web root (defaults to the built `dist/webapp`). */
9
- webRoot?: string;
10
- }
11
- export interface RunningServer {
12
- url: string;
13
- port: number;
14
- token: string;
15
- /** Resolves when the SPA requests shutdown or {@link close} is called. */
16
- closed: Promise<void>;
17
- close(): Promise<void>;
18
- }
19
- /** Start the server. Resolves once it is listening. */
20
- export declare function startServer(opts: StartServerOptions): Promise<RunningServer>;