@travetto/web-rpc 8.0.0-alpha.18 → 8.0.0-alpha.19
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 +1 -1
- package/support/client/rpc.ts +6 -6
package/package.json
CHANGED
package/support/client/rpc.ts
CHANGED
|
@@ -7,7 +7,7 @@ type PromiseResult<V extends PromiseFn> = Awaited<ReturnType<V>>;
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
const
|
|
10
|
+
const triggerBrowserRedirect = (world: any, url: URL): boolean => {
|
|
11
11
|
const location = world?.window?.location;
|
|
12
12
|
if (location) {
|
|
13
13
|
location.href = url.toString();
|
|
@@ -63,7 +63,7 @@ export type RpcRequest = {
|
|
|
63
63
|
controller: string;
|
|
64
64
|
endpoint: string;
|
|
65
65
|
method: string;
|
|
66
|
-
|
|
66
|
+
browserRedirect?: boolean;
|
|
67
67
|
};
|
|
68
68
|
url: URL | string;
|
|
69
69
|
consumeJSON?: <T>(text?: unknown) => (T | Promise<T>);
|
|
@@ -109,11 +109,11 @@ function registerTimeout<T>(
|
|
|
109
109
|
|
|
110
110
|
function buildRequest<T extends RequestInit>(base: T, controller: string, endpoint: string): T {
|
|
111
111
|
let verb: string;
|
|
112
|
-
let
|
|
112
|
+
let browserRedirect = false;
|
|
113
113
|
switch (endpoint.split(/[A-Z]/)[0]) {
|
|
114
114
|
case 'redirect': {
|
|
115
115
|
verb = 'GET';
|
|
116
|
-
|
|
116
|
+
browserRedirect = true;
|
|
117
117
|
break;
|
|
118
118
|
}
|
|
119
119
|
case 'get': verb = 'GET'; break;
|
|
@@ -123,7 +123,7 @@ function buildRequest<T extends RequestInit>(base: T, controller: string, endpoi
|
|
|
123
123
|
}
|
|
124
124
|
return {
|
|
125
125
|
...base,
|
|
126
|
-
|
|
126
|
+
browserRedirect,
|
|
127
127
|
method: verb,
|
|
128
128
|
path: `${controller}:${endpoint}`,
|
|
129
129
|
controller,
|
|
@@ -254,7 +254,7 @@ export async function invokeFetch<T>(request: RpcRequest, ...params: unknown[]):
|
|
|
254
254
|
url.searchParams.append(key, value);
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
if (core.
|
|
257
|
+
if (core.browserRedirect && triggerBrowserRedirect(globalThis, url)) {
|
|
258
258
|
return Promise.resolve(undefined!);
|
|
259
259
|
}
|
|
260
260
|
|