@knpkv/jira-cli 1.4.0 → 1.4.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.
@@ -1,72 +0,0 @@
1
- /**
2
- * Local HTTP callback server for OAuth2 authorization code capture.
3
- *
4
- * **Mental model**
5
- *
6
- * - **Scope-owned lifecycle**: {@link startCallbackServer} returns a `codePromise`
7
- * (Deferred). The server validates the CSRF `state` parameter, resolves the
8
- * Deferred with the authorization code, and stops when its enclosing scope closes.
9
- * - **Port auto-discovery**: Tries default port 8585, increments on conflict.
10
- *
11
- * @internal
12
- */
13
- import { OAuthError } from "@knpkv/atlassian-common/auth";
14
- import * as Context from "effect/Context";
15
- import * as Effect from "effect/Effect";
16
- import { HttpServer } from "effect/http";
17
- import type * as HttpServerError from "effect/http/HttpServerError";
18
- import * as Layer from "effect/Layer";
19
- import type * as Scope from "effect/Scope";
20
- /**
21
- * Factory service for creating HTTP servers.
22
- * This allows mocking the server creation in tests.
23
- *
24
- * @category Services
25
- */
26
- export interface HttpServerFactory {
27
- readonly createServerLayer: (options: CallbackServerListenOptions) => Layer.Layer<HttpServer.HttpServer, HttpServerError.ServeError, never>;
28
- }
29
- export interface CallbackServerListenOptions {
30
- readonly host: "localhost";
31
- readonly port: number;
32
- }
33
- export declare const callbackServerListenOptions: (port: number) => CallbackServerListenOptions;
34
- export declare const callbackUrl: (port: number) => string;
35
- declare const HttpServerFactoryTag_base: Context.ServiceClass<HttpServerFactoryTag, "@knpkv/jira-cli/HttpServerFactory", HttpServerFactory>;
36
- /**
37
- * Tag for the HttpServerFactory service.
38
- *
39
- * @category Services
40
- */
41
- export declare class HttpServerFactoryTag extends HttpServerFactoryTag_base {
42
- }
43
- /**
44
- * Create a HttpServerFactory layer from a layer factory function.
45
- * This allows injecting platform-specific implementations.
46
- *
47
- * @param createLayerFn - Function that creates HttpServer layer for a given port
48
- * @returns Layer providing HttpServerFactory
49
- *
50
- * @category Layers
51
- */
52
- export declare const makeHttpServerFactory: (createLayerFn: (options: CallbackServerListenOptions) => Layer.Layer<HttpServer.HttpServer, HttpServerError.ServeError, never>) => Layer.Layer<HttpServerFactoryTag>;
53
- /**
54
- * Result from the OAuth callback server.
55
- */
56
- export interface CallbackServerResult {
57
- /** Promise that resolves with the authorization code */
58
- readonly codePromise: Effect.Effect<string, OAuthError>;
59
- /** The port the server is listening on */
60
- readonly port: number;
61
- }
62
- /**
63
- * Start a local HTTP server to receive OAuth callback.
64
- *
65
- * @param expectedState - The state parameter to verify against CSRF
66
- * @returns Server control interface with code promise and port
67
- *
68
- * @category OAuth
69
- */
70
- export declare const startCallbackServer: (expectedState: string) => Effect.Effect<CallbackServerResult, OAuthError, HttpServerFactoryTag | Scope.Scope>;
71
- export {};
72
- //# sourceMappingURL=oauthServer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"oauthServer.d.ts","sourceRoot":"","sources":["../../src/internal/oauthServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAc,UAAU,EAAsB,MAAM,aAAa,CAAA;AACxE,OAAO,KAAK,KAAK,eAAe,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAK1C;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,iBAAiB,EAAE,CAAC,OAAO,EAAE,2BAA2B,KAAK,KAAK,CAAC,KAAK,CAC/E,UAAU,CAAC,UAAU,EACrB,eAAe,CAAC,UAAU,EAC1B,KAAK,CACN,CAAA;CACF;AAED,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAED,eAAO,MAAM,2BAA2B,SAAU,MAAM,KAAG,2BAGzD,CAAA;AAEF,eAAO,MAAM,WAAW,SAAU,MAAM,KAAG,MAA6C,CAAA;;AAExF;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,yBAGF;CAAG;AAE3C;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,kBACjB,CACb,OAAO,EAAE,2BAA2B,KACjC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,EAAE,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,KACzE,KAAK,CAAC,KAAK,CAAC,oBAAoB,CAG/B,CAAA;AAEJ;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,wDAAwD;IACxD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IACvD,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAQD;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,kBACf,MAAM,KACpB,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE,UAAU,EAAE,oBAAoB,GAAG,KAAK,CAAC,KAAK,CAgFjF,CAAA"}
@@ -1,97 +0,0 @@
1
- /**
2
- * Local HTTP callback server for OAuth2 authorization code capture.
3
- *
4
- * **Mental model**
5
- *
6
- * - **Scope-owned lifecycle**: {@link startCallbackServer} returns a `codePromise`
7
- * (Deferred). The server validates the CSRF `state` parameter, resolves the
8
- * Deferred with the authorization code, and stops when its enclosing scope closes.
9
- * - **Port auto-discovery**: Tries default port 8585, increments on conflict.
10
- *
11
- * @internal
12
- */
13
- import { OAuthError } from "@knpkv/atlassian-common/auth";
14
- import * as Context from "effect/Context";
15
- import * as Deferred from "effect/Deferred";
16
- import * as Effect from "effect/Effect";
17
- import { HttpRouter, HttpServer, HttpServerResponse } from "effect/http";
18
- import * as Layer from "effect/Layer";
19
- import { NetAddress } from "effect/net";
20
- import * as Schema from "effect/Schema";
21
- const DEFAULT_PORT = 8585;
22
- const MAX_PORT = 8594;
23
- export const callbackServerListenOptions = (port) => ({
24
- host: "localhost",
25
- port
26
- });
27
- export const callbackUrl = (port) => `http://localhost:${port}/callback`;
28
- /**
29
- * Tag for the HttpServerFactory service.
30
- *
31
- * @category Services
32
- */
33
- export class HttpServerFactoryTag extends Context.Service()("@knpkv/jira-cli/HttpServerFactory") {
34
- }
35
- /**
36
- * Create a HttpServerFactory layer from a layer factory function.
37
- * This allows injecting platform-specific implementations.
38
- *
39
- * @param createLayerFn - Function that creates HttpServer layer for a given port
40
- * @returns Layer providing HttpServerFactory
41
- *
42
- * @category Layers
43
- */
44
- export const makeHttpServerFactory = (createLayerFn) => Layer.succeed(HttpServerFactoryTag, {
45
- createServerLayer: createLayerFn
46
- });
47
- const AddressInUseCause = Schema.Struct({
48
- code: Schema.Literal("EADDRINUSE")
49
- });
50
- const isAddressInUse = (error) => Schema.is(AddressInUseCause)(error.cause);
51
- /**
52
- * Start a local HTTP server to receive OAuth callback.
53
- *
54
- * @param expectedState - The state parameter to verify against CSRF
55
- * @returns Server control interface with code promise and port
56
- *
57
- * @category OAuth
58
- */
59
- export const startCallbackServer = (expectedState) => Effect.gen(function* () {
60
- const factory = yield* HttpServerFactoryTag;
61
- const deferred = yield* Deferred.make();
62
- const serverScope = yield* Effect.scope;
63
- const buildServerContext = (port) => Layer.buildWithScope(factory.createServerLayer(callbackServerListenOptions(port)), serverScope).pipe(Effect.map((context) => ({ context, port })), Effect.catchIf((error) => isAddressInUse(error) && port < MAX_PORT, () => buildServerContext(port + 1)), Effect.mapError((cause) => new OAuthError({ step: "authorize", cause })));
64
- const { context: serverContext } = yield* buildServerContext(DEFAULT_PORT);
65
- const server = Context.get(serverContext, HttpServer.HttpServer);
66
- const port = yield* (NetAddress.isInetAddress(server.address)
67
- ? Effect.succeed(server.address.port)
68
- : Effect.fail(new OAuthError({ step: "authorize", cause: "OAuth callback server must listen on a TCP port" })));
69
- const router = yield* HttpRouter.make;
70
- yield* router.add("GET", "/callback", (req) => Effect.gen(function* () {
71
- const url = new URL(req.url, callbackUrl(port));
72
- const code = url.searchParams.get("code");
73
- const state = url.searchParams.get("state");
74
- const error = url.searchParams.get("error");
75
- const errorDescription = url.searchParams.get("error_description");
76
- if (state !== expectedState) {
77
- return HttpServerResponse.html("<html><body><h1>Security Error</h1><p>State verification failed.</p></body></html>").pipe(HttpServerResponse.setStatus(403));
78
- }
79
- if (error) {
80
- yield* Deferred.fail(deferred, new OAuthError({ step: "authorize", cause: errorDescription ?? error }));
81
- return HttpServerResponse.html("<html><body><h1>Authorization Failed</h1><p>You can close this window.</p></body></html>");
82
- }
83
- if (!code) {
84
- yield* Deferred.fail(deferred, new OAuthError({ step: "authorize", cause: "No authorization code received" }));
85
- return HttpServerResponse.html("<html><body><h1>Error</h1><p>No authorization code received.</p></body></html>");
86
- }
87
- yield* Deferred.succeed(deferred, code);
88
- return HttpServerResponse.html("<html><body><h1>Success!</h1><p>You can close this window and return to the terminal.</p></body></html>");
89
- }));
90
- const app = router.asHttpEffect();
91
- yield* HttpServer.serveEffect(app).pipe(Effect.provide(serverContext), Effect.forkScoped);
92
- return {
93
- codePromise: Deferred.await(deferred),
94
- port
95
- };
96
- });
97
- //# sourceMappingURL=oauthServer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"oauthServer.js","sourceRoot":"","sources":["../../src/internal/oauthServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAExE,OA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AA;QACH,CAAC;QAED,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;QACvC,OAAO,kBAAkB,CAAC,IAAI,CAC5B,yGAAyG,CAC1G,CAAA;IACH,CAAC,CAAC,CACL,CAAA;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,YAAY,EAAE,CAAA;IAEjC,KAAK,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,CACrC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAC7B,MAAM,CAAC,UAAU,CAClB,CAAA;IAED,OAAO;QACL,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;QACrC,IAAI;KACL,CAAA;AACH,CAAC,CAAC,CAAA"}
@@ -1,10 +0,0 @@
1
- /**
2
- * Cross-platform browser launcher backed by Effect v4 child process services.
3
- *
4
- * @internal
5
- */
6
- import * as Effect from "effect/Effect";
7
- import type * as PlatformError from "effect/PlatformError";
8
- import { ChildProcessSpawner } from "effect/process";
9
- export declare const openBrowser: (url: string) => Effect.Effect<void, PlatformError.PlatformError, ChildProcessSpawner.ChildProcessSpawner>;
10
- //# sourceMappingURL=openBrowser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openBrowser.d.ts","sourceRoot":"","sources":["../../src/internal/openBrowser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,aAAa,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAgB,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAiBlE,eAAO,MAAM,WAAW,QACjB,MAAM,KACV,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,aAAa,EAAE,mBAAmB,CAAC,mBAAmB,CAIxF,CAAA"}
@@ -1,17 +0,0 @@
1
- /**
2
- * Cross-platform browser launcher backed by Effect v4 child process services.
3
- *
4
- * @internal
5
- */
6
- import * as Effect from "effect/Effect";
7
- import { ChildProcess, ChildProcessSpawner } from "effect/process";
8
- const run = (command, args) => Effect.gen(function* () {
9
- const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
10
- yield* spawner.exitCode(ChildProcess.make(command, args, {
11
- stdin: "ignore",
12
- stdout: "ignore",
13
- stderr: "ignore"
14
- }));
15
- });
16
- export const openBrowser = (url) => run("open", [url]).pipe(Effect.catch(() => run("xdg-open", [url])), Effect.catch(() => run("rundll32.exe", ["url.dll,FileProtocolHandler", url])));
17
- //# sourceMappingURL=openBrowser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"openBrowser.js","sourceRoot":"","sources":["../../src/internal/openBrowser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAElE,MAAM,GAAG,GAAG,CACV,OAAe,EACf,IAA2B,EACgE,EAAE,CAC7F,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,mBAAmB,CAAC,mBAAmB,CAAA;IAC9D,KAAK,CAAC,CAAC,OAAO,CAAC,QAAQ,CACrB,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE;QAC/B,KAAK,EAAE,QAAQ;QACf,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,QAAQ;KACjB,CAAC,CACH,CAAA;AACH,CAAC,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,GAAW,EACgF,EAAE,CAC7F,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CACrB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAC1C,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC,CAAC,CAC9E,CAAA"}
@@ -1,17 +0,0 @@
1
- /**
2
- * Node.js-specific HTTP server factory — the only file importing `@effect/platform-node` server.
3
- *
4
- * @internal
5
- */
6
- import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer"
7
- import { createServer } from "node:http"
8
- import { makeHttpServerFactory } from "./oauthServer.js"
9
-
10
- /**
11
- * HTTP Server factory layer using Node.js http module.
12
- *
13
- * @category Layers
14
- */
15
- export const HttpServerFactoryLive = makeHttpServerFactory(
16
- (options) => NodeHttpServer.layerServer(createServer, options)
17
- )
@@ -1,187 +0,0 @@
1
- /**
2
- * Local HTTP callback server for OAuth2 authorization code capture.
3
- *
4
- * **Mental model**
5
- *
6
- * - **Scope-owned lifecycle**: {@link startCallbackServer} returns a `codePromise`
7
- * (Deferred). The server validates the CSRF `state` parameter, resolves the
8
- * Deferred with the authorization code, and stops when its enclosing scope closes.
9
- * - **Port auto-discovery**: Tries default port 8585, increments on conflict.
10
- *
11
- * @internal
12
- */
13
- import { OAuthError } from "@knpkv/atlassian-common/auth"
14
- import * as Context from "effect/Context"
15
- import * as Deferred from "effect/Deferred"
16
- import * as Effect from "effect/Effect"
17
- import { HttpRouter, HttpServer, HttpServerResponse } from "effect/http"
18
- import type * as HttpServerError from "effect/http/HttpServerError"
19
- import * as Layer from "effect/Layer"
20
- import { NetAddress } from "effect/net"
21
- import * as Schema from "effect/Schema"
22
- import type * as Scope from "effect/Scope"
23
-
24
- const DEFAULT_PORT = 8585
25
- const MAX_PORT = 8594
26
- type HttpServerInstance = Effect.Success<typeof HttpServer.HttpServer>
27
- /**
28
- * Factory service for creating HTTP servers.
29
- * This allows mocking the server creation in tests.
30
- *
31
- * @category Services
32
- */
33
- export interface HttpServerFactory {
34
- readonly createServerLayer: (options: CallbackServerListenOptions) => Layer.Layer<
35
- HttpServer.HttpServer,
36
- HttpServerError.ServeError,
37
- never
38
- >
39
- }
40
-
41
- export interface CallbackServerListenOptions {
42
- readonly host: "localhost"
43
- readonly port: number
44
- }
45
-
46
- export const callbackServerListenOptions = (port: number): CallbackServerListenOptions => ({
47
- host: "localhost",
48
- port
49
- })
50
-
51
- export const callbackUrl = (port: number): string => `http://localhost:${port}/callback`
52
-
53
- /**
54
- * Tag for the HttpServerFactory service.
55
- *
56
- * @category Services
57
- */
58
- export class HttpServerFactoryTag extends Context.Service<
59
- HttpServerFactoryTag,
60
- HttpServerFactory
61
- >()("@knpkv/jira-cli/HttpServerFactory") {}
62
-
63
- /**
64
- * Create a HttpServerFactory layer from a layer factory function.
65
- * This allows injecting platform-specific implementations.
66
- *
67
- * @param createLayerFn - Function that creates HttpServer layer for a given port
68
- * @returns Layer providing HttpServerFactory
69
- *
70
- * @category Layers
71
- */
72
- export const makeHttpServerFactory = (
73
- createLayerFn: (
74
- options: CallbackServerListenOptions
75
- ) => Layer.Layer<HttpServer.HttpServer, HttpServerError.ServeError, never>
76
- ): Layer.Layer<HttpServerFactoryTag> =>
77
- Layer.succeed(HttpServerFactoryTag, {
78
- createServerLayer: createLayerFn
79
- })
80
-
81
- /**
82
- * Result from the OAuth callback server.
83
- */
84
- export interface CallbackServerResult {
85
- /** Promise that resolves with the authorization code */
86
- readonly codePromise: Effect.Effect<string, OAuthError>
87
- /** The port the server is listening on */
88
- readonly port: number
89
- }
90
-
91
- const AddressInUseCause = Schema.Struct({
92
- code: Schema.Literal("EADDRINUSE")
93
- })
94
-
95
- const isAddressInUse = (error: HttpServerError.ServeError): boolean => Schema.is(AddressInUseCause)(error.cause)
96
-
97
- /**
98
- * Start a local HTTP server to receive OAuth callback.
99
- *
100
- * @param expectedState - The state parameter to verify against CSRF
101
- * @returns Server control interface with code promise and port
102
- *
103
- * @category OAuth
104
- */
105
- export const startCallbackServer = (
106
- expectedState: string
107
- ): Effect.Effect<CallbackServerResult, OAuthError, HttpServerFactoryTag | Scope.Scope> =>
108
- Effect.gen(function*() {
109
- const factory = yield* HttpServerFactoryTag
110
- const deferred = yield* Deferred.make<string, OAuthError>()
111
- const serverScope = yield* Effect.scope
112
- const buildServerContext = (port: number): Effect.Effect<
113
- { readonly context: Context.Context<HttpServer.HttpServer>; readonly port: number },
114
- OAuthError
115
- > =>
116
- Layer.buildWithScope(factory.createServerLayer(callbackServerListenOptions(port)), serverScope).pipe(
117
- Effect.map((context) => ({ context, port })),
118
- Effect.catchIf(
119
- (error) => isAddressInUse(error) && port < MAX_PORT,
120
- () => buildServerContext(port + 1)
121
- ),
122
- Effect.mapError((cause) => new OAuthError({ step: "authorize", cause }))
123
- )
124
- const { context: serverContext } = yield* buildServerContext(DEFAULT_PORT)
125
- const server: HttpServerInstance = Context.get(serverContext, HttpServer.HttpServer)
126
- const port = yield* (NetAddress.isInetAddress(server.address)
127
- ? Effect.succeed(server.address.port)
128
- : Effect.fail(new OAuthError({ step: "authorize", cause: "OAuth callback server must listen on a TCP port" })))
129
-
130
- const router = yield* HttpRouter.make
131
- yield* router.add(
132
- "GET",
133
- "/callback",
134
- (req) =>
135
- Effect.gen(function*() {
136
- const url = new URL(req.url, callbackUrl(port))
137
- const code = url.searchParams.get("code")
138
- const state = url.searchParams.get("state")
139
- const error = url.searchParams.get("error")
140
- const errorDescription = url.searchParams.get("error_description")
141
-
142
- if (state !== expectedState) {
143
- return HttpServerResponse.html(
144
- "<html><body><h1>Security Error</h1><p>State verification failed.</p></body></html>"
145
- ).pipe(
146
- HttpServerResponse.setStatus(403)
147
- )
148
- }
149
-
150
- if (error) {
151
- yield* Deferred.fail(
152
- deferred,
153
- new OAuthError({ step: "authorize", cause: errorDescription ?? error })
154
- )
155
- return HttpServerResponse.html(
156
- "<html><body><h1>Authorization Failed</h1><p>You can close this window.</p></body></html>"
157
- )
158
- }
159
-
160
- if (!code) {
161
- yield* Deferred.fail(
162
- deferred,
163
- new OAuthError({ step: "authorize", cause: "No authorization code received" })
164
- )
165
- return HttpServerResponse.html(
166
- "<html><body><h1>Error</h1><p>No authorization code received.</p></body></html>"
167
- )
168
- }
169
-
170
- yield* Deferred.succeed(deferred, code)
171
- return HttpServerResponse.html(
172
- "<html><body><h1>Success!</h1><p>You can close this window and return to the terminal.</p></body></html>"
173
- )
174
- })
175
- )
176
- const app = router.asHttpEffect()
177
-
178
- yield* HttpServer.serveEffect(app).pipe(
179
- Effect.provide(serverContext),
180
- Effect.forkScoped
181
- )
182
-
183
- return {
184
- codePromise: Deferred.await(deferred),
185
- port
186
- }
187
- })
@@ -1,31 +0,0 @@
1
- /**
2
- * Cross-platform browser launcher backed by Effect v4 child process services.
3
- *
4
- * @internal
5
- */
6
- import * as Effect from "effect/Effect"
7
- import type * as PlatformError from "effect/PlatformError"
8
- import { ChildProcess, ChildProcessSpawner } from "effect/process"
9
-
10
- const run = (
11
- command: string,
12
- args: ReadonlyArray<string>
13
- ): Effect.Effect<void, PlatformError.PlatformError, ChildProcessSpawner.ChildProcessSpawner> =>
14
- Effect.gen(function*() {
15
- const spawner = yield* ChildProcessSpawner.ChildProcessSpawner
16
- yield* spawner.exitCode(
17
- ChildProcess.make(command, args, {
18
- stdin: "ignore",
19
- stdout: "ignore",
20
- stderr: "ignore"
21
- })
22
- )
23
- })
24
-
25
- export const openBrowser = (
26
- url: string
27
- ): Effect.Effect<void, PlatformError.PlatformError, ChildProcessSpawner.ChildProcessSpawner> =>
28
- run("open", [url]).pipe(
29
- Effect.catch(() => run("xdg-open", [url])),
30
- Effect.catch(() => run("rundll32.exe", ["url.dll,FileProtocolHandler", url]))
31
- )