@envseal/http-server 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined in Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or Object
36
+ form, made available under the License, as indicated by a copyright
37
+ notice that is included in or attached to the work (an example is
38
+ provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original Work and any Derivative Works thereof, that is
50
+ intentionally submitted to, or received by, Licensor for inclusion
51
+ in the Work by the copyright owner or by an individual or Legal
52
+ Entity authorized to submit on behalf of the copyright owner. For
53
+ the purposes of this definition, "submitted" means any form of
54
+ electronic, verbal, or written communication sent to the Licensor
55
+ or its representatives, including but not limited to communication
56
+ on electronic mailing lists, source code control systems, and issue
57
+ tracking systems that are managed by, or on behalf of, the Licensor
58
+ for the purpose of discussing and improving the Work, but excluding
59
+ communication that is conspicuously marked or otherwise designated
60
+ in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
63
+ which a Contribution has been received by Licensor and subsequently
64
+ incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file, then any
107
+ Derivative Works that You distribute must include a readable
108
+ copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE from the Work, provided that
120
+ such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions of this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contribution.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in appropriate
184
+ comment syntax for the file type. We also recommend that you
185
+ include a file or class name and date of last modification in
186
+ the header comment to make it easier to identify the original
187
+ author and when the file was changed.
188
+
189
+ Copyright 2026 The envseal authors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,3 @@
1
+ export { startHttpServer } from './server.js';
2
+ export type { HttpServerOptions } from './server.js';
3
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { startHttpServer } from './server.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export declare function generateOpenAPI(port: number): unknown;
2
+ //# sourceMappingURL=openapi.d.ts.map
@@ -0,0 +1,105 @@
1
+ import { zodToJsonSchema } from 'zod-to-json-schema';
2
+ import { SEP_TOOL_NAMES, INPUT_SCHEMAS } from '@envseal/protocol';
3
+ export function generateOpenAPI(port) {
4
+ const paths = {};
5
+ for (const toolName of SEP_TOOL_NAMES) {
6
+ const schema = INPUT_SCHEMAS[toolName];
7
+ const jsonSchema = zodToJsonSchema(schema);
8
+ paths[`/v1/${toolName}`] = {
9
+ post: {
10
+ summary: `Call ${toolName}`,
11
+ requestBody: {
12
+ required: true,
13
+ content: {
14
+ 'application/json': {
15
+ schema: jsonSchema,
16
+ },
17
+ },
18
+ },
19
+ responses: {
20
+ 200: {
21
+ description: 'Success',
22
+ content: {
23
+ 'application/json': {
24
+ schema: {
25
+ type: 'object',
26
+ additionalProperties: true,
27
+ },
28
+ },
29
+ },
30
+ },
31
+ 400: {
32
+ description: 'Bad request',
33
+ content: {
34
+ 'application/json': {
35
+ schema: {
36
+ type: 'object',
37
+ properties: {
38
+ error: {
39
+ type: 'object',
40
+ properties: {
41
+ code: { type: 'string' },
42
+ userMessage: { type: 'string' },
43
+ retriable: { type: 'boolean' },
44
+ },
45
+ },
46
+ },
47
+ },
48
+ },
49
+ },
50
+ },
51
+ 401: {
52
+ description: 'Unauthorized',
53
+ content: {
54
+ 'application/json': {
55
+ schema: {
56
+ type: 'object',
57
+ properties: {
58
+ error: {
59
+ type: 'object',
60
+ properties: {
61
+ code: { type: 'string' },
62
+ userMessage: { type: 'string' },
63
+ retriable: { type: 'boolean' },
64
+ },
65
+ },
66
+ },
67
+ },
68
+ },
69
+ },
70
+ },
71
+ },
72
+ },
73
+ };
74
+ }
75
+ return {
76
+ openapi: '3.1.0',
77
+ info: {
78
+ title: 'envseal SEP/1',
79
+ version: '1.0.0',
80
+ description: 'Secret Elicitation Protocol - secure credential collection for AI agents',
81
+ },
82
+ servers: [
83
+ {
84
+ url: `http://127.0.0.1:${port}`,
85
+ description: 'Loopback server (127.0.0.1 only)',
86
+ },
87
+ ],
88
+ paths,
89
+ components: {
90
+ securitySchemes: {
91
+ bearerAuth: {
92
+ type: 'http',
93
+ scheme: 'bearer',
94
+ bearerFormat: 'custom',
95
+ },
96
+ },
97
+ },
98
+ security: [
99
+ {
100
+ bearerAuth: [],
101
+ },
102
+ ],
103
+ };
104
+ }
105
+ //# sourceMappingURL=openapi.js.map
@@ -0,0 +1,21 @@
1
+ import type { Prompter } from '@envseal/prompters';
2
+ export interface HttpServerOptions {
3
+ root: string;
4
+ port?: number;
5
+ token?: string;
6
+ /**
7
+ * Surface used to ask the user for env_use confirmation and for consent
8
+ * before a non-allowlisted verify probe. Defaults to selectPrompter(), which
9
+ * resolves to `none` in CI -- there those two operations fail with
10
+ * SEP_NO_INTERACTIVE_SURFACE rather than running unattended.
11
+ */
12
+ prompter?: Prompter;
13
+ }
14
+ interface StartResult {
15
+ url: string;
16
+ token: string;
17
+ close(): Promise<void>;
18
+ }
19
+ export declare function startHttpServer(opts: HttpServerOptions): Promise<StartResult>;
20
+ export {};
21
+ //# sourceMappingURL=server.d.ts.map
package/dist/server.js ADDED
@@ -0,0 +1,288 @@
1
+ import * as node_http from 'node:http';
2
+ import * as node_crypto from 'node:crypto';
3
+ import * as node_fs from 'node:fs';
4
+ import * as node_os from 'node:os';
5
+ import * as node_path from 'node:path';
6
+ import { Broker } from '@envseal/core';
7
+ import { createProbeApproval, createUseConfirm, dispatch, isSepToolName } from '@envseal/sdk';
8
+ import { selectPrompter } from '@envseal/prompters';
9
+ import { generateOpenAPI } from './openapi.js';
10
+ async function getOrCreateToken(token) {
11
+ if (token) {
12
+ return token;
13
+ }
14
+ const tokenDir = node_path.join(node_os.homedir(), '.envseal');
15
+ const tokenFile = node_path.join(tokenDir, 'api-token');
16
+ // Create directory if needed
17
+ if (!node_fs.existsSync(tokenDir)) {
18
+ node_fs.mkdirSync(tokenDir, { recursive: true, mode: 0o700 });
19
+ }
20
+ // Check if token file exists
21
+ if (node_fs.existsSync(tokenFile)) {
22
+ const tokenBuf = node_fs.readFileSync(tokenFile);
23
+ return tokenBuf.toString('utf8').trim();
24
+ }
25
+ // Generate new token (32 random bytes as hex)
26
+ const randomBytes = node_crypto.randomBytes(32);
27
+ const newToken = randomBytes.toString('hex');
28
+ // Write with 0o600 permissions
29
+ node_fs.writeFileSync(tokenFile, newToken, { mode: 0o600 });
30
+ return newToken;
31
+ }
32
+ /**
33
+ * Constant-time bearer token check. Shared by the /v1 route auth and the
34
+ * /openapi.json route (N5): the spec used to be served BEFORE the auth check,
35
+ * so any loopback process could read the API surface without the token.
36
+ */
37
+ function bearerTokenMatches(authorization, token) {
38
+ const authHeader = authorization ?? '';
39
+ const bearerPrefix = 'Bearer ';
40
+ if (!authHeader.startsWith(bearerPrefix)) {
41
+ return false;
42
+ }
43
+ const providedToken = authHeader.slice(bearerPrefix.length);
44
+ // Use timing-safe comparison
45
+ const expectedTokenBuf = Buffer.from(token, 'utf8');
46
+ const providedTokenBuf = Buffer.from(providedToken, 'utf8');
47
+ try {
48
+ return (expectedTokenBuf.length === providedTokenBuf.length &&
49
+ node_crypto.timingSafeEqual(expectedTokenBuf, providedTokenBuf));
50
+ }
51
+ catch {
52
+ return false;
53
+ }
54
+ }
55
+ export async function startHttpServer(opts) {
56
+ const token = await getOrCreateToken(opts.token);
57
+ const prompter = opts.prompter ?? (await selectPrompter());
58
+ const surface = { projectRoot: opts.root, prompter: async () => prompter };
59
+ const broker = new Broker({
60
+ root: opts.root,
61
+ prompter,
62
+ // /v1/env_use is in the OpenAPI document. Without onConfirm the broker has
63
+ // no way to ask anyone, and exec.ts reports the missing callback as "the
64
+ // user denied the confirmation" for a user who was never asked.
65
+ onConfirm: createUseConfirm(surface),
66
+ // PLAN.md §6.4 probe consent, supplied by no binding before this.
67
+ onApprovalNeeded: createProbeApproval(surface),
68
+ });
69
+ let server = null;
70
+ let actualPort = 0;
71
+ const requestHandler = async (req, res) => {
72
+ // Common response headers
73
+ res.setHeader('Cache-Control', 'no-store');
74
+ res.setHeader('X-Content-Type-Options', 'nosniff');
75
+ res.setHeader('Content-Type', 'application/json');
76
+ // Enforce Host header (DNS rebinding defense)
77
+ const hostHeader = req.headers.host;
78
+ const expectedHost = `127.0.0.1:${actualPort}`;
79
+ if (hostHeader !== expectedHost) {
80
+ res.writeHead(400);
81
+ res.end(JSON.stringify({
82
+ error: {
83
+ code: 'INVALID_HOST',
84
+ userMessage: 'Invalid Host header',
85
+ retriable: false,
86
+ },
87
+ }));
88
+ return;
89
+ }
90
+ // Reject requests carrying an Origin header at all (CORS defense).
91
+ //
92
+ // Deliberately stricter than the loopback prompter, which must accept the
93
+ // `Origin: null` a real browser sends on its own form post. Nothing here is
94
+ // ever fetched by a browser page, so any Origin is a browser reaching a
95
+ // surface it has no business on.
96
+ //
97
+ // `!== undefined`, not truthiness: `Origin:` with an empty value is a
98
+ // present header, and the old check let it straight through (W3-06).
99
+ if (req.headers.origin !== undefined) {
100
+ res.writeHead(400);
101
+ res.end(JSON.stringify({
102
+ error: {
103
+ code: 'INVALID_ORIGIN',
104
+ userMessage: 'Origin header not allowed',
105
+ retriable: false,
106
+ },
107
+ }));
108
+ return;
109
+ }
110
+ // Handle GET /openapi.json — authenticated like every other route (N5).
111
+ // The document carries no secrets, but an unauthenticated read let any
112
+ // loopback process fingerprint the deployment's full route table, and no
113
+ // caller in this repository depends on the anonymous read.
114
+ if (req.method === 'GET' && req.url === '/openapi.json') {
115
+ if (!bearerTokenMatches(req.headers.authorization, token)) {
116
+ res.writeHead(401);
117
+ res.end(JSON.stringify({
118
+ error: {
119
+ code: 'UNAUTHORIZED',
120
+ userMessage: 'Missing or invalid authorization',
121
+ retriable: false,
122
+ },
123
+ }));
124
+ return;
125
+ }
126
+ const openapi = generateOpenAPI(actualPort);
127
+ res.writeHead(200);
128
+ res.end(JSON.stringify(openapi));
129
+ return;
130
+ }
131
+ // All other routes require POST and Bearer token auth
132
+ if (req.method !== 'POST') {
133
+ res.writeHead(405);
134
+ res.end(JSON.stringify({
135
+ error: {
136
+ code: 'METHOD_NOT_ALLOWED',
137
+ userMessage: 'Method not allowed',
138
+ retriable: false,
139
+ },
140
+ }));
141
+ return;
142
+ }
143
+ // Check Authorization header
144
+ const authHeader = req.headers.authorization ?? '';
145
+ const bearerPrefix = 'Bearer ';
146
+ if (!authHeader.startsWith(bearerPrefix)) {
147
+ res.writeHead(401);
148
+ res.end(JSON.stringify({
149
+ error: {
150
+ code: 'UNAUTHORIZED',
151
+ userMessage: 'Missing or invalid authorization',
152
+ retriable: false,
153
+ },
154
+ }));
155
+ return;
156
+ }
157
+ if (!bearerTokenMatches(authHeader, token)) {
158
+ res.writeHead(401);
159
+ res.end(JSON.stringify({
160
+ error: {
161
+ code: 'UNAUTHORIZED',
162
+ userMessage: 'Invalid token',
163
+ retriable: false,
164
+ },
165
+ }));
166
+ return;
167
+ }
168
+ // Parse URL to get operation name
169
+ const urlPath = req.url ?? '/';
170
+ const match = urlPath.match(/^\/v1\/([a-z_]+)$/);
171
+ if (!match || !match[1]) {
172
+ res.writeHead(404);
173
+ res.end(JSON.stringify({
174
+ error: {
175
+ code: 'NOT_FOUND',
176
+ userMessage: 'Endpoint not found',
177
+ retriable: false,
178
+ },
179
+ }));
180
+ return;
181
+ }
182
+ const operationName = match[1];
183
+ // An unknown operation is a routing failure, not a result. It used to reach
184
+ // dispatch(), which answered with an error body under HTTP 200 -- so a
185
+ // client saw success for an endpoint that does not exist (F32). Checked
186
+ // after auth so an unauthenticated caller cannot map the route table.
187
+ if (!isSepToolName(operationName)) {
188
+ res.writeHead(404);
189
+ res.end(JSON.stringify({
190
+ error: {
191
+ code: 'SEP_UNKNOWN_KEY',
192
+ userMessage: `Unknown operation: ${operationName}`,
193
+ retriable: false,
194
+ },
195
+ }));
196
+ return;
197
+ }
198
+ // Read and validate body
199
+ const chunks = [];
200
+ let bodySize = 0;
201
+ const MAX_BODY_SIZE = 1024 * 1024; // 1 MiB
202
+ for await (const chunk of req) {
203
+ bodySize += chunk.length;
204
+ if (bodySize > MAX_BODY_SIZE) {
205
+ res.writeHead(413);
206
+ res.end(JSON.stringify({
207
+ error: {
208
+ code: 'PAYLOAD_TOO_LARGE',
209
+ userMessage: 'Request body too large',
210
+ retriable: false,
211
+ },
212
+ }));
213
+ return;
214
+ }
215
+ chunks.push(chunk);
216
+ }
217
+ let body;
218
+ try {
219
+ const bodyText = Buffer.concat(chunks).toString('utf8');
220
+ body = bodyText ? JSON.parse(bodyText) : {};
221
+ }
222
+ catch {
223
+ res.writeHead(400);
224
+ res.end(JSON.stringify({
225
+ error: {
226
+ code: 'INVALID_JSON',
227
+ userMessage: 'Invalid JSON in request body',
228
+ retriable: false,
229
+ },
230
+ }));
231
+ return;
232
+ }
233
+ // Dispatch to SDK
234
+ try {
235
+ const result = await dispatch(broker, operationName, body);
236
+ res.writeHead(200);
237
+ res.end(JSON.stringify(result));
238
+ }
239
+ catch (error) {
240
+ res.writeHead(500);
241
+ res.end(JSON.stringify({
242
+ error: {
243
+ code: 'INTERNAL_ERROR',
244
+ userMessage: 'An error occurred',
245
+ retriable: false,
246
+ },
247
+ }));
248
+ }
249
+ };
250
+ return new Promise((resolve, reject) => {
251
+ server = node_http.createServer(requestHandler);
252
+ server.listen(opts.port ?? 0, '127.0.0.1', () => {
253
+ if (!server) {
254
+ reject(new Error('Server not created'));
255
+ return;
256
+ }
257
+ const addr = server.address();
258
+ if (!addr || typeof addr === 'string') {
259
+ reject(new Error('Could not get server address'));
260
+ return;
261
+ }
262
+ actualPort = addr.port;
263
+ const url = `http://127.0.0.1:${actualPort}`;
264
+ resolve({
265
+ url,
266
+ token,
267
+ close: async () => {
268
+ return new Promise((closeResolve, closeReject) => {
269
+ if (!server) {
270
+ closeResolve();
271
+ return;
272
+ }
273
+ server.close((err) => {
274
+ if (err) {
275
+ closeReject(err);
276
+ }
277
+ else {
278
+ closeResolve();
279
+ }
280
+ });
281
+ });
282
+ },
283
+ });
284
+ });
285
+ server.on('error', reject);
286
+ });
287
+ }
288
+ //# sourceMappingURL=server.js.map
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@envseal/http-server",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "Apache-2.0",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "!dist/**/*.map"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public",
20
+ "provenance": true
21
+ },
22
+ "dependencies": {
23
+ "zod-to-json-schema": "^3.24.1",
24
+ "@envseal/prompters": "0.1.0",
25
+ "@envseal/protocol": "0.1.0",
26
+ "@envseal/sdk": "0.1.0",
27
+ "@envseal/core": "0.1.0"
28
+ },
29
+ "devDependencies": {
30
+ "vitest": "^2.1.8"
31
+ },
32
+ "scripts": {
33
+ "build": "tsc -p tsconfig.json",
34
+ "typecheck": "tsc -p tsconfig.json --noEmit",
35
+ "test": "vitest run"
36
+ }
37
+ }