@olane/o-server 0.8.13 → 0.8.14
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/middleware/auth.d.ts.map +1 -1
- package/dist/src/middleware/jwt-auth.d.ts.map +1 -1
- package/dist/src/o-server.d.ts.map +1 -1
- package/dist/src/o-server.js +31 -25
- package/dist/src/validation/request-validator.d.ts +2 -20
- package/dist/src/validation/request-validator.d.ts.map +1 -1
- package/package.json +26 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/middleware/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EACL,oBAAoB,EACpB,QAAQ,EACT,MAAM,0CAA0C,CAAC;AAElD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,IAAI,CAAC,EAAE,QAAQ,CAAC;SACjB;KACF;CACF;AAED,wBAAgB,cAAc,CAAC,YAAY,EAAE,oBAAoB,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/middleware/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EACL,oBAAoB,EACpB,QAAQ,EACT,MAAM,0CAA0C,CAAC;AAElD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,IAAI,CAAC,EAAE,QAAQ,CAAC;SACjB;KACF;CACF;AAED,wBAAgB,cAAc,CAAC,YAAY,EAAE,oBAAoB,IACjD,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,mBAe9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt-auth.d.ts","sourceRoot":"","sources":["../../../src/middleware/jwt-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,GAAG,MAAM,cAAc,CAAC;AAI/B;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,uEAAuE;IACvE,MAAM,EAAE,WAAW,GAAG,QAAQ,CAAC;IAE/B,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,0FAA0F;IAC1F,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,qFAAqF;IACrF,UAAU,CAAC,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC;IAE7B,oEAAoE;IACpE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAGD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,GAAG,CAAC,EAAE,UAAU,CAAC;SAClB;KACF;CACF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"jwt-auth.d.ts","sourceRoot":"","sources":["../../../src/middleware/jwt-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QA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M,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"o-server.d.ts","sourceRoot":"","sources":["../../src/o-server.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,YAAY,EACZ,cAAc,EACf,MAAM,yCAAyC,CAAC;AAuBjD,wBAAgB,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,cAAc,CA4W5D"}
|
package/dist/src/o-server.js
CHANGED
|
@@ -4,7 +4,8 @@ import { errorHandler } from './middleware/error-handler.js';
|
|
|
4
4
|
import { authMiddleware } from './middleware/auth.js';
|
|
5
5
|
import { createJwtMiddleware } from './middleware/jwt-auth.js';
|
|
6
6
|
import { ServerLogger } from './utils/logger.js';
|
|
7
|
-
import { oAddress, oRequestContext } from '@olane/o-core';
|
|
7
|
+
import { oAddress, oRequestContext, } from '@olane/o-core';
|
|
8
|
+
import { randomUUID } from 'crypto';
|
|
8
9
|
import { validateAddress, validateMethod, sanitizeParams, validateRequest, useRequestSchema, streamRequestSchema, } from './validation/index.js';
|
|
9
10
|
export function oServer(config) {
|
|
10
11
|
const { node, port = 3000, basePath = '/api/v1', cors: corsConfig, authenticate, jwtAuth, debug = false, } = config;
|
|
@@ -20,9 +21,7 @@ export function oServer(config) {
|
|
|
20
21
|
return undefined;
|
|
21
22
|
// Extract raw token from Authorization header
|
|
22
23
|
const authHeader = req.headers.authorization;
|
|
23
|
-
const token = authHeader?.startsWith('Bearer ')
|
|
24
|
-
? authHeader.slice(7)
|
|
25
|
-
: '';
|
|
24
|
+
const token = authHeader?.startsWith('Bearer ') ? authHeader.slice(7) : '';
|
|
26
25
|
return {
|
|
27
26
|
token,
|
|
28
27
|
claims: req.jwt,
|
|
@@ -35,23 +34,23 @@ export function oServer(config) {
|
|
|
35
34
|
function stripClientAuth(params) {
|
|
36
35
|
if (!params || typeof params !== 'object')
|
|
37
36
|
return params;
|
|
38
|
-
const { _auth, ...rest } = params;
|
|
37
|
+
const { _auth, _trace, ...rest } = params;
|
|
39
38
|
return rest;
|
|
40
39
|
}
|
|
41
40
|
/**
|
|
42
|
-
* Deep-strip _auth from response data before
|
|
43
|
-
* Prevents leaking tokens
|
|
41
|
+
* Deep-strip internal fields (_auth, _trace) from response data before
|
|
42
|
+
* sending to HTTP client. Prevents leaking tokens and trace metadata.
|
|
44
43
|
*/
|
|
45
|
-
function
|
|
44
|
+
function stripInternalFields(obj) {
|
|
46
45
|
if (obj === null || obj === undefined || typeof obj !== 'object')
|
|
47
46
|
return obj;
|
|
48
47
|
if (Array.isArray(obj))
|
|
49
|
-
return obj.map(
|
|
48
|
+
return obj.map(stripInternalFields);
|
|
50
49
|
const result = {};
|
|
51
50
|
for (const key of Object.keys(obj)) {
|
|
52
|
-
if (key === '_auth')
|
|
51
|
+
if (key === '_auth' || key === '_trace')
|
|
53
52
|
continue;
|
|
54
|
-
result[key] =
|
|
53
|
+
result[key] = stripInternalFields(obj[key]);
|
|
55
54
|
}
|
|
56
55
|
return result;
|
|
57
56
|
}
|
|
@@ -109,13 +108,15 @@ export function oServer(config) {
|
|
|
109
108
|
: sanitizedParams;
|
|
110
109
|
logger.debugLog(`Calling use with address ${addressStr}, method: ${method}`);
|
|
111
110
|
const address = new oAddress(addressStr);
|
|
112
|
-
//
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
// Generate a short request ID for tracing across the call chain
|
|
112
|
+
const requestId = randomUUID().replace(/-/g, '').substring(0, 8);
|
|
113
|
+
const store = { requestId };
|
|
114
|
+
if (auth)
|
|
115
|
+
store.auth = auth;
|
|
116
|
+
const result = await oRequestContext.run(store, () => node.use(address, { method, params: finalParams, id }));
|
|
116
117
|
const response = {
|
|
117
118
|
success: true,
|
|
118
|
-
data:
|
|
119
|
+
data: stripInternalFields(result.result),
|
|
119
120
|
};
|
|
120
121
|
res.json(response);
|
|
121
122
|
}
|
|
@@ -147,13 +148,15 @@ export function oServer(config) {
|
|
|
147
148
|
: sanitizedParams;
|
|
148
149
|
logger.debugLog(`Calling method ${method} on ${addressParam} with params:`, sanitizedParams);
|
|
149
150
|
const address = new oAddress(addressStr);
|
|
150
|
-
//
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
// Generate a short request ID for tracing across the call chain
|
|
152
|
+
const requestId = randomUUID().replace(/-/g, '').substring(0, 8);
|
|
153
|
+
const store = { requestId };
|
|
154
|
+
if (auth)
|
|
155
|
+
store.auth = auth;
|
|
156
|
+
const result = await oRequestContext.run(store, () => node.use(address, { method: method, params: finalParams }));
|
|
154
157
|
const response = {
|
|
155
158
|
success: true,
|
|
156
|
-
data:
|
|
159
|
+
data: stripInternalFields(result.result),
|
|
157
160
|
};
|
|
158
161
|
res.json(response);
|
|
159
162
|
}
|
|
@@ -187,15 +190,18 @@ export function oServer(config) {
|
|
|
187
190
|
res.setHeader('Cache-Control', 'no-cache');
|
|
188
191
|
res.setHeader('Connection', 'keep-alive');
|
|
189
192
|
const address = new oAddress(addressStr);
|
|
193
|
+
// Generate a short request ID for tracing across the call chain
|
|
194
|
+
const requestId = randomUUID().replace(/-/g, '').substring(0, 8);
|
|
195
|
+
const store = { requestId };
|
|
196
|
+
if (auth)
|
|
197
|
+
store.auth = auth;
|
|
190
198
|
try {
|
|
191
199
|
// TODO: Implement actual streaming support when available
|
|
192
200
|
// For now, execute and return result
|
|
193
|
-
const result = await (
|
|
194
|
-
? oRequestContext.run({ auth }, () => node.use(address, { method, params: finalParams }))
|
|
195
|
-
: node.use(address, { method, params: finalParams }));
|
|
201
|
+
const result = await oRequestContext.run(store, () => node.use(address, { method, params: finalParams }));
|
|
196
202
|
res.write(`data: ${JSON.stringify({
|
|
197
203
|
type: 'complete',
|
|
198
|
-
result:
|
|
204
|
+
result: stripInternalFields(result.result),
|
|
199
205
|
})}\n\n`);
|
|
200
206
|
res.end();
|
|
201
207
|
}
|
|
@@ -8,17 +8,7 @@ export declare const useRequestSchema: z.ZodObject<{
|
|
|
8
8
|
method: z.ZodString;
|
|
9
9
|
params: z.ZodOptional<z.ZodAny>;
|
|
10
10
|
id: z.ZodOptional<z.ZodString>;
|
|
11
|
-
},
|
|
12
|
-
address: string;
|
|
13
|
-
method: string;
|
|
14
|
-
params?: any;
|
|
15
|
-
id?: string | undefined;
|
|
16
|
-
}, {
|
|
17
|
-
address: string;
|
|
18
|
-
method: string;
|
|
19
|
-
params?: any;
|
|
20
|
-
id?: string | undefined;
|
|
21
|
-
}>;
|
|
11
|
+
}, z.core.$strip>;
|
|
22
12
|
/**
|
|
23
13
|
* Schema for POST /:address/:method endpoint
|
|
24
14
|
* This endpoint accepts any body as params
|
|
@@ -32,15 +22,7 @@ export declare const streamRequestSchema: z.ZodObject<{
|
|
|
32
22
|
address: z.ZodString;
|
|
33
23
|
method: z.ZodString;
|
|
34
24
|
params: z.ZodOptional<z.ZodAny>;
|
|
35
|
-
},
|
|
36
|
-
address: string;
|
|
37
|
-
method: string;
|
|
38
|
-
params?: any;
|
|
39
|
-
}, {
|
|
40
|
-
address: string;
|
|
41
|
-
method: string;
|
|
42
|
-
params?: any;
|
|
43
|
-
}>;
|
|
25
|
+
}, z.core.$strip>;
|
|
44
26
|
/**
|
|
45
27
|
* Validates request data against a Zod schema
|
|
46
28
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-validator.d.ts","sourceRoot":"","sources":["../../../src/validation/request-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;GAGG;AACH,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"request-validator.d.ts","sourceRoot":"","sources":["../../../src/validation/request-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;iBAK3B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,wBAAwB,UAAU,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;;iBAI9B,CAAC;AAEH;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAqB3E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olane/o-server",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -34,40 +34,40 @@
|
|
|
34
34
|
"license": "(MIT OR Apache-2.0)",
|
|
35
35
|
"description": "HTTP server entrypoint for Olane OS nodes - exposes node's 'use' functionality via REST API",
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@eslint/eslintrc": "^3.3.
|
|
38
|
-
"@eslint/js": "^
|
|
39
|
-
"@tsconfig/node20": "^20.1.
|
|
40
|
-
"@types/cors": "^2.8.
|
|
41
|
-
"@types/express": "^
|
|
37
|
+
"@eslint/eslintrc": "^3.3.4",
|
|
38
|
+
"@eslint/js": "^10.0.1",
|
|
39
|
+
"@tsconfig/node20": "^20.1.9",
|
|
40
|
+
"@types/cors": "^2.8.19",
|
|
41
|
+
"@types/express": "^5.0.6",
|
|
42
42
|
"@types/jest": "^30.0.0",
|
|
43
43
|
"@types/jsonwebtoken": "^9.0.10",
|
|
44
44
|
"@types/mocha": "^10.0.10",
|
|
45
|
-
"@types/node": "^
|
|
45
|
+
"@types/node": "^25.3.0",
|
|
46
46
|
"@types/supertest": "^6.0.3",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
48
|
-
"@typescript-eslint/parser": "^8.
|
|
49
|
-
"aegir": "^47.0.
|
|
50
|
-
"eslint": "^
|
|
51
|
-
"eslint-config-prettier": "^10.1.
|
|
52
|
-
"eslint-plugin-prettier": "^5.5.
|
|
53
|
-
"globals": "^
|
|
54
|
-
"jest": "^30.
|
|
55
|
-
"prettier": "^3.
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.56.1",
|
|
48
|
+
"@typescript-eslint/parser": "^8.56.1",
|
|
49
|
+
"aegir": "^47.0.26",
|
|
50
|
+
"eslint": "^10.0.2",
|
|
51
|
+
"eslint-config-prettier": "^10.1.8",
|
|
52
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
53
|
+
"globals": "^17.3.0",
|
|
54
|
+
"jest": "^30.2.0",
|
|
55
|
+
"prettier": "^3.8.1",
|
|
56
56
|
"supertest": "^7.2.2",
|
|
57
|
-
"ts-jest": "^29.4.
|
|
57
|
+
"ts-jest": "^29.4.6",
|
|
58
58
|
"ts-node": "^10.9.2",
|
|
59
59
|
"tsconfig-paths": "^4.2.0",
|
|
60
|
-
"tsx": "^4.
|
|
61
|
-
"typescript": "5.
|
|
60
|
+
"tsx": "^4.21.0",
|
|
61
|
+
"typescript": "5.9.3"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@olane/o-core": "0.8.
|
|
65
|
-
"cors": "^2.8.
|
|
66
|
-
"debug": "^4.4.
|
|
67
|
-
"dotenv": "^
|
|
68
|
-
"express": "^
|
|
64
|
+
"@olane/o-core": "0.8.14",
|
|
65
|
+
"cors": "^2.8.6",
|
|
66
|
+
"debug": "^4.4.3",
|
|
67
|
+
"dotenv": "^17.3.1",
|
|
68
|
+
"express": "^5.2.1",
|
|
69
69
|
"jsonwebtoken": "^9.0.3",
|
|
70
|
-
"zod": "^3.
|
|
70
|
+
"zod": "^4.3.6"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "c7df897d10e7c8078255701043f1887e48ccdd84"
|
|
73
73
|
}
|