@webpieces/http-client-browser 0.4.1002 → 0.4.1003
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/README.md +77 -0
- package/package.json +3 -3
- package/src/BrowserProxyClient.d.ts +2 -2
- package/src/BrowserProxyClient.js +4 -3
- package/src/BrowserProxyClient.js.map +1 -1
- package/src/ClientHttpBrowserFactory.d.ts +24 -2
- package/src/ClientHttpBrowserFactory.js +37 -5
- package/src/ClientHttpBrowserFactory.js.map +1 -1
- package/src/ReactNativeRuntimeDetector.d.ts +19 -0
- package/src/ReactNativeRuntimeDetector.js +31 -0
- package/src/ReactNativeRuntimeDetector.js.map +1 -0
- package/src/index.d.ts +4 -0
- package/src/index.js +45 -37
- package/src/index.js.map +1 -1
package/README.md
CHANGED
|
@@ -71,3 +71,80 @@ progress bar. Every failure it rejects with carries `err.callMode === CallMode.B
|
|
|
71
71
|
"log + report, no dialog" with no app-side bookkeeping. The error's class is unchanged — every
|
|
72
72
|
`instanceof` keeps working — and the property is non-enumerable, so it never reaches JSON or a log
|
|
73
73
|
record. A client bound with `Binder.createRpcClientAndBind` is FOREGROUND.
|
|
74
|
+
|
|
75
|
+
## React Native
|
|
76
|
+
|
|
77
|
+
The same typed client runs in React Native JavaScript, but there it needs an explicit runtime (#1445).
|
|
78
|
+
React Native's default `fetch` (whatwg-fetch over XHR, which settles through `setTimeout(..., 0)`) and
|
|
79
|
+
its JS timers can stop progressing while an Android phone is locked, while native-delivered callbacks
|
|
80
|
+
keep running. A call deadline built on JS timers therefore cannot fire either. So each React Native
|
|
81
|
+
factory takes an `HttpClientRuntime` with two native-backed collaborators:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { fetch as expoFetch } from 'expo/fetch';
|
|
85
|
+
import { ClientHttpBrowserFactory, HttpClientRuntime, MutableContextStore } from '@webpieces/http-client-browser';
|
|
86
|
+
|
|
87
|
+
// once, at startup — and pass the SAME runtime to EVERY React Native factory you build
|
|
88
|
+
const runtime = HttpClientRuntime.reactNative(expoFetch, nativeDeadlineScheduler);
|
|
89
|
+
const factory = new ClientHttpBrowserFactory(store, lifecycleListener, runtime);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- **`fetch`** — any `HttpFetch`: `(url: string, init: HttpFetchInit) => Promise<Response>`. Expo SDK 55's
|
|
93
|
+
`expo/fetch` (whose `FetchResponse` implements `Response`) is accepted as-is, with no cast; so is any
|
|
94
|
+
other native-backed transport with that shape. It receives exactly the URL, method, headers (context and
|
|
95
|
+
JWT included), serialized body, redirect mode and abort signal the platform `fetch` would have.
|
|
96
|
+
- **`deadlines`** — a `DeadlineScheduler` (`@webpieces/core-util`):
|
|
97
|
+
`schedule(delayMs, onExpire): DeadlineTimer` (with `cancel()`) and `now(): number`. Every call
|
|
98
|
+
deadline and every `RetryStrategy` backoff is scheduled through it; nothing on the call path touches a
|
|
99
|
+
JS timer. It must be **native-backed** — wrapping `setTimeout`, or `AbortSignal.timeout`, is the very
|
|
100
|
+
thing that stalls. `now()` should be a clock that keeps counting while the device sleeps (Android
|
|
101
|
+
`SystemClock.elapsedRealtime()`): when a result arrives after the budget and the native callback never
|
|
102
|
+
got through, the call still fails with `ApiCallTimeoutError` instead of returning late.
|
|
103
|
+
|
|
104
|
+
webpieces ships no native module and no Expo/React Native dependency — the scheduler is the app's. The
|
|
105
|
+
tested integration example is
|
|
106
|
+
[`src/__tests__/fixtures/NativeDeadlineScheduler.ts`](src/__tests__/fixtures/NativeDeadlineScheduler.ts):
|
|
107
|
+
a `NativeTimerModule` bridge (`start(id, delayMs)`, `cancel(id)`, a synchronous `elapsedRealtimeMs()`, and
|
|
108
|
+
one "fired" event the app forwards to `scheduler.deliver(id)`) plus the ~40-line adapter over it.
|
|
109
|
+
`InjectedRuntime.spec.ts` drives it with JS timers frozen and proves the deadline still aborts a stalled
|
|
110
|
+
transport, a transport that ignores abort, and a body that never finishes.
|
|
111
|
+
|
|
112
|
+
Guarantees, per call: the deadline covers URL resolution, filters, serialization, the send and the
|
|
113
|
+
response body — the same end-to-end budget as before, not just time-to-headers. It is cancelled exactly
|
|
114
|
+
once on every outcome; a late native callback after the call settled is ignored; the deadline's typed
|
|
115
|
+
`ApiCallTimeoutError` wins over the abort-induced transport rejection; each retry attempt gets a fresh
|
|
116
|
+
deadline and the backoff never extends one.
|
|
117
|
+
|
|
118
|
+
### How React Native is detected — and what is refused
|
|
119
|
+
|
|
120
|
+
The factory checks for the React Native **JavaScript runtime**, via `navigator.product === 'ReactNative'`
|
|
121
|
+
(set by React Native's `Libraries/Core/setUpNavigator.js`; verified on 0.83.10). In that runtime,
|
|
122
|
+
`new ClientHttpBrowserFactory(store)` — and passing `HttpClientRuntime.platformDefaults()` — throws
|
|
123
|
+
`ReactNativeRuntimeConfigError` at construction, naming the missing `fetch` / `deadlines` and linking
|
|
124
|
+
here. Nothing is sent first. `HttpClientRuntime.reactNative(...)` itself refuses a missing collaborator
|
|
125
|
+
(for plain-JavaScript callers the types cannot stop).
|
|
126
|
+
|
|
127
|
+
- **Browsers and WebView pages are unaffected.** A website inside a React Native WebView runs on the
|
|
128
|
+
browser engine's fetch and timers; `window.ReactNativeWebView` does not count as React Native, and
|
|
129
|
+
neither does `window` / `document` presence (React Native has window-like globals). No user-agent
|
|
130
|
+
sniffing, and no `react-native` import.
|
|
131
|
+
- **Node, SSR, workers and tests** (no `navigator`, or no `product`) keep the platform defaults and never
|
|
132
|
+
throw on a missing global.
|
|
133
|
+
- **Detection limits.** A runtime that hides or rewrites `navigator.product` is not detected — declare it
|
|
134
|
+
by passing `HttpClientRuntime.reactNative(...)`, which works with or without the marker. And no check
|
|
135
|
+
can PROVE a function is background-safe: `reactNative(fetch, deadlines)` is your explicit
|
|
136
|
+
acknowledgement, not an identity test of `expoFetch`.
|
|
137
|
+
- **What no runtime can promise.** If the OS suspends or kills the process, no JavaScript runs at all —
|
|
138
|
+
the native side must cancel its own network request, and the JS deadline rejects promptly on resumption.
|
|
139
|
+
Browsers throttle timers in background tabs; that is unchanged.
|
|
140
|
+
|
|
141
|
+
### Migration (breaking behavior change)
|
|
142
|
+
|
|
143
|
+
Before #1445, a React Native app that built `new ClientHttpBrowserFactory(store)` silently got the default
|
|
144
|
+
`fetch` and JS timers — and stalled while locked. It now **fails at startup** with
|
|
145
|
+
`ReactNativeRuntimeConfigError`. Fix every React Native factory (auth, heartbeat, log shipping, …) by
|
|
146
|
+
passing one shared `HttpClientRuntime.reactNative(fetch, deadlines)` as the third argument. Browser and
|
|
147
|
+
WebView code needs no change. A custom `CallStrategy` that waited with `setTimeout` should wait on its
|
|
148
|
+
new third argument, `deadlines` (see [client timeouts](../../../docs/client-timeouts.md)). Direct
|
|
149
|
+
`fetch` calls outside the typed client (e.g. media byte-range downloads) are not covered — wire the
|
|
150
|
+
same native transport into them yourself.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/http-client-browser",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1003",
|
|
4
4
|
"description": "Browser HTTP client for webpieces: DI-free (React or Angular), app-managed context store, no AsyncLocalStorage",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@webpieces/core-util": "0.4.
|
|
26
|
-
"@webpieces/http-client-core": "0.4.
|
|
25
|
+
"@webpieces/core-util": "0.4.1003",
|
|
26
|
+
"@webpieces/http-client-core": "0.4.1003"
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ContextMgr, DestinationTrust, RouteMetadata, ClientRole, CallMode } from '@webpieces/core-util';
|
|
2
|
-
import { ApiPrototype, ByteReadableStream, ClientRequest, ProxyClient, RequestOutcome } from '@webpieces/http-client-core';
|
|
2
|
+
import { ApiPrototype, ByteReadableStream, ClientRequest, HttpClientRuntime, ProxyClient, RequestOutcome } from '@webpieces/http-client-core';
|
|
3
3
|
import { ClientConfig } from './ClientConfig';
|
|
4
4
|
import { RequestLifecycleListener } from './RequestLifecycleListener';
|
|
5
5
|
/**
|
|
@@ -20,7 +20,7 @@ export declare class BrowserProxyClient extends ProxyClient {
|
|
|
20
20
|
/** The query parameter Angular's service worker (`Driver.onFetch`) honours to skip a request. */
|
|
21
21
|
static readonly NGSW_BYPASS_PARAM = "ngsw-bypass";
|
|
22
22
|
private readonly syntheticResponse;
|
|
23
|
-
constructor(contextMgr: ContextMgr, lifecycleListener?: RequestLifecycleListener | undefined);
|
|
23
|
+
constructor(contextMgr: ContextMgr, runtime: HttpClientRuntime, lifecycleListener?: RequestLifecycleListener | undefined);
|
|
24
24
|
/** Bind this client to one API contract + base URL. */
|
|
25
25
|
init(apiPrototype: ApiPrototype<object>, config: ClientConfig): void;
|
|
26
26
|
/**
|
|
@@ -32,11 +32,12 @@ class BrowserProxyClient extends http_client_core_1.ProxyClient {
|
|
|
32
32
|
static NGSW_BYPASS_PARAM = 'ngsw-bypass';
|
|
33
33
|
// Stateless, so constructed here rather than injected — the browser bundle keeps no DI on the fetch path.
|
|
34
34
|
syntheticResponse = new ServiceWorkerSyntheticResponse_1.ServiceWorkerSyntheticResponse();
|
|
35
|
-
constructor(contextMgr, lifecycleListener) {
|
|
35
|
+
constructor(contextMgr, runtime, lifecycleListener) {
|
|
36
36
|
// The browser's ApiCallContext, constructed here rather than installed at startup: its store
|
|
37
37
|
// is static, so every instance stamps into the one slot BrowserApiCallContext.snapshot()
|
|
38
|
-
// reads — which is how a browser logger folds the `api` tag into each line.
|
|
39
|
-
|
|
38
|
+
// reads — which is how a browser logger folds the `api` tag into each line. The runtime is
|
|
39
|
+
// the factory's (#1445): platform fetch + JS timers, or the app's native-backed pair.
|
|
40
|
+
super(new core_util_1.LogApiCallImpl(new BrowserApiCallContext_1.BrowserApiCallContext()), runtime);
|
|
40
41
|
this.contextMgr = contextMgr;
|
|
41
42
|
this.lifecycleListener = lifecycleListener;
|
|
42
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BrowserProxyClient.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/BrowserProxyClient.ts"],"names":[],"mappings":";;;AAAA,oDAS8B;AAC9B,mEAAgE;AAChE,kEAOqC;AAGrC,iEAA8D;AAC9D,qFAAkF;AAElF;;;;;;;;;GASG;AACH,MAAa,kBAAmB,SAAQ,8BAAW;IAkB1B;IACA;IAlBF,gBAAgB,CAAC,KAAoB;QACpD,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,MAA+C,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;QACtJ,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,MAA+C,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,MAAM,CAAC,MAAM,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAChM,MAAM,IAAI,KAAK,CAAC,YAAY,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,aAAa,OAAO,wHAAwH,CAAC,CAAC;QAC/M,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IACO,MAAM,CAAgB;IAE9B,iGAAiG;IACjG,MAAM,CAAU,iBAAiB,GAAG,aAAa,CAAC;IAElD,0GAA0G;IACzF,iBAAiB,GAAG,IAAI,+DAA8B,EAAE,CAAC;IAE1E,YACqB,UAAsB,EACtB,iBAA4C;QAE7D,6FAA6F;QAC7F,yFAAyF;QACzF,4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,KAAK,CAAC,CAAC;IACjC,CAAC;;AApKL,gDAqKC","sourcesContent":["import {\n ContextMgr,\n ClientRegistry,\n DestinationTrust,\n LogApiCallImpl,\n RouteMetadata,\n StreamDirection,\n ClientRole,\n CallMode,\n} from '@webpieces/core-util';\nimport { BrowserApiCallContext } from './BrowserApiCallContext';\nimport {\n ApiPrototype,\n ByteReadableStream,\n ClientRequest,\n ProxyClient,\n RequestOutcome,\n StreamingCapabilityError,\n} from '@webpieces/http-client-core';\nimport { ClientConfig } from './ClientConfig';\nimport { RequestLifecycleListener } from './RequestLifecycleListener';\nimport { ServiceWorkerRouting } from './ServiceWorkerRouting';\nimport { ServiceWorkerSyntheticResponse } from './ServiceWorkerSyntheticResponse';\n\n/**\n * The browser {@link ProxyClient}. Reads context from the app-held store (via {@link ContextMgr}),\n * because a browser has no ambient request scope.\n *\n * It attaches NO outbound credential and does NO recording — both inherit the base's no-ops. A\n * browser cannot mint an OIDC token and must never hold a shared secret; the user's JWT travels as\n * an ordinary transferred context key, set on the store at login.\n *\n * This is the ONLY class in webpieces that names ContextMgr.\n */\nexport class BrowserProxyClient extends ProxyClient {\n protected override selectAuthMethod(route: RouteMetadata): import('@webpieces/core-util').AuthMode {\n const selected = route.authMeta?.methods.find((method: import('@webpieces/core-util').AuthMode) => method.kind === 'jwt' || method.kind === 'public');\n if (!selected) {\n const methods = route.authMeta?.methods.map((method: import('@webpieces/core-util').AuthMode) => method.kind === 'apikey' ? `apiKey('${method.regime}', credentials)` : method.kind).join(', ');\n throw new Error(`Endpoint ${route.apiName}.${route.methodName} declares ${methods}. A browser cannot hold these credentials; call it from a server-side client with the configured verifier credentials.`);\n }\n return selected;\n }\n private config!: ClientConfig;\n\n /** The query parameter Angular's service worker (`Driver.onFetch`) honours to skip a request. */\n static readonly NGSW_BYPASS_PARAM = 'ngsw-bypass';\n\n // Stateless, so constructed here rather than injected — the browser bundle keeps no DI on the fetch path.\n private readonly syntheticResponse = new ServiceWorkerSyntheticResponse();\n\n constructor(\n private readonly contextMgr: ContextMgr,\n private readonly lifecycleListener?: RequestLifecycleListener,\n ) {\n // The browser's ApiCallContext, constructed here rather than installed at startup: its store\n // is static, so every instance stamps into the one slot BrowserApiCallContext.snapshot()\n // reads — which is how a browser logger folds the `api` tag into each line.\n super(new LogApiCallImpl(new BrowserApiCallContext()));\n }\n\n /** Bind this client to one API contract + base URL. */\n init(apiPrototype: ApiPrototype<object>, config: ClientConfig): void {\n this.config = config;\n // The browser factory does not take app filters yet, so this client runs the framework\n // built-ins only (today: none). The chain itself is isomorphic and ready for them.\n this.initRoutes(apiPrototype, []);\n }\n\n /**\n * The same chain every client runs — a ClientRegistry mapping, else the installed deriver — but\n * with the BROWSER's fallback: `''`, which makes the URL RELATIVE (`/auth/oauth`) and therefore\n * same-origin, by definition. A browser app almost always calls the backend that served it, so\n * that is the default, and an unregistered svcName must NEVER throw the way it used to — a\n * forgotten registration silently killed sign-in, the request never leaving the page.\n *\n * A mapping still wins, which is exactly how an Angular dev server on :4201 reaches its backend\n * on :8201, while the same bundle served BY that backend in prod registers nothing and goes\n * relative. No `window` access, so this stays SSR-safe and testable.\n */\n protected override clientRole(): ClientRole {\n return this.config.role;\n }\n\n /** From {@link ClientConfig.callMode}: a BACKGROUND client stamps every route and failure with it. */\n protected override callMode(): CallMode {\n return this.config.callMode;\n }\n\n /**\n * Append `ngsw-bypass=true` unless {@link ClientConfig.serviceWorker} is ALLOW (#1293), so ngsw\n * never intercepts the RPC and a network reject arrives as a native reject — which\n * `NetworkRejectClassifier` types as `ApiConnectionError` — instead of ngsw's synthetic 504.\n */\n protected override transportUrl(request: ClientRequest): string {\n const url = request.url;\n if (this.config.serviceWorker === ServiceWorkerRouting.ALLOW) {\n return url;\n }\n const separator = url.includes('?') ? '&' : '?';\n return `${url}${separator}${BrowserProxyClient.NGSW_BYPASS_PARAM}=true`;\n }\n\n /**\n * One transmission, then the fallback for a service worker that intercepted anyway (ALLOW, or a\n * worker other than ngsw honouring nothing): its synthetic 504 becomes `ApiConnectionError` with\n * the response as cause. A real gateway 504 has headers, so it stays `ApiDependencyTimeoutError`.\n */\n protected override async sendOnce(request: ClientRequest, signal: AbortSignal): Promise<Response> {\n const response = await super.sendOnce(request, signal);\n return this.syntheticResponse.rejectIfSynthetic(response, request.url);\n }\n\n protected override async resolveBaseUrl(): Promise<string> {\n return (await ClientRegistry.tryResolve(this.config.svcName)) ?? '';\n }\n\n /** Browser Fetch request streaming is specified as half-duplex, not concurrent duplex. */\n protected override supportsConcurrentDuplexFetch(): boolean {\n return false;\n }\n\n protected override sendStreamingTransport(\n _request: ClientRequest,\n _signal: AbortSignal,\n _body: ByteReadableStream,\n ): Promise<Response> {\n return Promise.reject(\n new StreamingCapabilityError(\n 'browser',\n 'Fetch request streaming is half-duplex and has no safe bidirectional fallback.',\n ),\n );\n }\n\n /**\n * `destination` is always the un-verifying kind here — {@link assertEndpointSupported} below\n * refuses to bind an oidcSameProject() / oidcSvcs(...) / sharedSecret(...) contract, so every browser destination is\n * jwt() or @WpAuthPublic — which means a browser never puts a trusted context key on the wire. It is\n * still threaded rather than short-circuited: the rule lives in ContextMgr, one place, for both\n * environments.\n */\n protected override outboundContextHeaders(destination: DestinationTrust): Map<string, string> {\n return this.contextMgr.buildOutboundHeaders(destination);\n }\n\n /**\n * Into the app-held store, via the same {@link ContextMgr} that owns the outbound direction — so\n * a value a server set reaches the page without the page naming a header.\n *\n * TRUSTED response keys are dropped there, by type: a browser store holds only untrusted values.\n * `destination` is threaded anyway rather than short-circuited here, for the reason the outbound\n * direction gives — the rule lives in ContextMgr, one place, for both environments.\n */\n protected override acceptResponseContext(\n headers: Headers,\n destination: DestinationTrust,\n ): void {\n this.contextMgr.acceptResponseHeaders(headers, destination);\n }\n\n /**\n * Forward the call's lifecycle to the app's listener, if one was registered on the factory. The\n * optional chain makes both a no-op when no listener is present — the default browser case.\n */\n protected override onRequestStart(route: RouteMetadata): void {\n this.lifecycleListener?.onRequestStart(route);\n }\n\n protected override onRequestEnd(route: RouteMetadata, outcome: RequestOutcome): void {\n this.lifecycleListener?.onRequestEnd(route, outcome);\n }\n\n /**\n * Reject a contract this browser cannot satisfy, at bind time rather than on the first call.\n * Both service-to-service modes need credentials only a server has: OIDC (oidcSameProject() / oidcSvcs(...)) needs a runtime\n * service account to mint a token, sharedSecret(...) needs a secret no browser may ship.\n *\n * @WpLocalOnly is deliberately NOT rejected: a browser calling a dev-only endpoint on the\n * developer's own server is the motivating case for that mode (shipping browser logs into the\n * server log). It needs no credential — the server refuses it off-local by not having the route.\n *\n * An exhaustive switch with NO `default`, like {@link DestinationTrust.forAuthMode} and\n * `AuthFilter.verifiesCaller`. This was a NEGATIVE allow-list (`kind !== 'oidc' && kind !==\n * 'shared-secret'`), which silently WAVED THROUGH any future AuthMode kind — the browser would\n * have bound a contract it cannot satisfy and failed on the first call instead of at bind time.\n * Adding `local-only` is what surfaced it: the third reader of the union should fail to compile\n * on a NEW kind for the same reason the other two do.\n */\n protected override assertEndpointSupported(route: RouteMetadata): void {\n const methodName = route.methodName;\n if (route.streaming && route.streaming.direction !== StreamDirection.RESPONSE) {\n throw new StreamingCapabilityError(\n 'browser',\n `Browser Fetch supports only @WpStream(StreamDirection.RESPONSE); ${methodName} is ${route.streaming.direction}.`,\n );\n }\n this.selectAuthMethod(route);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BrowserProxyClient.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/BrowserProxyClient.ts"],"names":[],"mappings":";;;AAAA,oDAS8B;AAC9B,mEAAgE;AAChE,kEAQqC;AAGrC,iEAA8D;AAC9D,qFAAkF;AAElF;;;;;;;;;GASG;AACH,MAAa,kBAAmB,SAAQ,8BAAW;IAkB1B;IAEA;IAnBF,gBAAgB,CAAC,KAAoB;QACpD,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,MAA+C,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK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AC;IAC7D,CAAC;IAED;;;;;;;OAOG;IACgB,qBAAqB,CACpC,OAAgB,EAChB,WAA6B;QAE7B,IAAI,CAAC,UAAU,CAAC,qBAAqB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAChE,CAAC;IAED;;;OAGG;IACgB,cAAc,CAAC,KAAoB;QAClD,IAAI,CAAC,iBAAiB,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IAEkB,YAAY,CAAC,KAAoB,EAAE,OAAuB;QACzE,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACgB,uBAAuB,CAAC,KAAoB;QAC3D,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;QACpC,IAAI,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC,SAAS,KAAK,2BAAe,CAAC,QAAQ,EAAE,CAAC;YAC5E,MAAM,IAAI,2CAAwB,CAC9B,SAAS,EACT,oEAAoE,UAAU,OAAO,KAAK,CAAC,SAAS,CAAC,SAAS,GAAG,CACpH,CAAC;QACN,CAAC;QACD,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;;AAtKL,gDAuKC","sourcesContent":["import {\n ContextMgr,\n ClientRegistry,\n DestinationTrust,\n LogApiCallImpl,\n RouteMetadata,\n StreamDirection,\n ClientRole,\n CallMode,\n} from '@webpieces/core-util';\nimport { BrowserApiCallContext } from './BrowserApiCallContext';\nimport {\n ApiPrototype,\n ByteReadableStream,\n ClientRequest,\n HttpClientRuntime,\n ProxyClient,\n RequestOutcome,\n StreamingCapabilityError,\n} from '@webpieces/http-client-core';\nimport { ClientConfig } from './ClientConfig';\nimport { RequestLifecycleListener } from './RequestLifecycleListener';\nimport { ServiceWorkerRouting } from './ServiceWorkerRouting';\nimport { ServiceWorkerSyntheticResponse } from './ServiceWorkerSyntheticResponse';\n\n/**\n * The browser {@link ProxyClient}. Reads context from the app-held store (via {@link ContextMgr}),\n * because a browser has no ambient request scope.\n *\n * It attaches NO outbound credential and does NO recording — both inherit the base's no-ops. A\n * browser cannot mint an OIDC token and must never hold a shared secret; the user's JWT travels as\n * an ordinary transferred context key, set on the store at login.\n *\n * This is the ONLY class in webpieces that names ContextMgr.\n */\nexport class BrowserProxyClient extends ProxyClient {\n protected override selectAuthMethod(route: RouteMetadata): import('@webpieces/core-util').AuthMode {\n const selected = route.authMeta?.methods.find((method: import('@webpieces/core-util').AuthMode) => method.kind === 'jwt' || method.kind === 'public');\n if (!selected) {\n const methods = route.authMeta?.methods.map((method: import('@webpieces/core-util').AuthMode) => method.kind === 'apikey' ? `apiKey('${method.regime}', credentials)` : method.kind).join(', ');\n throw new Error(`Endpoint ${route.apiName}.${route.methodName} declares ${methods}. A browser cannot hold these credentials; call it from a server-side client with the configured verifier credentials.`);\n }\n return selected;\n }\n private config!: ClientConfig;\n\n /** The query parameter Angular's service worker (`Driver.onFetch`) honours to skip a request. */\n static readonly NGSW_BYPASS_PARAM = 'ngsw-bypass';\n\n // Stateless, so constructed here rather than injected — the browser bundle keeps no DI on the fetch path.\n private readonly syntheticResponse = new ServiceWorkerSyntheticResponse();\n\n constructor(\n private readonly contextMgr: ContextMgr,\n runtime: HttpClientRuntime,\n private readonly lifecycleListener?: RequestLifecycleListener,\n ) {\n // The browser's ApiCallContext, constructed here rather than installed at startup: its store\n // is static, so every instance stamps into the one slot BrowserApiCallContext.snapshot()\n // reads — which is how a browser logger folds the `api` tag into each line. The runtime is\n // the factory's (#1445): platform fetch + JS timers, or the app's native-backed pair.\n super(new LogApiCallImpl(new BrowserApiCallContext()), runtime);\n }\n\n /** Bind this client to one API contract + base URL. */\n init(apiPrototype: ApiPrototype<object>, config: ClientConfig): void {\n this.config = config;\n // The browser factory does not take app filters yet, so this client runs the framework\n // built-ins only (today: none). The chain itself is isomorphic and ready for them.\n this.initRoutes(apiPrototype, []);\n }\n\n /**\n * The same chain every client runs — a ClientRegistry mapping, else the installed deriver — but\n * with the BROWSER's fallback: `''`, which makes the URL RELATIVE (`/auth/oauth`) and therefore\n * same-origin, by definition. A browser app almost always calls the backend that served it, so\n * that is the default, and an unregistered svcName must NEVER throw the way it used to — a\n * forgotten registration silently killed sign-in, the request never leaving the page.\n *\n * A mapping still wins, which is exactly how an Angular dev server on :4201 reaches its backend\n * on :8201, while the same bundle served BY that backend in prod registers nothing and goes\n * relative. No `window` access, so this stays SSR-safe and testable.\n */\n protected override clientRole(): ClientRole {\n return this.config.role;\n }\n\n /** From {@link ClientConfig.callMode}: a BACKGROUND client stamps every route and failure with it. */\n protected override callMode(): CallMode {\n return this.config.callMode;\n }\n\n /**\n * Append `ngsw-bypass=true` unless {@link ClientConfig.serviceWorker} is ALLOW (#1293), so ngsw\n * never intercepts the RPC and a network reject arrives as a native reject — which\n * `NetworkRejectClassifier` types as `ApiConnectionError` — instead of ngsw's synthetic 504.\n */\n protected override transportUrl(request: ClientRequest): string {\n const url = request.url;\n if (this.config.serviceWorker === ServiceWorkerRouting.ALLOW) {\n return url;\n }\n const separator = url.includes('?') ? '&' : '?';\n return `${url}${separator}${BrowserProxyClient.NGSW_BYPASS_PARAM}=true`;\n }\n\n /**\n * One transmission, then the fallback for a service worker that intercepted anyway (ALLOW, or a\n * worker other than ngsw honouring nothing): its synthetic 504 becomes `ApiConnectionError` with\n * the response as cause. A real gateway 504 has headers, so it stays `ApiDependencyTimeoutError`.\n */\n protected override async sendOnce(request: ClientRequest, signal: AbortSignal): Promise<Response> {\n const response = await super.sendOnce(request, signal);\n return this.syntheticResponse.rejectIfSynthetic(response, request.url);\n }\n\n protected override async resolveBaseUrl(): Promise<string> {\n return (await ClientRegistry.tryResolve(this.config.svcName)) ?? '';\n }\n\n /** Browser Fetch request streaming is specified as half-duplex, not concurrent duplex. */\n protected override supportsConcurrentDuplexFetch(): boolean {\n return false;\n }\n\n protected override sendStreamingTransport(\n _request: ClientRequest,\n _signal: AbortSignal,\n _body: ByteReadableStream,\n ): Promise<Response> {\n return Promise.reject(\n new StreamingCapabilityError(\n 'browser',\n 'Fetch request streaming is half-duplex and has no safe bidirectional fallback.',\n ),\n );\n }\n\n /**\n * `destination` is always the un-verifying kind here — {@link assertEndpointSupported} below\n * refuses to bind an oidcSameProject() / oidcSvcs(...) / sharedSecret(...) contract, so every browser destination is\n * jwt() or @WpAuthPublic — which means a browser never puts a trusted context key on the wire. It is\n * still threaded rather than short-circuited: the rule lives in ContextMgr, one place, for both\n * environments.\n */\n protected override outboundContextHeaders(destination: DestinationTrust): Map<string, string> {\n return this.contextMgr.buildOutboundHeaders(destination);\n }\n\n /**\n * Into the app-held store, via the same {@link ContextMgr} that owns the outbound direction — so\n * a value a server set reaches the page without the page naming a header.\n *\n * TRUSTED response keys are dropped there, by type: a browser store holds only untrusted values.\n * `destination` is threaded anyway rather than short-circuited here, for the reason the outbound\n * direction gives — the rule lives in ContextMgr, one place, for both environments.\n */\n protected override acceptResponseContext(\n headers: Headers,\n destination: DestinationTrust,\n ): void {\n this.contextMgr.acceptResponseHeaders(headers, destination);\n }\n\n /**\n * Forward the call's lifecycle to the app's listener, if one was registered on the factory. The\n * optional chain makes both a no-op when no listener is present — the default browser case.\n */\n protected override onRequestStart(route: RouteMetadata): void {\n this.lifecycleListener?.onRequestStart(route);\n }\n\n protected override onRequestEnd(route: RouteMetadata, outcome: RequestOutcome): void {\n this.lifecycleListener?.onRequestEnd(route, outcome);\n }\n\n /**\n * Reject a contract this browser cannot satisfy, at bind time rather than on the first call.\n * Both service-to-service modes need credentials only a server has: OIDC (oidcSameProject() / oidcSvcs(...)) needs a runtime\n * service account to mint a token, sharedSecret(...) needs a secret no browser may ship.\n *\n * @WpLocalOnly is deliberately NOT rejected: a browser calling a dev-only endpoint on the\n * developer's own server is the motivating case for that mode (shipping browser logs into the\n * server log). It needs no credential — the server refuses it off-local by not having the route.\n *\n * An exhaustive switch with NO `default`, like {@link DestinationTrust.forAuthMode} and\n * `AuthFilter.verifiesCaller`. This was a NEGATIVE allow-list (`kind !== 'oidc' && kind !==\n * 'shared-secret'`), which silently WAVED THROUGH any future AuthMode kind — the browser would\n * have bound a contract it cannot satisfy and failed on the first call instead of at bind time.\n * Adding `local-only` is what surfaced it: the third reader of the union should fail to compile\n * on a NEW kind for the same reason the other two do.\n */\n protected override assertEndpointSupported(route: RouteMetadata): void {\n const methodName = route.methodName;\n if (route.streaming && route.streaming.direction !== StreamDirection.RESPONSE) {\n throw new StreamingCapabilityError(\n 'browser',\n `Browser Fetch supports only @WpStream(StreamDirection.RESPONSE); ${methodName} is ${route.streaming.direction}.`,\n );\n }\n this.selectAuthMethod(route);\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiPrototype } from '@webpieces/http-client-core';
|
|
1
|
+
import { ApiPrototype, HttpClientRuntime } from '@webpieces/http-client-core';
|
|
2
2
|
import { ClientConfig } from './ClientConfig';
|
|
3
3
|
import { MutableContextStore } from './MutableContextStore';
|
|
4
4
|
import { RequestLifecycleListener } from './RequestLifecycleListener';
|
|
@@ -29,11 +29,33 @@ import { RequestLifecycleListener } from './RequestLifecycleListener';
|
|
|
29
29
|
*
|
|
30
30
|
* A browser cannot hold service credentials, so a contract with an oidcSameProject() / oidcSvcs(...) or sharedSecret(...)
|
|
31
31
|
* endpoint throws in `createRpcClient`, not on the first call.
|
|
32
|
+
*
|
|
33
|
+
* **Runtime (#1445).** The optional third argument is this factory's {@link HttpClientRuntime}: the
|
|
34
|
+
* fetch every client it builds sends through and the clock their deadlines use. Omitted, a browser or
|
|
35
|
+
* WebView page gets the platform fetch and JS timers, exactly as before. In the React Native JS
|
|
36
|
+
* runtime (detected by `navigator.product === 'ReactNative'`) omitting it — or passing
|
|
37
|
+
* `HttpClientRuntime.platformDefaults()` — THROWS {@link ReactNativeRuntimeConfigError} here, before
|
|
38
|
+
* any request, because React Native's default fetch and JS timers can stop while a phone is locked:
|
|
39
|
+
*
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { fetch as expoFetch } from 'expo/fetch';
|
|
42
|
+
* const factory = new ClientHttpBrowserFactory(
|
|
43
|
+
* store,
|
|
44
|
+
* listener,
|
|
45
|
+
* HttpClientRuntime.reactNative(expoFetch, nativeDeadlineScheduler),
|
|
46
|
+
* );
|
|
47
|
+
* ```
|
|
32
48
|
*/
|
|
33
49
|
export declare class ClientHttpBrowserFactory {
|
|
34
50
|
private readonly lifecycleListener?;
|
|
35
51
|
private readonly contextMgr;
|
|
36
|
-
|
|
52
|
+
private readonly runtime;
|
|
53
|
+
constructor(store: MutableContextStore, lifecycleListener?: RequestLifecycleListener | undefined, runtime?: HttpClientRuntime);
|
|
54
|
+
/**
|
|
55
|
+
* The supplied runtime, else the platform defaults — unless this is the React Native JS runtime,
|
|
56
|
+
* where only an explicit {@link HttpClientRuntime.reactNative} is accepted.
|
|
57
|
+
*/
|
|
58
|
+
private static selectRuntime;
|
|
37
59
|
/**
|
|
38
60
|
* Create a type-safe HTTP client for one API contract.
|
|
39
61
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var ClientHttpBrowserFactory_1;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.ClientHttpBrowserFactory = void 0;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
@@ -6,6 +7,7 @@ const core_util_1 = require("@webpieces/core-util");
|
|
|
6
7
|
const http_client_core_1 = require("@webpieces/http-client-core");
|
|
7
8
|
const BrowserProxyClient_1 = require("./BrowserProxyClient");
|
|
8
9
|
const MutableContextStore_1 = require("./MutableContextStore");
|
|
10
|
+
const ReactNativeRuntimeDetector_1 = require("./ReactNativeRuntimeDetector");
|
|
9
11
|
/**
|
|
10
12
|
* ClientHttpBrowserFactory - builds type-safe HTTP clients for a BROWSER from API prototypes
|
|
11
13
|
* carrying @ApiPath/@Endpoint decorators.
|
|
@@ -33,13 +35,43 @@ const MutableContextStore_1 = require("./MutableContextStore");
|
|
|
33
35
|
*
|
|
34
36
|
* A browser cannot hold service credentials, so a contract with an oidcSameProject() / oidcSvcs(...) or sharedSecret(...)
|
|
35
37
|
* endpoint throws in `createRpcClient`, not on the first call.
|
|
38
|
+
*
|
|
39
|
+
* **Runtime (#1445).** The optional third argument is this factory's {@link HttpClientRuntime}: the
|
|
40
|
+
* fetch every client it builds sends through and the clock their deadlines use. Omitted, a browser or
|
|
41
|
+
* WebView page gets the platform fetch and JS timers, exactly as before. In the React Native JS
|
|
42
|
+
* runtime (detected by `navigator.product === 'ReactNative'`) omitting it — or passing
|
|
43
|
+
* `HttpClientRuntime.platformDefaults()` — THROWS {@link ReactNativeRuntimeConfigError} here, before
|
|
44
|
+
* any request, because React Native's default fetch and JS timers can stop while a phone is locked:
|
|
45
|
+
*
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { fetch as expoFetch } from 'expo/fetch';
|
|
48
|
+
* const factory = new ClientHttpBrowserFactory(
|
|
49
|
+
* store,
|
|
50
|
+
* listener,
|
|
51
|
+
* HttpClientRuntime.reactNative(expoFetch, nativeDeadlineScheduler),
|
|
52
|
+
* );
|
|
53
|
+
* ```
|
|
36
54
|
*/
|
|
37
|
-
let ClientHttpBrowserFactory = class ClientHttpBrowserFactory {
|
|
55
|
+
let ClientHttpBrowserFactory = ClientHttpBrowserFactory_1 = class ClientHttpBrowserFactory {
|
|
38
56
|
lifecycleListener;
|
|
39
57
|
contextMgr;
|
|
40
|
-
|
|
58
|
+
runtime;
|
|
59
|
+
constructor(store, lifecycleListener, runtime) {
|
|
41
60
|
this.lifecycleListener = lifecycleListener;
|
|
42
61
|
this.contextMgr = new core_util_1.ContextMgr(store);
|
|
62
|
+
this.runtime = ClientHttpBrowserFactory_1.selectRuntime(runtime, new ReactNativeRuntimeDetector_1.ReactNativeRuntimeDetector());
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The supplied runtime, else the platform defaults — unless this is the React Native JS runtime,
|
|
66
|
+
* where only an explicit {@link HttpClientRuntime.reactNative} is accepted.
|
|
67
|
+
*/
|
|
68
|
+
// webpieces-disable no-function-outside-class -- pure construction-time selection
|
|
69
|
+
static selectRuntime(runtime, detector) {
|
|
70
|
+
const selected = runtime ?? http_client_core_1.HttpClientRuntime.platformDefaults();
|
|
71
|
+
if (selected.kind !== http_client_core_1.HttpRuntimeKind.REACT_NATIVE && detector.isReactNative()) {
|
|
72
|
+
throw new http_client_core_1.ReactNativeRuntimeConfigError(['fetch', 'deadlines'], 'new ClientHttpBrowserFactory(...)');
|
|
73
|
+
}
|
|
74
|
+
return selected;
|
|
43
75
|
}
|
|
44
76
|
/**
|
|
45
77
|
* Create a type-safe HTTP client for one API contract.
|
|
@@ -49,14 +81,14 @@ let ClientHttpBrowserFactory = class ClientHttpBrowserFactory {
|
|
|
49
81
|
*/
|
|
50
82
|
createRpcClient(apiPrototype, config) {
|
|
51
83
|
(0, core_util_1.assertNotInternalApi)(apiPrototype, 'ClientHttpBrowserFactory');
|
|
52
|
-
const proxyClient = new BrowserProxyClient_1.BrowserProxyClient(this.contextMgr, this.lifecycleListener);
|
|
84
|
+
const proxyClient = new BrowserProxyClient_1.BrowserProxyClient(this.contextMgr, this.runtime, this.lifecycleListener);
|
|
53
85
|
proxyClient.init(apiPrototype, config);
|
|
54
86
|
return (0, http_client_core_1.buildClientProxy)(apiPrototype, proxyClient);
|
|
55
87
|
}
|
|
56
88
|
};
|
|
57
89
|
exports.ClientHttpBrowserFactory = ClientHttpBrowserFactory;
|
|
58
|
-
exports.ClientHttpBrowserFactory = ClientHttpBrowserFactory = tslib_1.__decorate([
|
|
90
|
+
exports.ClientHttpBrowserFactory = ClientHttpBrowserFactory = ClientHttpBrowserFactory_1 = tslib_1.__decorate([
|
|
59
91
|
(0, core_util_1.DocumentDesign)(),
|
|
60
|
-
tslib_1.__metadata("design:paramtypes", [MutableContextStore_1.MutableContextStore, Object])
|
|
92
|
+
tslib_1.__metadata("design:paramtypes", [MutableContextStore_1.MutableContextStore, Object, http_client_core_1.HttpClientRuntime])
|
|
61
93
|
], ClientHttpBrowserFactory);
|
|
62
94
|
//# sourceMappingURL=ClientHttpBrowserFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientHttpBrowserFactory.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/ClientHttpBrowserFactory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ClientHttpBrowserFactory.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/ClientHttpBrowserFactory.ts"],"names":[],"mappings":";;;;;AAAA,oDAAwF;AACxF,kEAMqC;AACrC,6DAA0D;AAE1D,+DAA4D;AAE5D,6EAA0E;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEI,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAMZ;IALJ,UAAU,CAAa;IACvB,OAAO,CAAoB;IAE5C,YACI,KAA0B,EACT,iBAA4C,EAC7D,OAA2B;QADV,sBAAiB,GAAjB,iBAAiB,CAA2B;QAG7D,IAAI,CAAC,UAAU,GAAG,IAAI,sBAAU,CAAC,KAAK,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,0BAAwB,CAAC,aAAa,CACjD,OAAO,EACP,IAAI,uDAA0B,EAAE,CACnC,CAAC;IACN,CAAC;IAED;;;OAGG;IACH,kFAAkF;IAC1E,MAAM,CAAC,aAAa,CACxB,OAAsC,EACtC,QAAoC;QAEpC,MAAM,QAAQ,GAAG,OAAO,IAAI,oCAAiB,CAAC,gBAAgB,EAAE,CAAC;QACjE,IAAI,QAAQ,CAAC,IAAI,KAAK,kCAAe,CAAC,YAAY,IAAI,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC;YAC7E,MAAM,IAAI,gDAA6B,CACnC,CAAC,OAAO,EAAE,WAAW,CAAC,EACtB,mCAAmC,CACtC,CAAC;QACN,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAmB,YAA6B,EAAE,MAAoB;QACjF,IAAA,gCAAoB,EAAC,YAAY,EAAE,0BAA0B,CAAC,CAAC;QAC/D,MAAM,WAAW,GAAG,IAAI,uCAAkB,CACtC,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,iBAAiB,CACzB,CAAC;QACF,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QACvC,OAAO,IAAA,mCAAgB,EAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IACvD,CAAC;CACJ,CAAA;AAnDY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,0BAAc,GAAE;6CAMF,yCAAmB,UAEhB,oCAAiB;GAPtB,wBAAwB,CAmDpC","sourcesContent":["import { assertNotInternalApi, ContextMgr, DocumentDesign } from '@webpieces/core-util';\nimport {\n ApiPrototype,\n buildClientProxy,\n HttpClientRuntime,\n HttpRuntimeKind,\n ReactNativeRuntimeConfigError,\n} from '@webpieces/http-client-core';\nimport { BrowserProxyClient } from './BrowserProxyClient';\nimport { ClientConfig } from './ClientConfig';\nimport { MutableContextStore } from './MutableContextStore';\nimport { RequestLifecycleListener } from './RequestLifecycleListener';\nimport { ReactNativeRuntimeDetector } from './ReactNativeRuntimeDetector';\n\n/**\n * ClientHttpBrowserFactory - builds type-safe HTTP clients for a BROWSER from API prototypes\n * carrying @ApiPath/@Endpoint decorators.\n *\n * Deliberately a plain class with NO decorators and NO inversify: this package may be bundled by\n * React just as easily as by Angular, and neither should be forced to adopt a Node DI container.\n * The app provides it through whatever DI it already has — Angular's `useFactory`, a React context,\n * or a module-level `const`.\n *\n * The factory holds the ONE collaborator every browser client shares (the app's\n * {@link MutableContextStore}); each {@link ClientConfig} holds only that one client's base URL.\n *\n * ```typescript\n * // once, at startup (after HeaderRegistry.configure(...)):\n * const store = new MutableContextStore();\n * const factory = new ClientHttpBrowserFactory(store);\n *\n * const saveApi = factory.createRpcClient(SaveApi, new ClientConfig('server', ClientRole.END_USER_CLIENT));\n * const response = await saveApi.save({ query: 'test' }); // type-safe\n *\n * // later, when the user logs in / picks a tenant — every subsequent call carries them:\n * store.set(AppHeaders.AUTHORIZATION, token); // an app-defined key, if it wants auto-attach\n * store.set(CompanyHeaders.TENANT_ID, tenantId);\n * ```\n *\n * A browser cannot hold service credentials, so a contract with an oidcSameProject() / oidcSvcs(...) or sharedSecret(...)\n * endpoint throws in `createRpcClient`, not on the first call.\n *\n * **Runtime (#1445).** The optional third argument is this factory's {@link HttpClientRuntime}: the\n * fetch every client it builds sends through and the clock their deadlines use. Omitted, a browser or\n * WebView page gets the platform fetch and JS timers, exactly as before. In the React Native JS\n * runtime (detected by `navigator.product === 'ReactNative'`) omitting it — or passing\n * `HttpClientRuntime.platformDefaults()` — THROWS {@link ReactNativeRuntimeConfigError} here, before\n * any request, because React Native's default fetch and JS timers can stop while a phone is locked:\n *\n * ```typescript\n * import { fetch as expoFetch } from 'expo/fetch';\n * const factory = new ClientHttpBrowserFactory(\n * store,\n * listener,\n * HttpClientRuntime.reactNative(expoFetch, nativeDeadlineScheduler),\n * );\n * ```\n */\n@DocumentDesign()\nexport class ClientHttpBrowserFactory {\n private readonly contextMgr: ContextMgr;\n private readonly runtime: HttpClientRuntime;\n\n constructor(\n store: MutableContextStore,\n private readonly lifecycleListener?: RequestLifecycleListener,\n runtime?: HttpClientRuntime,\n ) {\n this.contextMgr = new ContextMgr(store);\n this.runtime = ClientHttpBrowserFactory.selectRuntime(\n runtime,\n new ReactNativeRuntimeDetector(),\n );\n }\n\n /**\n * The supplied runtime, else the platform defaults — unless this is the React Native JS runtime,\n * where only an explicit {@link HttpClientRuntime.reactNative} is accepted.\n */\n // webpieces-disable no-function-outside-class -- pure construction-time selection\n private static selectRuntime(\n runtime: HttpClientRuntime | undefined,\n detector: ReactNativeRuntimeDetector,\n ): HttpClientRuntime {\n const selected = runtime ?? HttpClientRuntime.platformDefaults();\n if (selected.kind !== HttpRuntimeKind.REACT_NATIVE && detector.isReactNative()) {\n throw new ReactNativeRuntimeConfigError(\n ['fetch', 'deadlines'],\n 'new ClientHttpBrowserFactory(...)',\n );\n }\n return selected;\n }\n\n /**\n * Create a type-safe HTTP client for one API contract.\n *\n * @param apiPrototype - The API prototype class with @ApiPath/@Endpoint decorators\n * @param config - This client's state (its baseUrl)\n */\n createRpcClient<T extends object>(apiPrototype: ApiPrototype<T>, config: ClientConfig): T {\n assertNotInternalApi(apiPrototype, 'ClientHttpBrowserFactory');\n const proxyClient = new BrowserProxyClient(\n this.contextMgr,\n this.runtime,\n this.lifecycleListener,\n );\n proxyClient.init(apiPrototype, config);\n return buildClientProxy(apiPrototype, proxyClient);\n }\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recognizes the React Native JAVASCRIPT runtime (#1445) — not "a page embedded in a WebView".
|
|
3
|
+
*
|
|
4
|
+
* The signal is `navigator.product === 'ReactNative'`, which React Native sets in
|
|
5
|
+
* `Libraries/Core/setUpNavigator.js` (verified on 0.83.10). Deliberately NOT used:
|
|
6
|
+
* - `window` / `document` presence — React Native defines window-like globals, and a WebView page's
|
|
7
|
+
* JavaScript has a real `window`; neither tells the two apart.
|
|
8
|
+
* - `window.ReactNativeWebView` — present in a WebView PAGE, which runs on the browser engine's fetch
|
|
9
|
+
* and timers and must keep the browser defaults.
|
|
10
|
+
* - the user agent, or importing `react-native` — this package must stay importable without it.
|
|
11
|
+
*
|
|
12
|
+
* Reads are guarded so Node, SSR, workers and tests (no `navigator`, or one without `product`) are
|
|
13
|
+
* simply "not React Native". A runtime that hides this marker is covered by declaring it explicitly
|
|
14
|
+
* with `HttpClientRuntime.reactNative(...)`.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ReactNativeRuntimeDetector {
|
|
17
|
+
static readonly REACT_NATIVE_PRODUCT = "ReactNative";
|
|
18
|
+
isReactNative(): boolean;
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReactNativeRuntimeDetector = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Recognizes the React Native JAVASCRIPT runtime (#1445) — not "a page embedded in a WebView".
|
|
6
|
+
*
|
|
7
|
+
* The signal is `navigator.product === 'ReactNative'`, which React Native sets in
|
|
8
|
+
* `Libraries/Core/setUpNavigator.js` (verified on 0.83.10). Deliberately NOT used:
|
|
9
|
+
* - `window` / `document` presence — React Native defines window-like globals, and a WebView page's
|
|
10
|
+
* JavaScript has a real `window`; neither tells the two apart.
|
|
11
|
+
* - `window.ReactNativeWebView` — present in a WebView PAGE, which runs on the browser engine's fetch
|
|
12
|
+
* and timers and must keep the browser defaults.
|
|
13
|
+
* - the user agent, or importing `react-native` — this package must stay importable without it.
|
|
14
|
+
*
|
|
15
|
+
* Reads are guarded so Node, SSR, workers and tests (no `navigator`, or one without `product`) are
|
|
16
|
+
* simply "not React Native". A runtime that hides this marker is covered by declaring it explicitly
|
|
17
|
+
* with `HttpClientRuntime.reactNative(...)`.
|
|
18
|
+
*/
|
|
19
|
+
class ReactNativeRuntimeDetector {
|
|
20
|
+
static REACT_NATIVE_PRODUCT = 'ReactNative';
|
|
21
|
+
isReactNative() {
|
|
22
|
+
if (typeof globalThis === 'undefined')
|
|
23
|
+
return false;
|
|
24
|
+
const navigator = globalThis.navigator;
|
|
25
|
+
if (typeof navigator !== 'object' || navigator === null)
|
|
26
|
+
return false;
|
|
27
|
+
return navigator.product === ReactNativeRuntimeDetector.REACT_NATIVE_PRODUCT;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ReactNativeRuntimeDetector = ReactNativeRuntimeDetector;
|
|
31
|
+
//# sourceMappingURL=ReactNativeRuntimeDetector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactNativeRuntimeDetector.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/ReactNativeRuntimeDetector.ts"],"names":[],"mappings":";;;AAUA;;;;;;;;;;;;;;GAcG;AACH,MAAa,0BAA0B;IACnC,MAAM,CAAU,oBAAoB,GAAG,aAAa,CAAC;IAErD,aAAa;QACT,IAAI,OAAO,UAAU,KAAK,WAAW;YAAE,OAAO,KAAK,CAAC;QACpD,MAAM,SAAS,GAAI,UAAkC,CAAC,SAAS,CAAC;QAChE,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI;YAAE,OAAO,KAAK,CAAC;QACtE,OAAO,SAAS,CAAC,OAAO,KAAK,0BAA0B,CAAC,oBAAoB,CAAC;IACjF,CAAC;;AARL,gEASC","sourcesContent":["/** The one navigator field the detector reads. Typed locally: this package ships no DOM assumption. */\ninterface NavigatorProduct {\n readonly product?: string;\n}\n\n/** `globalThis` as the detector reads it — `navigator` may be absent (Node, SSR, some workers). */\ninterface GlobalWithNavigator {\n readonly navigator?: NavigatorProduct | null;\n}\n\n/**\n * Recognizes the React Native JAVASCRIPT runtime (#1445) — not \"a page embedded in a WebView\".\n *\n * The signal is `navigator.product === 'ReactNative'`, which React Native sets in\n * `Libraries/Core/setUpNavigator.js` (verified on 0.83.10). Deliberately NOT used:\n * - `window` / `document` presence — React Native defines window-like globals, and a WebView page's\n * JavaScript has a real `window`; neither tells the two apart.\n * - `window.ReactNativeWebView` — present in a WebView PAGE, which runs on the browser engine's fetch\n * and timers and must keep the browser defaults.\n * - the user agent, or importing `react-native` — this package must stay importable without it.\n *\n * Reads are guarded so Node, SSR, workers and tests (no `navigator`, or one without `product`) are\n * simply \"not React Native\". A runtime that hides this marker is covered by declaring it explicitly\n * with `HttpClientRuntime.reactNative(...)`.\n */\nexport class ReactNativeRuntimeDetector {\n static readonly REACT_NATIVE_PRODUCT = 'ReactNative';\n\n isReactNative(): boolean {\n if (typeof globalThis === 'undefined') return false;\n const navigator = (globalThis as GlobalWithNavigator).navigator;\n if (typeof navigator !== 'object' || navigator === null) return false;\n return navigator.product === ReactNativeRuntimeDetector.REACT_NATIVE_PRODUCT;\n }\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -32,6 +32,10 @@ export { ServiceWorkerSyntheticResponse, ServiceWorkerSyntheticResponseError, }
|
|
|
32
32
|
export { MutableContextStore } from './MutableContextStore';
|
|
33
33
|
export type { RequestLifecycleListener } from './RequestLifecycleListener';
|
|
34
34
|
export { ProxyClient, ClientErrorTranslator, RequestOutcome } from '@webpieces/http-client-core';
|
|
35
|
+
export { HttpClientRuntime, HttpFetchInit, HttpRuntimeKind, ReactNativeRuntimeConfigError, } from '@webpieces/http-client-core';
|
|
36
|
+
export type { HttpFetch } from '@webpieces/http-client-core';
|
|
37
|
+
export { TimerDeadlineScheduler } from '@webpieces/core-util';
|
|
38
|
+
export type { DeadlineScheduler, DeadlineTimer } from '@webpieces/core-util';
|
|
35
39
|
export type { ApiPrototype } from '@webpieces/http-client-core';
|
|
36
40
|
export { StreamingCapabilityError } from '@webpieces/http-client-core';
|
|
37
41
|
export { ContextMgr } from '@webpieces/core-util';
|
package/src/index.js
CHANGED
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
* The server twin is @webpieces/http-client-node.
|
|
26
26
|
*/
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.
|
|
29
|
-
exports.WiringPolicy = exports.BrowserFactoryProvider = void 0;
|
|
28
|
+
exports.ExternalImpl = exports.BrowserWiringProviders = exports.ClientBindOptions = exports.Binder = exports.Queue = exports.PubSub = exports.Rpc = exports.apiKey = exports.vendorAuth = exports.sharedSecret = exports.oidcSvcs = exports.oidcSameProject = exports.jwt = exports.WpLocalOnly = exports.AuthorizationType = exports.WpAuthorization = exports.WpAuth = exports.WpAuthPublic = exports.QueryParams = exports.QueryString = exports.QueryParam = exports.PathParam = exports.Endpoint = exports.ApiPath = exports.WebpiecesCoreHeaders = exports.templateDeriver = exports.CallModeMarker = exports.CallMode = exports.ClientRole = exports.ClientRegistry = exports.HeaderRegistry = exports.ContextKey = exports.ContextMgr = exports.StreamingCapabilityError = exports.TimerDeadlineScheduler = exports.ReactNativeRuntimeConfigError = exports.HttpRuntimeKind = exports.HttpFetchInit = exports.HttpClientRuntime = exports.RequestOutcome = exports.ClientErrorTranslator = exports.ProxyClient = exports.MutableContextStore = exports.ServiceWorkerSyntheticResponseError = exports.ServiceWorkerSyntheticResponse = exports.ServiceWorkerRouting = exports.ClientConfig = exports.BrowserApiCallContext = exports.BrowserProxyClient = exports.ClientHttpBrowserFactory = void 0;
|
|
29
|
+
exports.WiringPolicy = exports.BrowserFactoryProvider = exports.BrowserExistingProvider = exports.BrowserClassProvider = exports.BrowserValueProvider = exports.UseExisting = exports.UseClass = void 0;
|
|
30
30
|
var ClientHttpBrowserFactory_1 = require("./ClientHttpBrowserFactory");
|
|
31
31
|
Object.defineProperty(exports, "ClientHttpBrowserFactory", { enumerable: true, get: function () { return ClientHttpBrowserFactory_1.ClientHttpBrowserFactory; } });
|
|
32
32
|
var BrowserProxyClient_1 = require("./BrowserProxyClient");
|
|
@@ -51,44 +51,52 @@ var http_client_core_1 = require("@webpieces/http-client-core");
|
|
|
51
51
|
Object.defineProperty(exports, "ProxyClient", { enumerable: true, get: function () { return http_client_core_1.ProxyClient; } });
|
|
52
52
|
Object.defineProperty(exports, "ClientErrorTranslator", { enumerable: true, get: function () { return http_client_core_1.ClientErrorTranslator; } });
|
|
53
53
|
Object.defineProperty(exports, "RequestOutcome", { enumerable: true, get: function () { return http_client_core_1.RequestOutcome; } });
|
|
54
|
+
// #1445: the factory's runtime collaborator — injected fetch + deadline clock, required in React Native.
|
|
54
55
|
var http_client_core_2 = require("@webpieces/http-client-core");
|
|
55
|
-
Object.defineProperty(exports, "
|
|
56
|
+
Object.defineProperty(exports, "HttpClientRuntime", { enumerable: true, get: function () { return http_client_core_2.HttpClientRuntime; } });
|
|
57
|
+
Object.defineProperty(exports, "HttpFetchInit", { enumerable: true, get: function () { return http_client_core_2.HttpFetchInit; } });
|
|
58
|
+
Object.defineProperty(exports, "HttpRuntimeKind", { enumerable: true, get: function () { return http_client_core_2.HttpRuntimeKind; } });
|
|
59
|
+
Object.defineProperty(exports, "ReactNativeRuntimeConfigError", { enumerable: true, get: function () { return http_client_core_2.ReactNativeRuntimeConfigError; } });
|
|
60
|
+
var core_util_1 = require("@webpieces/core-util");
|
|
61
|
+
Object.defineProperty(exports, "TimerDeadlineScheduler", { enumerable: true, get: function () { return core_util_1.TimerDeadlineScheduler; } });
|
|
62
|
+
var http_client_core_3 = require("@webpieces/http-client-core");
|
|
63
|
+
Object.defineProperty(exports, "StreamingCapabilityError", { enumerable: true, get: function () { return http_client_core_3.StreamingCapabilityError; } });
|
|
56
64
|
// ContextMgr is the BROWSER's outbound-header propagation. This is the only package that may use
|
|
57
65
|
// it; the server reads RequestContext directly (RequestContextHeaders in @webpieces/core-context).
|
|
58
|
-
var core_util_1 = require("@webpieces/core-util");
|
|
59
|
-
Object.defineProperty(exports, "ContextMgr", { enumerable: true, get: function () { return core_util_1.ContextMgr; } });
|
|
60
|
-
// Re-export the context-key contract from core-util for convenience (browser one-import)
|
|
61
66
|
var core_util_2 = require("@webpieces/core-util");
|
|
62
|
-
Object.defineProperty(exports, "
|
|
63
|
-
|
|
64
|
-
Object.defineProperty(exports, "ClientRegistry", { enumerable: true, get: function () { return core_util_2.ClientRegistry; } });
|
|
65
|
-
Object.defineProperty(exports, "ClientRole", { enumerable: true, get: function () { return core_util_2.ClientRole; } });
|
|
66
|
-
Object.defineProperty(exports, "CallMode", { enumerable: true, get: function () { return core_util_2.CallMode; } });
|
|
67
|
-
Object.defineProperty(exports, "CallModeMarker", { enumerable: true, get: function () { return core_util_2.CallModeMarker; } });
|
|
68
|
-
Object.defineProperty(exports, "templateDeriver", { enumerable: true, get: function () { return core_util_2.templateDeriver; } });
|
|
69
|
-
Object.defineProperty(exports, "WebpiecesCoreHeaders", { enumerable: true, get: function () { return core_util_2.WebpiecesCoreHeaders; } });
|
|
70
|
-
// Re-export API decorators for convenience (same as http-routing does)
|
|
67
|
+
Object.defineProperty(exports, "ContextMgr", { enumerable: true, get: function () { return core_util_2.ContextMgr; } });
|
|
68
|
+
// Re-export the context-key contract from core-util for convenience (browser one-import)
|
|
71
69
|
var core_util_3 = require("@webpieces/core-util");
|
|
72
|
-
Object.defineProperty(exports, "
|
|
73
|
-
Object.defineProperty(exports, "
|
|
74
|
-
Object.defineProperty(exports, "
|
|
75
|
-
Object.defineProperty(exports, "
|
|
76
|
-
Object.defineProperty(exports, "
|
|
77
|
-
Object.defineProperty(exports, "
|
|
78
|
-
Object.defineProperty(exports, "
|
|
79
|
-
Object.defineProperty(exports, "
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
Object.defineProperty(exports, "
|
|
83
|
-
Object.defineProperty(exports, "
|
|
84
|
-
Object.defineProperty(exports, "
|
|
85
|
-
Object.defineProperty(exports, "
|
|
86
|
-
Object.defineProperty(exports, "
|
|
87
|
-
Object.defineProperty(exports, "
|
|
88
|
-
Object.defineProperty(exports, "
|
|
89
|
-
Object.defineProperty(exports, "
|
|
90
|
-
Object.defineProperty(exports, "
|
|
91
|
-
Object.defineProperty(exports, "
|
|
70
|
+
Object.defineProperty(exports, "ContextKey", { enumerable: true, get: function () { return core_util_3.ContextKey; } });
|
|
71
|
+
Object.defineProperty(exports, "HeaderRegistry", { enumerable: true, get: function () { return core_util_3.HeaderRegistry; } });
|
|
72
|
+
Object.defineProperty(exports, "ClientRegistry", { enumerable: true, get: function () { return core_util_3.ClientRegistry; } });
|
|
73
|
+
Object.defineProperty(exports, "ClientRole", { enumerable: true, get: function () { return core_util_3.ClientRole; } });
|
|
74
|
+
Object.defineProperty(exports, "CallMode", { enumerable: true, get: function () { return core_util_3.CallMode; } });
|
|
75
|
+
Object.defineProperty(exports, "CallModeMarker", { enumerable: true, get: function () { return core_util_3.CallModeMarker; } });
|
|
76
|
+
Object.defineProperty(exports, "templateDeriver", { enumerable: true, get: function () { return core_util_3.templateDeriver; } });
|
|
77
|
+
Object.defineProperty(exports, "WebpiecesCoreHeaders", { enumerable: true, get: function () { return core_util_3.WebpiecesCoreHeaders; } });
|
|
78
|
+
// Re-export API decorators for convenience (same as http-routing does)
|
|
79
|
+
var core_util_4 = require("@webpieces/core-util");
|
|
80
|
+
Object.defineProperty(exports, "ApiPath", { enumerable: true, get: function () { return core_util_4.ApiPath; } });
|
|
81
|
+
Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return core_util_4.Endpoint; } });
|
|
82
|
+
Object.defineProperty(exports, "PathParam", { enumerable: true, get: function () { return core_util_4.PathParam; } });
|
|
83
|
+
Object.defineProperty(exports, "QueryParam", { enumerable: true, get: function () { return core_util_4.QueryParam; } });
|
|
84
|
+
Object.defineProperty(exports, "QueryString", { enumerable: true, get: function () { return core_util_4.QueryString; } });
|
|
85
|
+
Object.defineProperty(exports, "QueryParams", { enumerable: true, get: function () { return core_util_4.QueryParams; } });
|
|
86
|
+
Object.defineProperty(exports, "WpAuthPublic", { enumerable: true, get: function () { return core_util_4.WpAuthPublic; } });
|
|
87
|
+
Object.defineProperty(exports, "WpAuth", { enumerable: true, get: function () { return core_util_4.WpAuth; } });
|
|
88
|
+
Object.defineProperty(exports, "WpAuthorization", { enumerable: true, get: function () { return core_util_4.WpAuthorization; } });
|
|
89
|
+
Object.defineProperty(exports, "AuthorizationType", { enumerable: true, get: function () { return core_util_4.AuthorizationType; } });
|
|
90
|
+
Object.defineProperty(exports, "WpLocalOnly", { enumerable: true, get: function () { return core_util_4.WpLocalOnly; } });
|
|
91
|
+
Object.defineProperty(exports, "jwt", { enumerable: true, get: function () { return core_util_4.jwt; } });
|
|
92
|
+
Object.defineProperty(exports, "oidcSameProject", { enumerable: true, get: function () { return core_util_4.oidcSameProject; } });
|
|
93
|
+
Object.defineProperty(exports, "oidcSvcs", { enumerable: true, get: function () { return core_util_4.oidcSvcs; } });
|
|
94
|
+
Object.defineProperty(exports, "sharedSecret", { enumerable: true, get: function () { return core_util_4.sharedSecret; } });
|
|
95
|
+
Object.defineProperty(exports, "vendorAuth", { enumerable: true, get: function () { return core_util_4.vendorAuth; } });
|
|
96
|
+
Object.defineProperty(exports, "apiKey", { enumerable: true, get: function () { return core_util_4.apiKey; } });
|
|
97
|
+
Object.defineProperty(exports, "Rpc", { enumerable: true, get: function () { return core_util_4.Rpc; } });
|
|
98
|
+
Object.defineProperty(exports, "PubSub", { enumerable: true, get: function () { return core_util_4.PubSub; } });
|
|
99
|
+
Object.defineProperty(exports, "Queue", { enumerable: true, get: function () { return core_util_4.Queue; } });
|
|
92
100
|
var Wiring_1 = require("./Wiring");
|
|
93
101
|
Object.defineProperty(exports, "Binder", { enumerable: true, get: function () { return Wiring_1.Binder; } });
|
|
94
102
|
Object.defineProperty(exports, "ClientBindOptions", { enumerable: true, get: function () { return Wiring_1.ClientBindOptions; } });
|
|
@@ -102,6 +110,6 @@ Object.defineProperty(exports, "BrowserValueProvider", { enumerable: true, get:
|
|
|
102
110
|
Object.defineProperty(exports, "BrowserClassProvider", { enumerable: true, get: function () { return BrowserProviders_1.BrowserClassProvider; } });
|
|
103
111
|
Object.defineProperty(exports, "BrowserExistingProvider", { enumerable: true, get: function () { return BrowserProviders_1.BrowserExistingProvider; } });
|
|
104
112
|
Object.defineProperty(exports, "BrowserFactoryProvider", { enumerable: true, get: function () { return BrowserProviders_1.BrowserFactoryProvider; } });
|
|
105
|
-
var
|
|
106
|
-
Object.defineProperty(exports, "WiringPolicy", { enumerable: true, get: function () { return
|
|
113
|
+
var http_client_core_4 = require("@webpieces/http-client-core");
|
|
114
|
+
Object.defineProperty(exports, "WiringPolicy", { enumerable: true, get: function () { return http_client_core_4.WiringPolicy; } });
|
|
107
115
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;;AAEH,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AACjC,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,4FAA4F;AAC5F,kGAAkG;AAClG,8BAA8B;AAC9B,iEAAgE;AAAvD,8HAAA,qBAAqB,OAAA;AAC9B,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,kFAAkF;AAClF,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,mFAG0C;AAFtC,gJAAA,8BAA8B,OAAA;AAC9B,qJAAA,mCAAmC,OAAA;AAEvC,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAG5B,wEAAwE;AACxE,gEAAiG;AAAxF,+GAAA,WAAW,OAAA;AAAE,yHAAA,qBAAqB,OAAA;AAAE,kHAAA,cAAc,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/http/http-client-browser/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;;AAEH,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AACjC,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,4FAA4F;AAC5F,kGAAkG;AAClG,8BAA8B;AAC9B,iEAAgE;AAAvD,8HAAA,qBAAqB,OAAA;AAC9B,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,kFAAkF;AAClF,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,mFAG0C;AAFtC,gJAAA,8BAA8B,OAAA;AAC9B,qJAAA,mCAAmC,OAAA;AAEvC,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAG5B,wEAAwE;AACxE,gEAAiG;AAAxF,+GAAA,WAAW,OAAA;AAAE,yHAAA,qBAAqB,OAAA;AAAE,kHAAA,cAAc,OAAA;AAC3D,yGAAyG;AACzG,gEAKqC;AAJjC,qHAAA,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A;AAAE,wHAAA,oBAAoB,OAAA;AAAE,2HAAA,uBAAuB,OAAA;AAAE,0HAAA,sBAAsB,OAAA;AAGpG,gEAA2D;AAAlD,gHAAA,YAAY,OAAA","sourcesContent":["/**\n * @webpieces/http-client-browser\n *\n * The BROWSER HTTP client. Reads an API contract's decorators and generates type-safe HTTP\n * clients from it — the same contract the server implements.\n *\n * DI-free on purpose: this may be bundled by React or Angular, so it ships no inversify and no\n * @webpieces/core-context (which is AsyncLocalStorage-backed and Node-only). Browsers have no\n * ambient request scope, so the app holds a {@link MutableContextStore} and sets context values\n * as they become known; every outbound call then transfers them as headers.\n *\n * Usage:\n * ```typescript\n * import { ClientHttpBrowserFactory, ClientConfig, MutableContextStore } from '@webpieces/http-client-browser';\n *\n * HeaderRegistry.configure(CompanyHeaders.ALL_HEADERS, true);\n * const store = new MutableContextStore();\n * const factory = new ClientHttpBrowserFactory(store);\n *\n * const client = factory.createRpcClient(SaveApi, new ClientConfig('save-svc', ClientRole.END_USER_CLIENT));\n * const response = await client.save({ query: 'test' });\n * ```\n *\n * The server twin is @webpieces/http-client-node.\n */\n\nexport { ClientHttpBrowserFactory } from './ClientHttpBrowserFactory';\nexport { BrowserProxyClient } from './BrowserProxyClient';\n// Browser impl of the ApiCallContext seam, constructed by BrowserProxyClient. Exported so a\n// browser/Angular logger can read the current tag via the STATIC BrowserApiCallContext.snapshot()\n// and fold it into log lines.\nexport { BrowserApiCallContext } from './BrowserApiCallContext';\nexport { ClientConfig } from './ClientConfig';\n// #1293: service-worker routing for every RPC, and ngsw's synthetic-504 fallback.\nexport { ServiceWorkerRouting } from './ServiceWorkerRouting';\nexport {\n ServiceWorkerSyntheticResponse,\n ServiceWorkerSyntheticResponseError,\n} from './ServiceWorkerSyntheticResponse';\nexport { MutableContextStore } from './MutableContextStore';\nexport type { RequestLifecycleListener } from './RequestLifecycleListener';\n\n// The isomorphic engine, re-exported so a browser app needs one import.\nexport { ProxyClient, ClientErrorTranslator, RequestOutcome } from '@webpieces/http-client-core';\n// #1445: the factory's runtime collaborator — injected fetch + deadline clock, required in React Native.\nexport {\n HttpClientRuntime,\n HttpFetchInit,\n HttpRuntimeKind,\n ReactNativeRuntimeConfigError,\n} from '@webpieces/http-client-core';\nexport type { HttpFetch } from '@webpieces/http-client-core';\nexport { TimerDeadlineScheduler } from '@webpieces/core-util';\nexport type { DeadlineScheduler, DeadlineTimer } from '@webpieces/core-util';\nexport type { ApiPrototype } from '@webpieces/http-client-core';\nexport { StreamingCapabilityError } from '@webpieces/http-client-core';\n\n// ContextMgr is the BROWSER's outbound-header propagation. This is the only package that may use\n// it; the server reads RequestContext directly (RequestContextHeaders in @webpieces/core-context).\nexport { ContextMgr } from '@webpieces/core-util';\n\n// Re-export the context-key contract from core-util for convenience (browser one-import)\nexport {\n ContextReader,\n ContextWriter,\n ContextStore,\n ContextKey,\n HeaderRegistry,\n ClientRegistry,\n ClientRole,\n CallMode,\n CallModeMarker,\n templateDeriver,\n WebpiecesCoreHeaders,\n} from '@webpieces/core-util';\nexport type { ServiceUrlDeriver } from '@webpieces/core-util';\n\n// Re-export API decorators for convenience (same as http-routing does)\nexport {\n ApiPath,\n Endpoint,\n PathParam,\n QueryParam,\n QueryString,\n QueryParams,\n WpAuthPublic,\n WpAuth,\n WpAuthorization,\n AuthorizationType,\n WpLocalOnly,\n jwt,\n oidcSameProject,\n oidcSvcs,\n sharedSecret,\n vendorAuth,\n apiKey,\n Rpc,\n PubSub,\n Queue,\n ValidateImplementation,\n} from '@webpieces/core-util';\n\n// The browser host's wiring: bind modules only (no route channel), the Binder they configure, and\n// the ExternalImpl recipes (UseClass / UseExisting) Binder.bindExternal takes.\nexport type { Wiring, AppWiring, BindModule } from './Wiring';\nexport { Binder, ClientBindOptions, BrowserWiringProviders } from './Wiring';\nexport { ExternalImpl, UseClass, UseExisting } from './ExternalImpl';\nexport type { ExternalClassType, ExternalExistingType } from './ExternalImpl';\nexport { BrowserValueProvider, BrowserClassProvider, BrowserExistingProvider, BrowserFactoryProvider } from './BrowserProviders';\nexport type { BrowserProvider, BrowserToken, BrowserType } from './BrowserProviders';\n\nexport { WiringPolicy } from '@webpieces/http-client-core';\n"]}
|