From b9c417cbff241d4b674db899215a8844bc14a59c Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Sat, 11 Mar 2023 17:46:43 +0100 Subject: [PATCH] use simple-json-rpc --- client/package.json | 5 +-- client/pnpm-lock.yaml | 83 +++++++------------------------------------ client/src/api.ts | 16 ++++----- 3 files changed, 23 insertions(+), 81 deletions(-) diff --git a/client/package.json b/client/package.json index d1881f4..8a358fb 100644 --- a/client/package.json +++ b/client/package.json @@ -12,7 +12,6 @@ }, "dependencies": { "@intlify/unplugin-vue-i18n": "^0.8.2", - "@open-rpc/client-js": "^1.8.1", "@vueuse/core": "^9.13.0", "@vueuse/head": "^1.1.15", "axios": "^1.3.4", @@ -21,9 +20,11 @@ "focus-trap-vue": "^4.0.2", "markdown-it-link-attributes": "^4.0.1", "markdown-it-shiki": "^0.8.0", + "simple-jsonrpc-js": "^1.2.0", "vue": "^3.2.45", "vue-i18n": "9", - "vue-router": "4" + "vue-router": "4", + "ws": "^8.13.0" }, "devDependencies": { "@iconify/json": "^2.2.30", diff --git a/client/pnpm-lock.yaml b/client/pnpm-lock.yaml index c79955f..2ad3418 100644 --- a/client/pnpm-lock.yaml +++ b/client/pnpm-lock.yaml @@ -3,7 +3,6 @@ lockfileVersion: 5.4 specifiers: '@iconify/json': ^2.2.30 '@intlify/unplugin-vue-i18n': ^0.8.2 - '@open-rpc/client-js': ^1.8.1 '@types/events': ^3.0.0 '@types/markdown-it-link-attributes': ^3.0.1 '@typescript-eslint/parser': ^5.54.1 @@ -20,6 +19,7 @@ specifiers: focus-trap-vue: ^4.0.2 markdown-it-link-attributes: ^4.0.1 markdown-it-shiki: ^0.8.0 + simple-jsonrpc-js: ^1.2.0 typescript: ^4.9.3 unplugin-auto-import: ^0.15.0 unplugin-icons: ^0.15.3 @@ -32,10 +32,10 @@ specifiers: vue-i18n: '9' vue-router: '4' vue-tsc: ^1.0.24 + ws: ^8.13.0 dependencies: '@intlify/unplugin-vue-i18n': 0.8.2_vue-i18n@9.2.2 - '@open-rpc/client-js': 1.8.1 '@vueuse/core': 9.13.0_vue@3.2.47 '@vueuse/head': 1.1.15_vue@3.2.47 axios: 1.3.4 @@ -44,9 +44,11 @@ dependencies: focus-trap-vue: 4.0.2_oggptlzwchqpaguemspe4ract4 markdown-it-link-attributes: 4.0.1 markdown-it-shiki: 0.8.0 + simple-jsonrpc-js: 1.2.0 vue: 3.2.47 vue-i18n: 9.2.2_vue@3.2.47 vue-router: 4.1.6_vue@3.2.47 + ws: 8.13.0 devDependencies: '@iconify/json': 2.2.30 @@ -777,19 +779,6 @@ packages: - supports-color dev: true - /@open-rpc/client-js/1.8.1: - resolution: {integrity: sha512-vV+Hetl688nY/oWI9IFY0iKDrWuLdYhf7OIKI6U1DcnJV7r4gAgwRJjEr1QVYszUc0gjkHoQJzqevmXMGLyA0g==} - dependencies: - isomorphic-fetch: 3.0.0 - isomorphic-ws: 5.0.0_ws@7.5.9 - strict-event-emitter-types: 2.0.0 - ws: 7.5.9 - transitivePeerDependencies: - - bufferutil - - encoding - - utf-8-validate - dev: false - /@pkgr/utils/2.3.1: resolution: {integrity: sha512-wfzX8kc1PMyUILA+1Z/EqoE4UCXGy0iRGMhPwdfae1+f0OXlLqCk+By+aMzgJBzR9AzS4CDizioG6Ss1gvAFJw==} engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} @@ -2619,23 +2608,6 @@ packages: /isexe/2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} - /isomorphic-fetch/3.0.0: - resolution: {integrity: sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==} - dependencies: - node-fetch: 2.6.9 - whatwg-fetch: 3.6.2 - transitivePeerDependencies: - - encoding - dev: false - - /isomorphic-ws/5.0.0_ws@7.5.9: - resolution: {integrity: sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw==} - peerDependencies: - ws: '*' - dependencies: - ws: 7.5.9 - dev: false - /jiti/1.17.1: resolution: {integrity: sha512-NZIITw8uZQFuzQimqjUxIrIcEdxYDFIe/0xYfIlVXTkiBjjyBEvgasj5bb0/cHtPRD/NziPbT312sFrkI5ALpw==} hasBin: true @@ -2953,18 +2925,6 @@ packages: resolution: {integrity: sha512-KIkvH1jl6b3O7es/0ShyCgWLcfXxlBrLBbP3rOr23WArC66IMcU4DeZEeYEOwnopYhawLTn7/y+YtmASe8DFVQ==} dev: true - /node-fetch/2.6.9: - resolution: {integrity: sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==} - engines: {node: 4.x || >=6.0.0} - peerDependencies: - encoding: ^0.1.0 - peerDependenciesMeta: - encoding: - optional: true - dependencies: - whatwg-url: 5.0.0 - dev: false - /node-releases/2.0.10: resolution: {integrity: sha512-5GFldHPXVG/YZmFzJvKK2zDSzPKhEp0+ZR5SVaoSag9fsL5YgHbUHDfnG5494ISANDcK4KwPXAx2xqVEydmd7w==} dev: true @@ -3298,6 +3258,10 @@ packages: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} dev: true + /simple-jsonrpc-js/1.2.0: + resolution: {integrity: sha512-owkAmh7fjSYBUZVestTPCZMKYQvNiDejqZ/iGfVaKs1nrC1ZBDA3qGraf94+JNFJmu536Tb8oPe8PSPuq7GO6Q==} + dev: false + /sirv/2.0.2: resolution: {integrity: sha512-4Qog6aE29nIjAOKe/wowFTxOdmbEZKb+3tsLljaBRzJwtqto0BChD2zzH0LhgCSXiI+V7X+Y45v14wBZQ1TK3w==} engines: {node: '>= 10'} @@ -3344,10 +3308,6 @@ packages: internal-slot: 1.0.5 dev: true - /strict-event-emitter-types/2.0.0: - resolution: {integrity: sha512-Nk/brWYpD85WlOgzw5h173aci0Teyv8YdIAEtV+N88nDB0dLlazZyJMIsN6eo1/AR61l+p6CJTG1JIyFaoNEEA==} - dev: false - /string_decoder/1.1.1: resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==} dependencies: @@ -3456,10 +3416,6 @@ packages: engines: {node: '>=6'} dev: true - /tr46/0.0.3: - resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} - dev: false - /tslib/1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} dev: true @@ -3909,10 +3865,6 @@ packages: '@vue/server-renderer': 3.2.47_vue@3.2.47 '@vue/shared': 3.2.47 - /webidl-conversions/3.0.1: - resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} - dev: false - /webpack-sources/3.2.3: resolution: {integrity: sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==} engines: {node: '>=10.13.0'} @@ -3920,17 +3872,6 @@ packages: /webpack-virtual-modules/0.5.0: resolution: {integrity: sha512-kyDivFZ7ZM0BVOUteVbDFhlRt7Ah/CSPwJdi8hBpkK7QLumUqdLtVfm/PX/hkcnrvr0i77fO5+TjZ94Pe+C9iw==} - /whatwg-fetch/3.6.2: - resolution: {integrity: sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==} - dev: false - - /whatwg-url/5.0.0: - resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} - dependencies: - tr46: 0.0.3 - webidl-conversions: 3.0.1 - dev: false - /which-boxed-primitive/1.0.2: resolution: {integrity: sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==} dependencies: @@ -3978,12 +3919,12 @@ packages: resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} dev: true - /ws/7.5.9: - resolution: {integrity: sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==} - engines: {node: '>=8.3.0'} + /ws/8.13.0: + resolution: {integrity: sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==} + engines: {node: '>=10.0.0'} peerDependencies: bufferutil: ^4.0.1 - utf-8-validate: ^5.0.2 + utf-8-validate: '>=5.0.2' peerDependenciesMeta: bufferutil: optional: true diff --git a/client/src/api.ts b/client/src/api.ts index 51d3c03..d0ff029 100644 --- a/client/src/api.ts +++ b/client/src/api.ts @@ -1,9 +1,9 @@ -import { RequestManager, HTTPTransport, WebSocketTransport, Client } from "@open-rpc/client-js"; +import WebSocketServer from 'ws'; +import JsonRPC from 'simple-jsonrpc-js'; import axios from "axios"; -const httpTransport = new HTTPTransport("http://"+ window.location.host +"/api"); -// const socktransport = new WebSocketTransport("ws://"+ window.location.host + "/ws/api"); -const manager = new RequestManager([httpTransport], () => crypto.randomUUID()); -const client = new Client(manager); + +let jrpc = new JsonRPC.connect_xhr('/api'); +// let socket = new WebSocket("ws://"+ window.location.host +"/ws/api"); let UnauthorizedCallback: Function; @@ -14,11 +14,11 @@ export function setup(_UnauthorizedCallback: () => void) { export async function apiCall(method: string, params: Record): Promise{ console.debug("Starting API Call..."); try { - const result = await client.request({method, params}); + const result = await jrpc.call(method, params); console.debug("api call result", result); return { Data: result, Error: null}; - } catch (ex){ - if (ex == "Error: Unauthorized") { + } catch (ex: any){ + if (ex.code === 401) { UnauthorizedCallback(); } else { console.debug("api call epic fail", ex);