@travetto/web-rpc 6.0.0 → 6.0.2
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/package.json +2 -2
- package/src/controller.ts +9 -1
- package/support/client/rpc.ts +13 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/web-rpc",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.2",
|
|
4
4
|
"description": "RPC support for a Web Application",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@travetto/config": "^6.0.0",
|
|
30
30
|
"@travetto/schema": "^6.0.0",
|
|
31
|
-
"@travetto/web": "^6.0.
|
|
31
|
+
"@travetto/web": "^6.0.2"
|
|
32
32
|
},
|
|
33
33
|
"travetto": {
|
|
34
34
|
"displayName": "Web RPC Support"
|
package/src/controller.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Any, AppError, Util } from '@travetto/runtime';
|
|
|
3
3
|
import {
|
|
4
4
|
HeaderParam, Controller, Undocumented, ExcludeInterceptors, ControllerRegistry,
|
|
5
5
|
WebAsyncContext, Body, EndpointUtil, BodyInterceptor, Post, WebCommonUtil,
|
|
6
|
-
RespondInterceptor, DecompressInterceptor
|
|
6
|
+
RespondInterceptor, DecompressInterceptor, Get
|
|
7
7
|
} from '@travetto/web';
|
|
8
8
|
|
|
9
9
|
@Controller('/rpc')
|
|
@@ -19,6 +19,14 @@ export class WebRpcController {
|
|
|
19
19
|
@Inject()
|
|
20
20
|
ctx: WebAsyncContext;
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Allow for get-based requests
|
|
24
|
+
*/
|
|
25
|
+
@Get('/:target')
|
|
26
|
+
async onGetRequest(target: string, @HeaderParam('X-TRV-RPC-INPUTS') paramInput?: string): Promise<unknown> {
|
|
27
|
+
return this.onRequest(target, paramInput);
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
/**
|
|
23
31
|
* RPC main entrypoint
|
|
24
32
|
*/
|
package/support/client/rpc.ts
CHANGED
|
@@ -76,7 +76,15 @@ function buildRequest<T extends RequestInit>(base: T, controller: string, endpoi
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
export function getBody(inputs: unknown[]): { body: FormData | string, headers: Record<string, string> } {
|
|
79
|
+
export function getBody(inputs: unknown[], isBodyRequest: boolean): { body: FormData | string | undefined, headers: Record<string, string> } {
|
|
80
|
+
if (!isBodyRequest) {
|
|
81
|
+
return {
|
|
82
|
+
body: undefined,
|
|
83
|
+
headers: {
|
|
84
|
+
'X-TRV-RPC-INPUTS': btoa(encodeURIComponent(JSON.stringify(inputs)))
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
80
88
|
// If we do not have a blob, simple output
|
|
81
89
|
if (!inputs.some(isBlobLike)) {
|
|
82
90
|
return {
|
|
@@ -147,8 +155,10 @@ export async function invokeFetch<T>(request: RpcRequest, ...params: unknown[]):
|
|
|
147
155
|
let core = request.core!;
|
|
148
156
|
|
|
149
157
|
try {
|
|
150
|
-
const { body, headers } = getBody(params);
|
|
151
|
-
|
|
158
|
+
const { body, headers } = getBody(params, /^(post|put|patch)$/i.test(request.core?.method ?? 'POST'));
|
|
159
|
+
if (body) {
|
|
160
|
+
core.body = body;
|
|
161
|
+
}
|
|
152
162
|
core.headers = extendHeaders(core.headers, headers);
|
|
153
163
|
|
|
154
164
|
for (const fn of request.preRequestHandlers ?? []) {
|