@enbox/dwn-server 0.0.16 → 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/dist/esm/src/json-rpc-api.d.ts.map +1 -1
- package/dist/esm/src/json-rpc-api.js +2 -0
- package/dist/esm/src/json-rpc-api.js.map +1 -1
- package/dist/esm/src/json-rpc-handlers/ping.d.ts +10 -0
- package/dist/esm/src/json-rpc-handlers/ping.d.ts.map +1 -0
- package/dist/esm/src/json-rpc-handlers/ping.js +14 -0
- package/dist/esm/src/json-rpc-handlers/ping.js.map +1 -0
- package/dist/esm/src/lib/json-rpc-router.d.ts.map +1 -1
- package/dist/esm/src/lib/json-rpc-router.js +6 -0
- package/dist/esm/src/lib/json-rpc-router.js.map +1 -1
- package/package.json +2 -2
- package/src/json-rpc-api.ts +3 -0
- package/src/json-rpc-handlers/ping.ts +19 -0
- package/src/lib/json-rpc-router.ts +11 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc-api.d.ts","sourceRoot":"","sources":["../../../src/json-rpc-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"json-rpc-api.d.ts","sourceRoot":"","sources":["../../../src/json-rpc-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzD,eAAO,MAAM,aAAa,eAAsB,CAAC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { JsonRpcRouter } from './lib/json-rpc-router.js';
|
|
2
2
|
import { handleDwnProcessMessage } from './json-rpc-handlers/dwn/index.js';
|
|
3
|
+
import { handlePing } from './json-rpc-handlers/ping.js';
|
|
3
4
|
import { handleSubscriptionAck, handleSubscriptionsClose } from './json-rpc-handlers/subscription/index.js';
|
|
4
5
|
export const jsonRpcRouter = new JsonRpcRouter();
|
|
5
6
|
jsonRpcRouter.on('dwn.processMessage', handleDwnProcessMessage);
|
|
6
7
|
jsonRpcRouter.on('rpc.subscribe.dwn.processMessage', handleDwnProcessMessage);
|
|
7
8
|
jsonRpcRouter.on('rpc.ack', handleSubscriptionAck);
|
|
8
9
|
jsonRpcRouter.on('rpc.subscribe.close', handleSubscriptionsClose);
|
|
10
|
+
jsonRpcRouter.on('rpc.ping', handlePing);
|
|
9
11
|
//# sourceMappingURL=json-rpc-api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc-api.js","sourceRoot":"","sources":["../../../src/json-rpc-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AAE5G,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;AAEjD,aAAa,CAAC,EAAE,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,CAAC;AAChE,aAAa,CAAC,EAAE,CAAC,kCAAkC,EAAE,uBAAuB,CAAC,CAAC;AAE9E,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;AACnD,aAAa,CAAC,EAAE,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"json-rpc-api.js","sourceRoot":"","sources":["../../../src/json-rpc-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AAE5G,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;AAEjD,aAAa,CAAC,EAAE,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,CAAC;AAChE,aAAa,CAAC,EAAE,CAAC,kCAAkC,EAAE,uBAAuB,CAAC,CAAC;AAE9E,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;AACnD,aAAa,CAAC,EAAE,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,CAAC;AAElE,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { JsonRpcHandler } from '../lib/json-rpc-router.js';
|
|
2
|
+
/**
|
|
3
|
+
* Handles `rpc.ping` requests — a lightweight application-level heartbeat.
|
|
4
|
+
*
|
|
5
|
+
* Clients send `rpc.ping` periodically to detect silently dead WebSocket
|
|
6
|
+
* connections (NAT timeout, network switch, device sleep). The server
|
|
7
|
+
* responds with a simple success so the client knows the connection is alive.
|
|
8
|
+
*/
|
|
9
|
+
export declare const handlePing: JsonRpcHandler;
|
|
10
|
+
//# sourceMappingURL=ping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ping.d.ts","sourceRoot":"","sources":["../../../../src/json-rpc-handlers/ping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,cAAc,EACf,MAAM,2BAA2B,CAAC;AAInC;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,EAAE,cAIxB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createJsonRpcSuccessResponse } from '@enbox/dwn-clients';
|
|
2
|
+
/**
|
|
3
|
+
* Handles `rpc.ping` requests — a lightweight application-level heartbeat.
|
|
4
|
+
*
|
|
5
|
+
* Clients send `rpc.ping` periodically to detect silently dead WebSocket
|
|
6
|
+
* connections (NAT timeout, network switch, device sleep). The server
|
|
7
|
+
* responds with a simple success so the client knows the connection is alive.
|
|
8
|
+
*/
|
|
9
|
+
export const handlePing = async (request) => {
|
|
10
|
+
return {
|
|
11
|
+
jsonRpcResponse: createJsonRpcSuccessResponse(request.id, { ok: true }),
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=ping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ping.js","sourceRoot":"","sources":["../../../../src/json-rpc-handlers/ping.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAElE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAmB,KAAK,EAAE,OAAO,EAA4B,EAAE;IACpF,OAAO;QACL,eAAe,EAAE,4BAA4B,CAAC,OAAO,CAAC,EAAG,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;KACzE,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc-router.d.ts","sourceRoot":"","sources":["../../../../src/lib/json-rpc-router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,KAAK,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1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AC1C,iBAAiB,CAAC,EAAE,WAAW,CAAC;IAChC,+EAA+E;IAC/E,qBAAqB,CAAC,EAAE,oBAAoB,EAAE,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,eAAe,EAAE,eAAe,CAAC;IACjC,UAAU,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,CAC3B,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,cAAc,KACpB,OAAO,CAAC,eAAe,CAAC,CAAC;AAE9B,qBAAa,aAAa;IACxB,OAAO,CAAC,cAAc,CAAuC;;IAM7D,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI;IAI/C,MAAM,CACV,UAAU,EAAE,cAAc,EAC1B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC;CAc5B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createJsonRpcErrorResponse, JsonRpcErrorCodes } from '@enbox/dwn-clients';
|
|
1
2
|
export class JsonRpcRouter {
|
|
2
3
|
methodHandlers;
|
|
3
4
|
constructor() {
|
|
@@ -8,6 +9,11 @@ export class JsonRpcRouter {
|
|
|
8
9
|
}
|
|
9
10
|
async handle(rpcRequest, context) {
|
|
10
11
|
const handler = this.methodHandlers[rpcRequest.method];
|
|
12
|
+
if (!handler) {
|
|
13
|
+
return {
|
|
14
|
+
jsonRpcResponse: createJsonRpcErrorResponse(rpcRequest.id, JsonRpcErrorCodes.MethodNotFound, `Method not found: ${rpcRequest.method}`),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
11
17
|
return await handler(rpcRequest, context);
|
|
12
18
|
}
|
|
13
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc-router.js","sourceRoot":"","sources":["../../../../src/lib/json-rpc-router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"json-rpc-router.js","sourceRoot":"","sources":["../../../../src/lib/json-rpc-router.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAuCnF,MAAM,OAAO,aAAa;IAChB,cAAc,CAAuC;IAE7D;QACE,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;IAC3B,CAAC;IAED,EAAE,CAAC,UAAkB,EAAE,OAAuB;QAC5C,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,MAAM,CACV,UAA0B,EAC1B,OAAuB;QAEvB,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACvD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO;gBACL,eAAe,EAAE,0BAA0B,CACzC,UAAU,CAAC,EAAG,EACd,iBAAiB,CAAC,cAAc,EAChC,qBAAqB,UAAU,CAAC,MAAM,EAAE,CACzC;aACF,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enbox/dwn-server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@enbox/common": "0.1.0",
|
|
34
34
|
"@enbox/crypto": "0.1.0",
|
|
35
35
|
"@enbox/dids": "0.1.0",
|
|
36
|
-
"@enbox/dwn-clients": "0.
|
|
36
|
+
"@enbox/dwn-clients": "0.3.0",
|
|
37
37
|
"@enbox/dwn-sdk-js": "0.3.2",
|
|
38
38
|
"@enbox/dwn-sql-store": "0.0.17",
|
|
39
39
|
"@nats-io/jetstream": "3.3.1",
|
package/src/json-rpc-api.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { JsonRpcRouter } from './lib/json-rpc-router.js';
|
|
2
2
|
|
|
3
3
|
import { handleDwnProcessMessage } from './json-rpc-handlers/dwn/index.js';
|
|
4
|
+
import { handlePing } from './json-rpc-handlers/ping.js';
|
|
4
5
|
import { handleSubscriptionAck, handleSubscriptionsClose } from './json-rpc-handlers/subscription/index.js';
|
|
5
6
|
|
|
6
7
|
export const jsonRpcRouter = new JsonRpcRouter();
|
|
@@ -10,3 +11,5 @@ jsonRpcRouter.on('rpc.subscribe.dwn.processMessage', handleDwnProcessMessage);
|
|
|
10
11
|
|
|
11
12
|
jsonRpcRouter.on('rpc.ack', handleSubscriptionAck);
|
|
12
13
|
jsonRpcRouter.on('rpc.subscribe.close', handleSubscriptionsClose);
|
|
14
|
+
|
|
15
|
+
jsonRpcRouter.on('rpc.ping', handlePing);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HandlerResponse,
|
|
3
|
+
JsonRpcHandler,
|
|
4
|
+
} from '../lib/json-rpc-router.js';
|
|
5
|
+
|
|
6
|
+
import { createJsonRpcSuccessResponse } from '@enbox/dwn-clients';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Handles `rpc.ping` requests — a lightweight application-level heartbeat.
|
|
10
|
+
*
|
|
11
|
+
* Clients send `rpc.ping` periodically to detect silently dead WebSocket
|
|
12
|
+
* connections (NAT timeout, network switch, device sleep). The server
|
|
13
|
+
* responds with a simple success so the client knows the connection is alive.
|
|
14
|
+
*/
|
|
15
|
+
export const handlePing: JsonRpcHandler = async (request): Promise<HandlerResponse> => {
|
|
16
|
+
return {
|
|
17
|
+
jsonRpcResponse: createJsonRpcSuccessResponse(request.id!, { ok: true }),
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -8,6 +8,8 @@ import type { SocketConnection } from '../connection/socket-connection.js';
|
|
|
8
8
|
import type { Dwn, SubscriptionListener } from '@enbox/dwn-sdk-js';
|
|
9
9
|
import type { JsonRpcId, JsonRpcRequest, JsonRpcResponse } from '@enbox/dwn-clients';
|
|
10
10
|
|
|
11
|
+
import { createJsonRpcErrorResponse, JsonRpcErrorCodes } from '@enbox/dwn-clients';
|
|
12
|
+
|
|
11
13
|
export type RequestContext = {
|
|
12
14
|
transport: 'http' | 'ws';
|
|
13
15
|
dwn: Dwn;
|
|
@@ -61,6 +63,15 @@ export class JsonRpcRouter {
|
|
|
61
63
|
context: RequestContext,
|
|
62
64
|
): Promise<HandlerResponse> {
|
|
63
65
|
const handler = this.methodHandlers[rpcRequest.method];
|
|
66
|
+
if (!handler) {
|
|
67
|
+
return {
|
|
68
|
+
jsonRpcResponse: createJsonRpcErrorResponse(
|
|
69
|
+
rpcRequest.id!,
|
|
70
|
+
JsonRpcErrorCodes.MethodNotFound,
|
|
71
|
+
`Method not found: ${rpcRequest.method}`,
|
|
72
|
+
),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
64
75
|
|
|
65
76
|
return await handler(rpcRequest, context);
|
|
66
77
|
}
|