@wildix/smithy-react-native
v1.0.0
Published
React Native runtime support for generated Wildix Smithy clients: a streaming XMLHttpRequest transport and the web globals Hermes does not provide
Downloads
503
Maintainers
Keywords
Readme
@wildix/smithy-react-native
React Native runtime support for generated Wildix Smithy clients. Every @wildix/*-client
depends on this and wires it in from its own runtimeConfig.native.ts, so applications do not
import it directly.
What an app has to do
Install the two polyfills the AWS SDK also documents, as the first statements of the entry point:
npm install react-native-get-random-values react-native-url-polyfillimport "react-native-get-random-values";
import "react-native-url-polyfill/auto";That is the whole contract. No metro.config.js resolver override, and no patches to
@smithy/*.
What this package provides
| Export | Purpose |
| --- | --- |
| XhrHttpHandler | HttpHandler built on XMLHttpRequest, API-compatible with FetchHttpHandler. React Native's fetch never populates response.body, so the fetch handler buffers every response into a Blob — and React Native's Blob implements neither arrayBuffer() (nothing deserializes) nor stream() (streaming operations get no body). This one delivers a real ReadableStream, incrementally, which is what makes text/event-stream operations work. |
| installReactNativeGlobals() | Installs TextDecoder, structuredClone and ReadableStream only when absent, and warns once naming the packages for the globals it deliberately will not fake. |
| MinimalReadableStream, createPushStream | The stream implementation behind the handler, exported for tests and for anything building a body by hand. |
| decodeUtf8, createUtf8DecoderState | Incremental UTF-8 decoding, including the mid-code-point chunk boundaries a streaming body produces. |
Why these and not others
The list was measured against the engine React Native ships
(ios/Pods/hermes-engine/destroot/bin/hermes), not inferred:
TextEncoder = function TextDecoder = undefined
structuredClone = undefined ReadableStream = undefined
URL = undefined URLSearchParams = undefined
crypto = undefined btoa / atob = function
Symbol.asyncIterator = undefinedBlob, FileReader, XMLHttpRequest and fetch come from React Native itself rather than the
engine. Two consequences:
TextEncoderis present and complete,encodeIntoincluded, sofromUtf8andcalculateBodyLengthfrom@smithy/core/serdeneed nothing from us. Only the decoder is missing, and it is installed as a global because its callers —@smithy/core/cborat module-evaluation time, andsdkStreamMixin.transformToString— cannot be reached through client config.crypto.getRandomValues,URLandURLSearchParamsare reported, never faked. AMath.randomstand-in for a CSPRNG is a silent security downgrade, and a partial WHATWG URL parser corrupts request paths instead of failing. Both are on the AWS SDK's documented polyfill list for the same reason.
sdk-ts/docs/react_native.md records the full comparison against @aws-sdk/client-s3, the
version numbers everything was checked at, and which upstream bugs this compensates for.
Development
pnpm run build # dist-cjs + dist-es + dist-types
pnpm test # jestThe transport is tested against a fake that mirrors React Native's own XMLHttpRequest
semantics — cumulative responseText, incremental delivery only for the text response type —
because a transport that passes against a well-behaved fake can still buffer the whole body on a
device.
