@fougere/transport-http 0.16.8-alpha.0 → 0.17.0-alpha.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/dist/client.js +14 -14
- package/dist/client.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +12 -14
- package/dist/server.js.map +1 -1
- package/package.json +5 -5
- package/src/client.ts +14 -14
- package/src/server.ts +12 -14
package/dist/client.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { FougereError, ErrorCode, maxBodyBytes, maxFrameBytes } from '@fougere/core/contract';
|
|
3
3
|
/** Frame a call as a JSON-RPC request. */
|
|
4
4
|
export function frameCall(call, invocation, id) {
|
|
5
|
-
return { jsonrpc: '2.0', id, method: `${call.
|
|
5
|
+
return { jsonrpc: '2.0', id, method: `${call.address}.${call.op}`, params: invocation };
|
|
6
6
|
}
|
|
7
7
|
/** Unframe a JSON-RPC response — the result, or the revived FougereError thrown. */
|
|
8
8
|
export function unframeResponse(response, call) {
|
|
@@ -10,7 +10,7 @@ export function unframeResponse(response, call) {
|
|
|
10
10
|
throw new FougereError({
|
|
11
11
|
code: ErrorCode.BAD_GATEWAY,
|
|
12
12
|
message: 'Answered neither a result nor an error — not a Fougere receiver?',
|
|
13
|
-
|
|
13
|
+
address: call.address,
|
|
14
14
|
operation: call.op,
|
|
15
15
|
});
|
|
16
16
|
}
|
|
@@ -20,7 +20,7 @@ export function unframeResponse(response, call) {
|
|
|
20
20
|
throw new FougereError({
|
|
21
21
|
code: ErrorCode.BAD_GATEWAY,
|
|
22
22
|
message: 'Answered an error that is not a JSON-RPC error object',
|
|
23
|
-
|
|
23
|
+
address: call.address,
|
|
24
24
|
operation: call.op,
|
|
25
25
|
});
|
|
26
26
|
}
|
|
@@ -29,7 +29,7 @@ export function unframeResponse(response, call) {
|
|
|
29
29
|
throw new FougereError({
|
|
30
30
|
code: ErrorCode.INTERNAL_ERROR,
|
|
31
31
|
message: `${error.message} (rpc ${error.code})`,
|
|
32
|
-
|
|
32
|
+
address: call.address,
|
|
33
33
|
operation: call.op,
|
|
34
34
|
});
|
|
35
35
|
}
|
|
@@ -78,9 +78,9 @@ export function createHttpTransport(baseUrl, options = {}) {
|
|
|
78
78
|
if (isTimeout(err)) {
|
|
79
79
|
throw new FougereError({
|
|
80
80
|
code: ErrorCode.GATEWAY_TIMEOUT,
|
|
81
|
-
message: `${call.
|
|
81
|
+
message: `${call.address}.${call.op} timed out after ${timeoutMs}ms`,
|
|
82
82
|
cause: new Error(`${baseUrl} did not answer in ${timeoutMs}ms`),
|
|
83
|
-
|
|
83
|
+
address: call.address,
|
|
84
84
|
operation: call.op,
|
|
85
85
|
});
|
|
86
86
|
}
|
|
@@ -88,8 +88,8 @@ export function createHttpTransport(baseUrl, options = {}) {
|
|
|
88
88
|
continue;
|
|
89
89
|
throw new FougereError({
|
|
90
90
|
code: ErrorCode.SERVICE_UNAVAILABLE,
|
|
91
|
-
message: `${call.
|
|
92
|
-
|
|
91
|
+
message: `${call.address}.${call.op}: the process serving it is unreachable`,
|
|
92
|
+
address: call.address,
|
|
93
93
|
operation: call.op,
|
|
94
94
|
cause: new Error(`${baseUrl} unreachable: ${err?.message ?? err}`, { cause: err }),
|
|
95
95
|
});
|
|
@@ -99,9 +99,9 @@ export function createHttpTransport(baseUrl, options = {}) {
|
|
|
99
99
|
if (!res.ok) {
|
|
100
100
|
throw new FougereError({
|
|
101
101
|
code: ErrorCode.BAD_GATEWAY,
|
|
102
|
-
message: `${call.
|
|
102
|
+
message: `${call.address}.${call.op}: the receiver answered HTTP ${res.status} — not a Fougere receiver?`,
|
|
103
103
|
cause: new Error(`${baseUrl} answered HTTP ${res.status}`),
|
|
104
|
-
|
|
104
|
+
address: call.address,
|
|
105
105
|
operation: call.op,
|
|
106
106
|
});
|
|
107
107
|
}
|
|
@@ -112,9 +112,9 @@ export function createHttpTransport(baseUrl, options = {}) {
|
|
|
112
112
|
catch {
|
|
113
113
|
throw new FougereError({
|
|
114
114
|
code: ErrorCode.BAD_GATEWAY,
|
|
115
|
-
message: `${call.
|
|
115
|
+
message: `${call.address}.${call.op}: the receiver answered non-JSON`,
|
|
116
116
|
cause: new Error(`${baseUrl} answered non-JSON`),
|
|
117
|
-
|
|
117
|
+
address: call.address,
|
|
118
118
|
operation: call.op,
|
|
119
119
|
});
|
|
120
120
|
}
|
|
@@ -126,9 +126,9 @@ export function createHttpTransport(baseUrl, options = {}) {
|
|
|
126
126
|
function tooLarge(call, baseUrl) {
|
|
127
127
|
return new FougereError({
|
|
128
128
|
code: ErrorCode.PAYLOAD_TOO_LARGE,
|
|
129
|
-
message: `${call.
|
|
129
|
+
message: `${call.address}.${call.op} carries more than the ${maxBodyBytes()} bytes a caller may send (maxBodyBytes).`,
|
|
130
130
|
cause: new Error(`refused for ${baseUrl}`),
|
|
131
|
-
|
|
131
|
+
address: call.address,
|
|
132
132
|
operation: call.op,
|
|
133
133
|
});
|
|
134
134
|
}
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAA2E,MAAM,wBAAwB,CAAC;AAMvK,0CAA0C;AAC1C,MAAM,UAAU,SAAS,CAAC,IAAe,EAAE,UAA6B,EAAE,EAAU;IAClF,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAA2E,MAAM,wBAAwB,CAAC;AAMvK,0CAA0C;AAC1C,MAAM,UAAU,SAAS,CAAC,IAAe,EAAE,UAA6B,EAAE,EA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AK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;IAClH;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,OAAO,EAAkE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGzI,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D,uDAAuD;AACvD,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,KAAK,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;IAClH;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,WAAW,CAAC,CA0EnH"}
|
package/dist/server.js
CHANGED
|
@@ -12,10 +12,10 @@ export async function handleRpc(runner, raw, options = {}) {
|
|
|
12
12
|
return {
|
|
13
13
|
jsonrpc: '2.0',
|
|
14
14
|
id,
|
|
15
|
-
error: { code: INVALID_REQUEST, message: `Invalid method '${req.method}' — expected '
|
|
15
|
+
error: { code: INVALID_REQUEST, message: `Invalid method '${req.method}' — expected 'address.op'` },
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
const
|
|
18
|
+
const address = req.method.slice(0, dot);
|
|
19
19
|
const op = req.method.slice(dot + 1);
|
|
20
20
|
// Fresh objects — middlewares deposit into state, nothing may be shared.
|
|
21
21
|
const sent = (req.params ?? {});
|
|
@@ -23,16 +23,14 @@ export async function handleRpc(runner, raw, options = {}) {
|
|
|
23
23
|
.filter(([key, value]) => value !== undefined && !SENT[key])
|
|
24
24
|
.map(([key]) => key);
|
|
25
25
|
if (strangers.length > 0)
|
|
26
|
-
return malformed(id, strangers,
|
|
26
|
+
return malformed(id, strangers, address, op);
|
|
27
27
|
/** State is ESTABLISHED here, or it is only claimed. */
|
|
28
28
|
let state = sent.state ?? {};
|
|
29
29
|
let caller;
|
|
30
30
|
if (options.verify && sent.identity) {
|
|
31
31
|
try {
|
|
32
32
|
// What ARRIVED, never what we would rather it had been — the comparison is the point.
|
|
33
|
-
({ caller, state } = await options.verify(sent.identity, {
|
|
34
|
-
entity,
|
|
35
|
-
op,
|
|
33
|
+
({ caller, state } = await options.verify(sent.identity, { address, op,
|
|
36
34
|
params: sent.params ?? {},
|
|
37
35
|
query: sent.query ?? {},
|
|
38
36
|
input: sent.input,
|
|
@@ -40,11 +38,11 @@ export async function handleRpc(runner, raw, options = {}) {
|
|
|
40
38
|
}));
|
|
41
39
|
}
|
|
42
40
|
catch (err) {
|
|
43
|
-
return refused(id, err?.message ?? 'unverifiable identity',
|
|
41
|
+
return refused(id, err?.message ?? 'unverifiable identity', address, op);
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
else if (options.requireIdentity) {
|
|
47
|
-
return refused(id, 'this receiver takes signed calls only',
|
|
45
|
+
return refused(id, 'this receiver takes signed calls only', address, op);
|
|
48
46
|
}
|
|
49
47
|
// Built field by field, never spread from `sent`: everything here is either validated
|
|
50
48
|
// above or carried deliberately, and `caller` is ours to write alone.
|
|
@@ -59,7 +57,7 @@ export async function handleRpc(runner, raw, options = {}) {
|
|
|
59
57
|
crossed: true,
|
|
60
58
|
};
|
|
61
59
|
try {
|
|
62
|
-
return { jsonrpc: '2.0', id, result: await runner({
|
|
60
|
+
return { jsonrpc: '2.0', id, result: await runner({ address, op }, invocation) };
|
|
63
61
|
}
|
|
64
62
|
catch (err) {
|
|
65
63
|
const failure = err instanceof FougereError
|
|
@@ -67,7 +65,7 @@ export async function handleRpc(runner, raw, options = {}) {
|
|
|
67
65
|
: new FougereError({
|
|
68
66
|
code: ErrorCode.INTERNAL_ERROR,
|
|
69
67
|
message: err?.message ?? 'Internal error',
|
|
70
|
-
|
|
68
|
+
address,
|
|
71
69
|
operation: op,
|
|
72
70
|
cause: err,
|
|
73
71
|
});
|
|
@@ -84,19 +82,19 @@ const SENT = {
|
|
|
84
82
|
params: true, query: true, input: true, state: true, trace: true, identity: true, runAt: true, caller: false,
|
|
85
83
|
crossed: false,
|
|
86
84
|
};
|
|
87
|
-
function malformed(id, strangers,
|
|
85
|
+
function malformed(id, strangers, address, op) {
|
|
88
86
|
const admitted = Object.keys(SENT).filter((key) => SENT[key]);
|
|
89
87
|
const data = toPublicError(new FougereError({
|
|
90
88
|
code: ErrorCode.BAD_REQUEST,
|
|
91
89
|
message: `Unknown invocation member ${strangers.map((key) => `'${key}'`).join(', ')} — one of ${admitted.join(', ')}.`,
|
|
92
|
-
|
|
90
|
+
address,
|
|
93
91
|
operation: op,
|
|
94
92
|
}));
|
|
95
93
|
return { jsonrpc: '2.0', id, error: { code: APP_ERROR, message: data.message, data } };
|
|
96
94
|
}
|
|
97
95
|
/** An admission refusal, framed like any other failure so a caller reads one vocabulary. */
|
|
98
|
-
function refused(id, why,
|
|
99
|
-
const data = toPublicError(new FougereError({ code: ErrorCode.UNAUTHORIZED, message: `Refused: ${why}`,
|
|
96
|
+
function refused(id, why, address, op) {
|
|
97
|
+
const data = toPublicError(new FougereError({ code: ErrorCode.UNAUTHORIZED, message: `Refused: ${why}`, address, operation: op }));
|
|
100
98
|
return { jsonrpc: '2.0', id, error: { code: APP_ERROR, message: data.message, data } };
|
|
101
99
|
}
|
|
102
100
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAA2D,MAAM,wBAAwB,CAAC;AACzI,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAcxE,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAiB,EAAE,GAAY,EAAE,OAAO,GAAmB,EAAE;IAC3F,MAAM,GAAG,GAAG,GAAiC,CAAC;IAC9C,MAAM,EAAE,GAAG,OAAO,GAAG,EAAE,EAAE,KAAK,QAAQ,IAAI,OAAO,GAAG,EAAE,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAEtF,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,KAAK,KAAK,IAAI,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;QACnF,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,8BAA8B,EAAE,EAAE,CAAC;IAC3G,CAAC;IAED,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACpC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,KAAK,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9C,OAAO;YACL,OAAO,EAAE,KAAK;YACd,EAAE;YACF,KAAK,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,mBAAmB,GAAG,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"m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,SAAS,CAAC,YAAY,EAAE,OAAO,EAAE,YAAY,GAAG,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CACvG,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;AACzF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fougere/transport-http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0-alpha.0",
|
|
4
4
|
"description": "The call contract on the wire, in JSON-RPC 2.0 (server + client).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fougere",
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"src"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@fougere/core": "0.
|
|
41
|
+
"@fougere/core": "0.17.0-alpha.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@fougere/schema": "0.
|
|
44
|
+
"@fougere/schema": "0.17.0-alpha.0",
|
|
45
45
|
"jiti": "^2.6.1",
|
|
46
|
-
"@fougere/container": "0.
|
|
47
|
-
"@fougere/compiler": "0.
|
|
46
|
+
"@fougere/container": "0.17.0-alpha.0",
|
|
47
|
+
"@fougere/compiler": "0.17.0-alpha.0"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
package/src/client.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type { RpcResponse } from './jsonrpc/RpcResponse.js';
|
|
|
7
7
|
|
|
8
8
|
/** Frame a call as a JSON-RPC request. */
|
|
9
9
|
export function frameCall(call: FrondCall, invocation: InvocationContext, id: number): RpcRequest {
|
|
10
|
-
return { jsonrpc: '2.0', id, method: `${call.
|
|
10
|
+
return { jsonrpc: '2.0', id, method: `${call.address}.${call.op}`, params: invocation };
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/** Unframe a JSON-RPC response — the result, or the revived FougereError thrown. */
|
|
@@ -16,7 +16,7 @@ export function unframeResponse(response: unknown, call: FrondCall): unknown {
|
|
|
16
16
|
throw new FougereError({
|
|
17
17
|
code: ErrorCode.BAD_GATEWAY,
|
|
18
18
|
message: 'Answered neither a result nor an error — not a Fougere receiver?',
|
|
19
|
-
|
|
19
|
+
address: call.address,
|
|
20
20
|
operation: call.op,
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -26,7 +26,7 @@ export function unframeResponse(response: unknown, call: FrondCall): unknown {
|
|
|
26
26
|
throw new FougereError({
|
|
27
27
|
code: ErrorCode.BAD_GATEWAY,
|
|
28
28
|
message: 'Answered an error that is not a JSON-RPC error object',
|
|
29
|
-
|
|
29
|
+
address: call.address,
|
|
30
30
|
operation: call.op,
|
|
31
31
|
});
|
|
32
32
|
}
|
|
@@ -34,7 +34,7 @@ export function unframeResponse(response: unknown, call: FrondCall): unknown {
|
|
|
34
34
|
throw new FougereError({
|
|
35
35
|
code: ErrorCode.INTERNAL_ERROR,
|
|
36
36
|
message: `${error.message} (rpc ${error.code})`,
|
|
37
|
-
|
|
37
|
+
address: call.address,
|
|
38
38
|
operation: call.op,
|
|
39
39
|
});
|
|
40
40
|
}
|
|
@@ -99,17 +99,17 @@ export function createHttpTransport(baseUrl: string, options: HttpTransportOptio
|
|
|
99
99
|
if (isTimeout(err)) {
|
|
100
100
|
throw new FougereError({
|
|
101
101
|
code: ErrorCode.GATEWAY_TIMEOUT,
|
|
102
|
-
message: `${call.
|
|
102
|
+
message: `${call.address}.${call.op} timed out after ${timeoutMs}ms`,
|
|
103
103
|
cause: new Error(`${baseUrl} did not answer in ${timeoutMs}ms`),
|
|
104
|
-
|
|
104
|
+
address: call.address,
|
|
105
105
|
operation: call.op,
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
if (attempt < retries && isConnectionFailure(err)) continue;
|
|
109
109
|
throw new FougereError({
|
|
110
110
|
code: ErrorCode.SERVICE_UNAVAILABLE,
|
|
111
|
-
message: `${call.
|
|
112
|
-
|
|
111
|
+
message: `${call.address}.${call.op}: the process serving it is unreachable`,
|
|
112
|
+
address: call.address,
|
|
113
113
|
operation: call.op,
|
|
114
114
|
cause: new Error(`${baseUrl} unreachable: ${(err as Error)?.message ?? err}`, { cause: err }),
|
|
115
115
|
});
|
|
@@ -119,9 +119,9 @@ export function createHttpTransport(baseUrl: string, options: HttpTransportOptio
|
|
|
119
119
|
if (!res.ok) {
|
|
120
120
|
throw new FougereError({
|
|
121
121
|
code: ErrorCode.BAD_GATEWAY,
|
|
122
|
-
message: `${call.
|
|
122
|
+
message: `${call.address}.${call.op}: the receiver answered HTTP ${res.status} — not a Fougere receiver?`,
|
|
123
123
|
cause: new Error(`${baseUrl} answered HTTP ${res.status}`),
|
|
124
|
-
|
|
124
|
+
address: call.address,
|
|
125
125
|
operation: call.op,
|
|
126
126
|
});
|
|
127
127
|
}
|
|
@@ -132,9 +132,9 @@ export function createHttpTransport(baseUrl: string, options: HttpTransportOptio
|
|
|
132
132
|
} catch {
|
|
133
133
|
throw new FougereError({
|
|
134
134
|
code: ErrorCode.BAD_GATEWAY,
|
|
135
|
-
message: `${call.
|
|
135
|
+
message: `${call.address}.${call.op}: the receiver answered non-JSON`,
|
|
136
136
|
cause: new Error(`${baseUrl} answered non-JSON`),
|
|
137
|
-
|
|
137
|
+
address: call.address,
|
|
138
138
|
operation: call.op,
|
|
139
139
|
});
|
|
140
140
|
}
|
|
@@ -148,9 +148,9 @@ export function createHttpTransport(baseUrl: string, options: HttpTransportOptio
|
|
|
148
148
|
function tooLarge(call: FrondCall, baseUrl: string): FougereError {
|
|
149
149
|
return new FougereError({
|
|
150
150
|
code: ErrorCode.PAYLOAD_TOO_LARGE,
|
|
151
|
-
message: `${call.
|
|
151
|
+
message: `${call.address}.${call.op} carries more than the ${maxBodyBytes()} bytes a caller may send (maxBodyBytes).`,
|
|
152
152
|
cause: new Error(`refused for ${baseUrl}`),
|
|
153
|
-
|
|
153
|
+
address: call.address,
|
|
154
154
|
operation: call.op,
|
|
155
155
|
});
|
|
156
156
|
}
|
package/src/server.ts
CHANGED
|
@@ -27,10 +27,10 @@ export async function handleRpc(runner: Transport, raw: unknown, options: Receiv
|
|
|
27
27
|
return {
|
|
28
28
|
jsonrpc: '2.0',
|
|
29
29
|
id,
|
|
30
|
-
error: { code: INVALID_REQUEST, message: `Invalid method '${req.method}' — expected '
|
|
30
|
+
error: { code: INVALID_REQUEST, message: `Invalid method '${req.method}' — expected 'address.op'` },
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const address = req.method.slice(0, dot);
|
|
34
34
|
const op = req.method.slice(dot + 1);
|
|
35
35
|
|
|
36
36
|
// Fresh objects — middlewares deposit into state, nothing may be shared.
|
|
@@ -38,7 +38,7 @@ export async function handleRpc(runner: Transport, raw: unknown, options: Receiv
|
|
|
38
38
|
const strangers = Object.entries(sent)
|
|
39
39
|
.filter(([key, value]) => value !== undefined && !SENT[key as keyof InvocationContext])
|
|
40
40
|
.map(([key]) => key);
|
|
41
|
-
if (strangers.length > 0) return malformed(id, strangers,
|
|
41
|
+
if (strangers.length > 0) return malformed(id, strangers, address, op);
|
|
42
42
|
|
|
43
43
|
/** State is ESTABLISHED here, or it is only claimed. */
|
|
44
44
|
let state: Record<string, unknown> = sent.state ?? {};
|
|
@@ -46,19 +46,17 @@ export async function handleRpc(runner: Transport, raw: unknown, options: Receiv
|
|
|
46
46
|
if (options.verify && sent.identity) {
|
|
47
47
|
try {
|
|
48
48
|
// What ARRIVED, never what we would rather it had been — the comparison is the point.
|
|
49
|
-
({ caller, state } = await options.verify(sent.identity, {
|
|
50
|
-
entity,
|
|
51
|
-
op,
|
|
49
|
+
({ caller, state } = await options.verify(sent.identity, { address, op,
|
|
52
50
|
params: sent.params ?? {},
|
|
53
51
|
query: sent.query ?? {},
|
|
54
52
|
input: sent.input,
|
|
55
53
|
runAt: sent.runAt,
|
|
56
54
|
}));
|
|
57
55
|
} catch (err) {
|
|
58
|
-
return refused(id, (err as Error)?.message ?? 'unverifiable identity',
|
|
56
|
+
return refused(id, (err as Error)?.message ?? 'unverifiable identity', address, op);
|
|
59
57
|
}
|
|
60
58
|
} else if (options.requireIdentity) {
|
|
61
|
-
return refused(id, 'this receiver takes signed calls only',
|
|
59
|
+
return refused(id, 'this receiver takes signed calls only', address, op);
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
// Built field by field, never spread from `sent`: everything here is either validated
|
|
@@ -75,14 +73,14 @@ export async function handleRpc(runner: Transport, raw: unknown, options: Receiv
|
|
|
75
73
|
};
|
|
76
74
|
|
|
77
75
|
try {
|
|
78
|
-
return { jsonrpc: '2.0', id, result: await runner({
|
|
76
|
+
return { jsonrpc: '2.0', id, result: await runner({ address, op }, invocation) };
|
|
79
77
|
} catch (err) {
|
|
80
78
|
const failure = err instanceof FougereError
|
|
81
79
|
? err
|
|
82
80
|
: new FougereError({
|
|
83
81
|
code: ErrorCode.INTERNAL_ERROR,
|
|
84
82
|
message: (err as Error)?.message ?? 'Internal error',
|
|
85
|
-
|
|
83
|
+
address,
|
|
86
84
|
operation: op,
|
|
87
85
|
cause: err,
|
|
88
86
|
});
|
|
@@ -102,12 +100,12 @@ const SENT = {
|
|
|
102
100
|
crossed: false,
|
|
103
101
|
} satisfies Record<keyof InvocationContext, boolean>;
|
|
104
102
|
|
|
105
|
-
function malformed(id: string | number, strangers: string[],
|
|
103
|
+
function malformed(id: string | number, strangers: string[], address: string, op: string): RpcResponse {
|
|
106
104
|
const admitted = Object.keys(SENT).filter((key) => SENT[key as keyof InvocationContext]);
|
|
107
105
|
const data = toPublicError(new FougereError({
|
|
108
106
|
code: ErrorCode.BAD_REQUEST,
|
|
109
107
|
message: `Unknown invocation member ${strangers.map((key) => `'${key}'`).join(', ')} — one of ${admitted.join(', ')}.`,
|
|
110
|
-
|
|
108
|
+
address,
|
|
111
109
|
operation: op,
|
|
112
110
|
}));
|
|
113
111
|
|
|
@@ -115,9 +113,9 @@ function malformed(id: string | number, strangers: string[], entity: string, op:
|
|
|
115
113
|
}
|
|
116
114
|
|
|
117
115
|
/** An admission refusal, framed like any other failure so a caller reads one vocabulary. */
|
|
118
|
-
function refused(id: string | number, why: string,
|
|
116
|
+
function refused(id: string | number, why: string, address: string, op: string): RpcResponse {
|
|
119
117
|
const data = toPublicError(
|
|
120
|
-
new FougereError({ code: ErrorCode.UNAUTHORIZED, message: `Refused: ${why}`,
|
|
118
|
+
new FougereError({ code: ErrorCode.UNAUTHORIZED, message: `Refused: ${why}`, address, operation: op }),
|
|
121
119
|
);
|
|
122
120
|
|
|
123
121
|
return { jsonrpc: '2.0', id, error: { code: APP_ERROR, message: data.message, data } };
|