@funkit/connect-rn 7.0.0 → 8.0.0
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/CHANGELOG.md +47 -0
- package/README.md +76 -56
- package/dist/chunk-D64EJ57D.js +161 -0
- package/dist/chunk-D64EJ57D.js.map +7 -0
- package/dist/{chunk-P3OLDPDC.js → chunk-KZOSYNGV.js} +57 -192
- package/dist/chunk-KZOSYNGV.js.map +7 -0
- package/dist/{chunk-HRJNTNCV.js → chunk-SRVRWQO6.js} +5 -3
- package/dist/{chunk-HRJNTNCV.js.map → chunk-SRVRWQO6.js.map} +1 -1
- package/dist/clients/lighter.js +4 -2
- package/dist/clients/lighter.js.map +1 -1
- package/dist/clients/nado.js +5 -3
- package/dist/clients/nado.js.map +1 -1
- package/dist/clients/solana/index.d.ts +5 -0
- package/dist/clients/solana/index.d.ts.map +1 -0
- package/dist/clients/solana/solanaWithdrawal.d.ts +20 -0
- package/dist/clients/solana/solanaWithdrawal.d.ts.map +1 -0
- package/dist/clients/solana/useSolanaWithdrawal.d.ts +13 -0
- package/dist/clients/solana/useSolanaWithdrawal.d.ts.map +1 -0
- package/dist/clients/solana.d.ts +1 -0
- package/dist/clients/solana.js +87 -0
- package/dist/clients/solana.js.map +7 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2561 -2071
- package/dist/index.js.map +4 -4
- package/dist/src/components/Grabber.d.ts +3 -1
- package/dist/src/components/Grabber.d.ts.map +1 -1
- package/dist/src/fiat/KycGlassBackdrop.d.ts.map +1 -1
- package/dist/src/fiat/quoteRefusal.d.ts +29 -6
- package/dist/src/fiat/quoteRefusal.d.ts.map +1 -1
- package/dist/src/fiat/useFiatDirectDelivery.d.ts +5 -4
- package/dist/src/fiat/useFiatDirectDelivery.d.ts.map +1 -1
- package/dist/src/fiat/useIdentityAssertion.d.ts +35 -0
- package/dist/src/fiat/useIdentityAssertion.d.ts.map +1 -0
- package/dist/src/fiat/useQuoteableCeiling.d.ts +28 -0
- package/dist/src/fiat/useQuoteableCeiling.d.ts.map +1 -0
- package/dist/src/flow/DepositReceivedToast.d.ts +2 -2
- package/dist/src/flow/DepositReceivedToast.d.ts.map +1 -1
- package/dist/src/flow/FeeDetailsSheet.d.ts.map +1 -1
- package/dist/src/flow/FiatDepositAmountStep.d.ts.map +1 -1
- package/dist/src/flow/FlowSheet.d.ts +14 -20
- package/dist/src/flow/FlowSheet.d.ts.map +1 -1
- package/dist/src/flow/FunkitFlowProvider.d.ts +9 -4
- package/dist/src/flow/FunkitFlowProvider.d.ts.map +1 -1
- package/dist/src/flow/SheetMaterial.d.ts +11 -0
- package/dist/src/flow/SheetMaterial.d.ts.map +1 -0
- package/dist/src/flow/WithdrawalFlowContent.d.ts.map +1 -1
- package/dist/src/flow/depositFlowConfig.d.ts +21 -5
- package/dist/src/flow/depositFlowConfig.d.ts.map +1 -1
- package/dist/src/flow/flowError.d.ts +11 -1
- package/dist/src/flow/flowError.d.ts.map +1 -1
- package/dist/src/flow/flowStepHeight.d.ts +19 -0
- package/dist/src/flow/flowStepHeight.d.ts.map +1 -0
- package/dist/src/flow/validateClientMetadata.d.ts +2 -3
- package/dist/src/flow/validateClientMetadata.d.ts.map +1 -1
- package/dist/src/hooks/useSheetFade.d.ts +11 -0
- package/dist/src/hooks/useSheetFade.d.ts.map +1 -0
- package/dist/src/identity/IdentityContext.d.ts +28 -4
- package/dist/src/identity/IdentityContext.d.ts.map +1 -1
- package/dist/src/logging/debugBridge.d.ts +2 -0
- package/dist/src/logging/debugBridge.d.ts.map +1 -1
- package/dist/src/native/glassEffect.d.ts +18 -0
- package/dist/src/native/glassEffect.d.ts.map +1 -0
- package/dist/src/providers/FunkitProvider.d.ts +6 -8
- package/dist/src/providers/FunkitProvider.d.ts.map +1 -1
- package/dist/src/providers/NativeCapabilitiesContext.d.ts +12 -11
- package/dist/src/providers/NativeCapabilitiesContext.d.ts.map +1 -1
- package/dist/src/providers/useFunkitCheckout.d.ts +7 -3
- package/dist/src/providers/useFunkitCheckout.d.ts.map +1 -1
- package/dist/src/screens/DepositAmountScreen.d.ts.map +1 -1
- package/dist/src/screens/FeeDetailsScreen.d.ts +2 -5
- package/dist/src/screens/FeeDetailsScreen.d.ts.map +1 -1
- package/dist/src/screens/WithdrawAddressScreen.d.ts.map +1 -1
- package/dist/src/screens/WithdrawAmountScreen.d.ts.map +1 -1
- package/dist/src/screens/WithdrawCompleteScreen.d.ts.map +1 -1
- package/dist/src/swapped/SwappedWebView.d.ts.map +1 -1
- package/dist/src/swapped/SwappedWithdrawScreen.d.ts +3 -1
- package/dist/src/swapped/SwappedWithdrawScreen.d.ts.map +1 -1
- package/dist/src/swapped/paymentNavigation.d.ts +21 -0
- package/dist/src/swapped/paymentNavigation.d.ts.map +1 -0
- package/dist/src/transfer/hooks/useDepositRecipient.d.ts +2 -2
- package/dist/src/transfer/hooks/useDepositRecipient.d.ts.map +1 -1
- package/dist/src/transfer/hooks/useTokenTransfer.d.ts +3 -2
- package/dist/src/transfer/hooks/useTokenTransfer.d.ts.map +1 -1
- package/dist/src/transfer/hooks/useTransferInit.d.ts +2 -3
- package/dist/src/transfer/hooks/useTransferInit.d.ts.map +1 -1
- package/dist/src/utils/motion.d.ts +10 -0
- package/dist/src/utils/motion.d.ts.map +1 -1
- package/dist/src/withdrawal/fiatTargetDecimals.d.ts +13 -0
- package/dist/src/withdrawal/fiatTargetDecimals.d.ts.map +1 -0
- package/dist/src/withdrawal/useSourceTokenDecimals.d.ts.map +1 -1
- package/dist/src/withdrawal/useWithdrawalExecution.d.ts.map +1 -1
- package/expo-module.config.json +6 -0
- package/ios/FunkitGlassEffect.podspec +23 -0
- package/ios/FunkitGlassEffectModule.swift +126 -0
- package/ios/GlassStyle.swift +52 -0
- package/ios/GlassView.swift +305 -0
- package/package.json +15 -4
- package/dist/chunk-P3OLDPDC.js.map +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# @funkit/connect-rn
|
|
2
2
|
|
|
3
|
+
## 8.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- fd90e03: The deposit sheets' Liquid Glass material now ships inside the SDK, so a host installs nothing and passes nothing for it.
|
|
8
|
+
|
|
9
|
+
Migration: `expo` and `expo-blur` are now peer dependencies — install both, then rebuild your binary so the SDK's `FunkitGlassEffect` pod links. Drop `renderBackdropBlur` and `liquidGlass` from `FunkitProvider` unless you need a different material; a kept `renderBackdropBlur` takes no arguments now (`BackdropBlurRenderer` is `() => ReactNode`).
|
|
10
|
+
- 28c7128: Deposits await the sheet, hosts pass their identity minter by ref, and a failed identity check now tells the host whether to sign the user back in, stop, or retry.
|
|
11
|
+
|
|
12
|
+
`checkoutConfig.targetAsset` also accepts a Solana mint, so Solana USDC targets need no cast.
|
|
13
|
+
|
|
14
|
+
**Migration**
|
|
15
|
+
|
|
16
|
+
- `beginDeposit` now returns `Promise<void>` that resolves once the flow is on screen. It also resolves (never rejects) if a newer `beginDeposit` replaced it or the flow closed first, so fire-and-forget callers get no unhandled rejection; check `onDepositError` for failures. A misconfigured flow still throws synchronously at the call, so existing `try { beginDeposit(cfg) } catch {}` keeps working; `await` it to know when the sheet is up.
|
|
17
|
+
- Pass `getIdentityAssertionRef` (a `useRef` holding your minter) on `FunkitProvider`'s `config`. `getIdentityAssertion` still works but is deprecated.
|
|
18
|
+
- Have your minter reject with `code: 'SESSION_EXPIRED' | 'ACCOUNT_INELIGIBLE' | 'TRANSIENT'`. `onDepositError` gains the `session_expired` code: the flow has closed — re-authenticate the user and call `beginDeposit` again.
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- 387e230: Fiat deposits with an identity minter let the backend resolve the recipient from the verified assertion without a frontend wallet address.
|
|
23
|
+
- a1f9be5: Accept an explicit gross destination-token deposit cap in client metadata, independently of the fiat input amount.
|
|
24
|
+
- 01c1797: Withdraw USDC from a connected Solana wallet, to crypto or to cash, through the new opt-in Solana withdrawal entry.
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- fd90e03: Deposit amount digits use their natural widths instead of tabular spacing.
|
|
29
|
+
- afbd9e5: Allow hosts to send debug events through the configured Funkit logging pipeline.
|
|
30
|
+
- 50fe735: Full-height withdrawal steps fill the container the flow is mounted in rather than the browser window, so a host dialog no longer clips the foot of the screen.
|
|
31
|
+
- d7f401e: Hide the deposit max route on the identity options card and offer a way to close the deposit instead
|
|
32
|
+
- 9fcba82: An amount over the buyer's own limit is now answered on the amount field, naming the cap that refused and offering the way down to it, instead of an alert the buyer has to dismiss before they can act. The alert remains for a refusal that carries no cap under the entered amount.
|
|
33
|
+
- c452c25: The amount screen now learns the buyer's spending ceiling before it asks for a price, so an amount over it is answered immediately instead of buying a refusal.
|
|
34
|
+
- e056364: Fix the withdrawal amount screen laying out wrongly and the flow sheet logging a nested-button DOM error under react-native-web.
|
|
35
|
+
- 3889bd1: The Liquid Glass deposit sheet takes a lighter tint, so more of the host app reads through it.
|
|
36
|
+
- fd90e03: Fade the deposit sheet's grabber in with the sheet instead of showing it at full strength mid-rise.
|
|
37
|
+
- 91a2785: Remove the close button from the fee details drawer
|
|
38
|
+
- 30c01e5: Support withdrawals from non-EVM source tokens on the React Native crypto and cash rails.
|
|
39
|
+
- 6c28263: Document Solana withdrawal setup.
|
|
40
|
+
- 32d3ac1: Keep the Swapped card payment journey inside the WebView instead of handing it to the system browser
|
|
41
|
+
- Updated dependencies [d4de552]
|
|
42
|
+
- Updated dependencies [28c7128]
|
|
43
|
+
- Updated dependencies [30c01e5]
|
|
44
|
+
- Updated dependencies [d4de552]
|
|
45
|
+
- Updated dependencies [12a70d7]
|
|
46
|
+
- Updated dependencies [c452c25]
|
|
47
|
+
- @funkit/api-base@8.5.0
|
|
48
|
+
- @funkit/connect-core@8.3.0
|
|
49
|
+
|
|
3
50
|
## 7.0.0
|
|
4
51
|
|
|
5
52
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -39,6 +39,17 @@ log transports, identity context, and transfer hooks are **internal** (mirroring
|
|
|
39
39
|
`@funkit/connect`, which exports none of them). When adding a public export, wire
|
|
40
40
|
it explicitly in `index.ts`.
|
|
41
41
|
|
|
42
|
+
## Payment deposit metadata
|
|
43
|
+
|
|
44
|
+
`clientMetadata.authorizedAmountBaseUnit` is an explicit maximum gross deposit
|
|
45
|
+
in destination-token base units, forwarded unchanged to `POST /eoa`. For Base
|
|
46
|
+
EURC, `'20000000'` caps the gross deposit at 20 EURC before fees. It is separate
|
|
47
|
+
from `initialAmount` (fiat input), `lockAmount` (UI editing), and actual net credit;
|
|
48
|
+
no cap is inferred. Supply a positive integer string of 1–30 digits without leading
|
|
49
|
+
zeros, or `beginDeposit` throws `FunkitMisconfiguredError` before opening.
|
|
50
|
+
The field is optional in the SDK; Betty's backend requires it with the payment
|
|
51
|
+
IDs and rejects a different cap or destination when reusing the same payment ID.
|
|
52
|
+
|
|
42
53
|
## MoonPay crypto setup
|
|
43
54
|
|
|
44
55
|
MoonPay requires a secure `globalThis.crypto.getRandomValues` implementation on
|
|
@@ -166,6 +177,10 @@ Two deliberate choices keep it that way:
|
|
|
166
177
|
`includeOnramp: true`; bare RN: `stripe-react-native/Onramp` in the Podfile and
|
|
167
178
|
`StripeSdk_includeOnramp=true` in `gradle.properties`), and rebuilds; that
|
|
168
179
|
rail cannot run in Expo Go.
|
|
180
|
+
- **The glass module is optional at runtime.** `FunkitGlassEffect` (this
|
|
181
|
+
package's `ios/`) is not in Expo Go. `src/native/glassEffect.ts` looks it up
|
|
182
|
+
with `requireOptionalNativeModule`, so an unlinked binary renders the
|
|
183
|
+
`expo-blur` fallback (which Expo Go bundles) instead of throwing.
|
|
169
184
|
- **No `react-native-device-info`.** `src/statsig/statsigMetadata.ts` vendors the
|
|
170
185
|
Statsig metadata adapter with the `react-native-device-info` dependency removed
|
|
171
186
|
(it's a native module that needs a dev build). The app-version / device-model
|
|
@@ -173,67 +188,34 @@ Two deliberate choices keep it that way:
|
|
|
173
188
|
built-in `Platform` / `NativeModules` (no extra native dep). Geo/IP resolution
|
|
174
189
|
uses plain `fetch`.
|
|
175
190
|
|
|
176
|
-
**Contributor rule:** don't add a hard top-level import of a
|
|
177
|
-
|
|
178
|
-
|
|
191
|
+
**Contributor rule:** don't add a hard top-level import of a native module that
|
|
192
|
+
Expo Go doesn't bundle. If you genuinely need one, make it optional + lazily
|
|
193
|
+
imported + guarded with a host-injectable override, the way clipboard is — or,
|
|
194
|
+
for a native view of our own, look it up as an optional module the way the glass
|
|
195
|
+
view is.
|
|
179
196
|
|
|
180
197
|
## Sheet material (blur / Liquid Glass)
|
|
181
198
|
|
|
182
199
|
The V2 deposit sheet and the drawers over it (fee details, country list, KYC
|
|
183
200
|
choosers) are drawn on glass: the design's Figma layer is a dark fill with a
|
|
184
|
-
**Glass** effect, which is iOS 26's Liquid Glass. The SDK ships
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
```tsx
|
|
203
|
-
import { BlurView } from 'expo-blur'
|
|
204
|
-
import { GlassView, isLiquidGlassAvailable } from 'expo-glass-effect'
|
|
205
|
-
import { StyleSheet } from 'react-native'
|
|
206
|
-
|
|
207
|
-
const liquidGlass = isLiquidGlassAvailable()
|
|
208
|
-
|
|
209
|
-
const renderBackdropBlur = ({ tint }: { tint: string }) =>
|
|
210
|
-
liquidGlass ? (
|
|
211
|
-
<GlassView
|
|
212
|
-
glassEffectStyle="regular" // the frosted cut the design draws
|
|
213
|
-
tintColor={tint}
|
|
214
|
-
colorScheme="dark" // the SDK carries its own theme
|
|
215
|
-
style={StyleSheet.absoluteFill}
|
|
216
|
-
/>
|
|
217
|
-
) : (
|
|
218
|
-
<BlurView tint="default" intensity={90} style={StyleSheet.absoluteFill} />
|
|
219
|
-
)
|
|
220
|
-
|
|
221
|
-
<FunkitProvider renderBackdropBlur={renderBackdropBlur} liquidGlass={liquidGlass} />
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
Bare React Native — [`@callstack/liquid-glass`](https://github.com/callstack/liquid-glass)
|
|
225
|
-
(RN 0.80+, Xcode 26) and
|
|
226
|
-
[`@react-native-community/blur`](https://github.com/react-native-community/react-native-blur)
|
|
227
|
-
take the same shape. `LiquidGlassView` names the props `effect` / `tintColor` /
|
|
228
|
-
`colorScheme`, and `isLiquidGlassSupported` is a constant rather than a
|
|
229
|
-
function — it reads `false` on a binary built without the module, where
|
|
230
|
-
`isLiquidGlassAvailable()` throws.
|
|
231
|
-
|
|
232
|
-
Neither glass module is bundled in Expo Go, so a development build is needed.
|
|
233
|
-
Liquid Glass exists on iOS 26 only; Android and earlier iOS take the blur
|
|
234
|
-
branch, so always ship both. The
|
|
235
|
-
[`with-expo`](../../apps/with-expo/components/BackdropBlur.tsx) playground is a
|
|
236
|
-
working example of the Expo pair.
|
|
201
|
+
**Glass** effect, which is iOS 26's Liquid Glass. The SDK ships that material
|
|
202
|
+
itself (`src/flow/SheetMaterial.tsx`): an `expo-blur` blur of the host app with
|
|
203
|
+
the SDK's own Liquid Glass view refracting through it. The tint is the
|
|
204
|
+
material's — every surface renders it as is, and none passes one in.
|
|
205
|
+
|
|
206
|
+
The glass view is a native module this package carries under `ios/`
|
|
207
|
+
(`FunkitGlassEffect`, forked from `expo-glass-effect` with iOS 26's
|
|
208
|
+
container-concentric corners added, so the slab's corners match the device's).
|
|
209
|
+
Expo autolinking picks it up from `expo-module.config.json`; a host rebuilds
|
|
210
|
+
its binary once after upgrading. Where the pod isn't linked — Android, Expo Go,
|
|
211
|
+
a binary built before the upgrade — `src/native/glassEffect.ts` reads the
|
|
212
|
+
module as absent, the blur stands alone, and each surface paints its fill over
|
|
213
|
+
it, as the blur path always has.
|
|
214
|
+
|
|
215
|
+
`expo` and `expo-blur` are peer dependencies for this. A host that wants a
|
|
216
|
+
different native material still has `FunkitProvider`'s `renderBackdropBlur`,
|
|
217
|
+
paired with `liquidGlass` when that view is Liquid Glass; the SDK then paints
|
|
218
|
+
no fill over it.
|
|
237
219
|
|
|
238
220
|
## Lighter withdrawals
|
|
239
221
|
|
|
@@ -316,6 +298,44 @@ required by the config type and reserved for that rail, so it must be supplied
|
|
|
316
298
|
even though nothing calls it today; a stub is fine. Same for the optional
|
|
317
299
|
`getSecureMinWithdrawalAmount`.
|
|
318
300
|
|
|
301
|
+
## Solana withdrawals
|
|
302
|
+
|
|
303
|
+
Solana lives on its own entry, `@funkit/connect-rn/clients/solana`, so a host
|
|
304
|
+
that never configures it carries none of it. The host owns the Solana wallet
|
|
305
|
+
connection; the SDK takes the connected wallet's signer and builds a withdrawal
|
|
306
|
+
config over it. USDC on Solana is the only source today, and both the crypto
|
|
307
|
+
and the cash (Swapped) methods work from it.
|
|
308
|
+
|
|
309
|
+
```tsx
|
|
310
|
+
import { useFunkitCheckout } from '@funkit/connect-rn'
|
|
311
|
+
import { useSolanaWithdrawal } from '@funkit/connect-rn/clients/solana'
|
|
312
|
+
import { useMemo } from 'react'
|
|
313
|
+
|
|
314
|
+
// Both inputs are compared by identity, so keep them stable across renders.
|
|
315
|
+
const solana = useMemo(() => ({ signer: solanaWallet }), [solanaWallet])
|
|
316
|
+
const config = useMemo(
|
|
317
|
+
() => ({
|
|
318
|
+
defaultReceiveToken: 'USDC',
|
|
319
|
+
// Your own accounting for the spendable balance, if you have it.
|
|
320
|
+
withdrawalSourceTokenBalance: () => usdcBalance,
|
|
321
|
+
}),
|
|
322
|
+
[usdcBalance],
|
|
323
|
+
)
|
|
324
|
+
// `solanaWallet`: a base58 address, the RPC connection funkit submits through,
|
|
325
|
+
// and one of `signTransaction` / `signAndSendTransaction`.
|
|
326
|
+
const withdrawal = useSolanaWithdrawal({ solana, config })
|
|
327
|
+
|
|
328
|
+
const { beginWithdrawal } = useFunkitCheckout()
|
|
329
|
+
// `undefined` while the signer is absent or its address is not base58.
|
|
330
|
+
if (withdrawal) beginWithdrawal(withdrawal)
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Install `@solana/web3.js` (an optional peer) and give Hermes what it lacks
|
|
334
|
+
before importing the SDK: `Buffer` (the `buffer` package), a full `URL`
|
|
335
|
+
(`react-native-url-polyfill/auto`), and `crypto.getRandomValues` as described
|
|
336
|
+
under [MoonPay crypto setup](#moonpay-crypto-setup). Point the connection at an
|
|
337
|
+
RPC you control; Solana's public endpoints rate-limit.
|
|
338
|
+
|
|
319
339
|
## Local development
|
|
320
340
|
|
|
321
341
|
> No root shortcut exists for this package — use the `pnpm --filter` form (or
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// src/logging/logger.ts
|
|
2
|
+
import { FunLogger } from "@funkit/connect-core";
|
|
3
|
+
|
|
4
|
+
// src/logging/serializeLogBatch.ts
|
|
5
|
+
var UNSERIALIZABLE_DATA = "[Unserializable]";
|
|
6
|
+
function serializeLogBatch(batch) {
|
|
7
|
+
try {
|
|
8
|
+
return JSON.stringify(batch, createSafeJsonReplacer());
|
|
9
|
+
} catch {
|
|
10
|
+
return `[${batch.map(serializeRecord).join(",")}]`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function serializeRecord(record) {
|
|
14
|
+
const attributes = Object.entries(record).flatMap(([key, value]) => {
|
|
15
|
+
const serialized = serializeValue(value);
|
|
16
|
+
return serialized === void 0 ? [] : [`${JSON.stringify(key)}:${serialized}`];
|
|
17
|
+
});
|
|
18
|
+
return `{${attributes.join(",")}}`;
|
|
19
|
+
}
|
|
20
|
+
function serializeValue(value) {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.stringify(value, createSafeJsonReplacer());
|
|
23
|
+
} catch {
|
|
24
|
+
return JSON.stringify(UNSERIALIZABLE_DATA);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function createSafeJsonReplacer() {
|
|
28
|
+
const ancestors = [];
|
|
29
|
+
return function(_key, value) {
|
|
30
|
+
if (typeof value === "bigint") {
|
|
31
|
+
return value.toString();
|
|
32
|
+
}
|
|
33
|
+
if (typeof value === "function") {
|
|
34
|
+
return `[Function] ${value.name || "anonymous"}`;
|
|
35
|
+
}
|
|
36
|
+
if (typeof value === "symbol") {
|
|
37
|
+
return `[Symbol] ${value.description ?? ""}`;
|
|
38
|
+
}
|
|
39
|
+
if (value === null || typeof value !== "object") {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
if ("$$typeof" in value) {
|
|
43
|
+
return "[React]";
|
|
44
|
+
}
|
|
45
|
+
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) {
|
|
46
|
+
ancestors.pop();
|
|
47
|
+
}
|
|
48
|
+
if (ancestors.includes(value)) {
|
|
49
|
+
return "[Circular]";
|
|
50
|
+
}
|
|
51
|
+
ancestors.push(value);
|
|
52
|
+
return value;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/logging/datadogHttpLogTransport.ts
|
|
57
|
+
var DEFAULT_SERVICE = "connect-rn";
|
|
58
|
+
var DEFAULT_SITE = "datadoghq.com";
|
|
59
|
+
var DEFAULT_FLUSH_INTERVAL_MS = 5e3;
|
|
60
|
+
var DEFAULT_MAX_BATCH_SIZE = 50;
|
|
61
|
+
var DatadogHttpLogTransport = class {
|
|
62
|
+
constructor(options) {
|
|
63
|
+
this.consent = "granted";
|
|
64
|
+
this.queue = [];
|
|
65
|
+
this.flushTimer = null;
|
|
66
|
+
const site = options.site ?? DEFAULT_SITE;
|
|
67
|
+
this.service = options.service ?? DEFAULT_SERVICE;
|
|
68
|
+
this.env = options.env;
|
|
69
|
+
this.flushIntervalMs = options.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS;
|
|
70
|
+
this.maxBatchSize = options.maxBatchSize ?? DEFAULT_MAX_BATCH_SIZE;
|
|
71
|
+
this.intakeUrl = `https://browser-intake-${site}/api/v2/logs?dd-api-key=${encodeURIComponent(options.clientToken)}&ddsource=react-native&dd-evp-origin=react-native`;
|
|
72
|
+
}
|
|
73
|
+
setEnv(environment) {
|
|
74
|
+
this.env = environment;
|
|
75
|
+
}
|
|
76
|
+
setTrackingConsent(consent) {
|
|
77
|
+
this.consent = consent;
|
|
78
|
+
if (consent !== "granted") {
|
|
79
|
+
this.queue = [];
|
|
80
|
+
this.clearTimer();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
log({ level, title, context, error }) {
|
|
84
|
+
if (this.consent !== "granted") {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const entry = {
|
|
88
|
+
// Caller context first so the mandatory Datadog fields below always win —
|
|
89
|
+
// a future LogContext attribute named e.g. `message`/`status` can't
|
|
90
|
+
// silently corrupt the record.
|
|
91
|
+
...context,
|
|
92
|
+
ddsource: "react-native",
|
|
93
|
+
service: this.service,
|
|
94
|
+
status: level,
|
|
95
|
+
message: title,
|
|
96
|
+
...this.env ? { ddtags: `env:${this.env}` } : {},
|
|
97
|
+
...error ? {
|
|
98
|
+
error: {
|
|
99
|
+
message: error.message,
|
|
100
|
+
stack: error.stack,
|
|
101
|
+
kind: error.name
|
|
102
|
+
}
|
|
103
|
+
} : {}
|
|
104
|
+
};
|
|
105
|
+
this.queue.push(entry);
|
|
106
|
+
if (this.queue.length >= this.maxBatchSize) {
|
|
107
|
+
this.flush();
|
|
108
|
+
} else {
|
|
109
|
+
this.scheduleFlush();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Send the buffered batch. Fire-and-forget; network errors are swallowed. */
|
|
113
|
+
flush() {
|
|
114
|
+
this.clearTimer();
|
|
115
|
+
if (this.queue.length === 0) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (typeof fetch !== "function") {
|
|
119
|
+
this.queue = [];
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const batch = this.queue;
|
|
123
|
+
this.queue = [];
|
|
124
|
+
fetch(this.intakeUrl, {
|
|
125
|
+
method: "POST",
|
|
126
|
+
headers: { "Content-Type": "application/json" },
|
|
127
|
+
body: serializeLogBatch(batch)
|
|
128
|
+
}).catch(() => {
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
scheduleFlush() {
|
|
132
|
+
if (this.flushTimer != null) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.flushTimer = setTimeout(() => {
|
|
136
|
+
this.flushTimer = null;
|
|
137
|
+
this.flush();
|
|
138
|
+
}, this.flushIntervalMs);
|
|
139
|
+
}
|
|
140
|
+
clearTimer() {
|
|
141
|
+
if (this.flushTimer != null) {
|
|
142
|
+
clearTimeout(this.flushTimer);
|
|
143
|
+
this.flushTimer = null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// src/logging/logger.ts
|
|
149
|
+
var DDOG_CLIENT_TOKEN = "pub4f86c6be8c792cb48dc156a8c17d9a47";
|
|
150
|
+
var logger = new FunLogger(
|
|
151
|
+
new DatadogHttpLogTransport({
|
|
152
|
+
clientToken: DDOG_CLIENT_TOKEN
|
|
153
|
+
// service defaults to 'connect-rn' (see DatadogHttpLogTransport).
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
logger.setDebugTag(process.env.EXPO_PUBLIC_DEV_TAG ?? null);
|
|
157
|
+
|
|
158
|
+
export {
|
|
159
|
+
logger
|
|
160
|
+
};
|
|
161
|
+
//# sourceMappingURL=chunk-D64EJ57D.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/logging/logger.ts", "../src/logging/serializeLogBatch.ts", "../src/logging/datadogHttpLogTransport.ts"],
|
|
4
|
+
"sourcesContent": ["import { FunLogger } from '@funkit/connect-core'\n\nimport { DatadogHttpLogTransport } from './datadogHttpLogTransport'\n\n// Public Datadog client token (same one `@funkit/connect` uses for web). A\n// client token is safe to embed in client apps.\nconst DDOG_CLIENT_TOKEN = 'pub4f86c6be8c792cb48dc156a8c17d9a47'\n\n/**\n * The React Native `FunLogger` singleton. Mirrors `@funkit/connect`'s web\n * `logger`, but injects the raw-HTTP {@link DatadogHttpLogTransport} (no Datadog\n * SDK, no native modules) instead of `@datadog/browser-logs`. The host wires\n * `logger.configure(...)` / `setUserInfo(...)` once identity is available.\n */\nexport const logger = new FunLogger(\n new DatadogHttpLogTransport({\n clientToken: DDOG_CLIENT_TOKEN,\n // service defaults to 'connect-rn' (see DatadogHttpLogTransport).\n }),\n)\n\n// Names a developer's build in Datadog and switches on the MoonPay frame taps.\n// Metro inlines `EXPO_PUBLIC_*` only outside `node_modules` (expo/expo#46982),\n// so this resolves in this monorepo's playground and is `undefined` \u2014 taps off \u2014\n// for anyone consuming the published package. That is the intent: it is dev\n// tooling, and a host needs no API to opt out of it.\nlogger.setDebugTag(process.env.EXPO_PUBLIC_DEV_TAG ?? null)\n", "const UNSERIALIZABLE_DATA = '[Unserializable]'\n\n/**\n * Serialize log records to a JSON body. Always succeeds.\n *\n * Web gets this from `@datadog/browser-logs`; the raw-`fetch` RN transport has\n * no such layer and serializes inside the caller's `log()`, so a throw would\n * land in a user flow.\n */\nexport function serializeLogBatch(batch: readonly object[]): string {\n try {\n return JSON.stringify(batch, createSafeJsonReplacer())\n } catch {\n return `[${batch.map(serializeRecord).join(',')}]`\n }\n}\n\n/** Attribute by attribute, so one bad value can't drop unrelated records. */\nfunction serializeRecord(record: object): string {\n const attributes = Object.entries(record).flatMap(([key, value]) => {\n const serialized = serializeValue(value)\n // Omit undefined, as JSON.stringify does for object properties.\n return serialized === undefined\n ? []\n : [`${JSON.stringify(key)}:${serialized}`]\n })\n return `{${attributes.join(',')}}`\n}\n\nfunction serializeValue(value: unknown): string | undefined {\n try {\n return JSON.stringify(value, createSafeJsonReplacer())\n } catch {\n return JSON.stringify(UNSERIALIZABLE_DATA)\n }\n}\n\n/**\n * Resolves what `JSON.stringify` can't, inside the traversal it already makes.\n * `toJSON` runs before the replacer, so a throwing one escapes to the callers\n * above. Create one per `stringify`.\n */\nfunction createSafeJsonReplacer() {\n const ancestors: object[] = []\n\n return function (this: unknown, _key: string, value: unknown): unknown {\n if (typeof value === 'bigint') {\n return value.toString()\n }\n if (typeof value === 'function') {\n return `[Function] ${value.name || 'anonymous'}`\n }\n if (typeof value === 'symbol') {\n return `[Symbol] ${value.description ?? ''}`\n }\n if (value === null || typeof value !== 'object') {\n return value\n }\n\n // React values reference the fiber that rendered them, or themselves \u2014\n // internals either way, so mark the family instead of walking it.\n if ('$$typeof' in value) {\n return '[React]'\n }\n\n // `this` is the object `value` came from; unwinding to it leaves only true\n // ancestors, so a repeated sibling reference isn't read as a cycle.\n while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) {\n ancestors.pop()\n }\n if (ancestors.includes(value)) {\n return '[Circular]'\n }\n ancestors.push(value)\n return value\n }\n}\n", "import type {\n LogRecord,\n LogTransport,\n TrackingConsent,\n} from '@funkit/connect-core'\n\nimport { serializeLogBatch } from './serializeLogBatch'\n\n/**\n * React Native `LogTransport` that ships records to Datadog over **raw HTTP**\n * (`fetch`) \u2014 deliberately NOT the Datadog SDK. `@datadog/mobile-react-native`\n * pulls in native modules (autolinking, pods, no Expo Go); a plain `fetch` to\n * the logs intake needs none, so this works in Expo Go and any RN runtime.\n *\n * Records are batched and flushed fire-and-forget on a timer (or when the batch\n * fills); network errors are swallowed so logging never breaks a user flow.\n * Authenticates with the public Datadog **client token** via `dd-api-key`\n * (the same credential the browser SDK uses \u2014 safe to embed), so no server-side\n * API key is needed.\n */\nexport interface DatadogHttpLogTransportOptions {\n /** Datadog client token (`pub\u2026`). Safe to ship in client apps. */\n clientToken: string\n /** Service name attached to every log. */\n service?: string\n /** Datadog site, e.g. `datadoghq.com` (default), `datadoghq.eu`. */\n site?: string\n /** Initial environment tag; also settable later via {@link setEnv}. */\n env?: string\n /** Flush the batch at most this often (ms). Default 5000. */\n flushIntervalMs?: number\n /** Flush immediately once the batch reaches this size. Default 50. */\n maxBatchSize?: number\n}\n\ninterface DatadogLogEntry {\n ddsource: string\n service: string\n status: LogRecord['level']\n message: string\n ddtags?: string\n error?: { message: string; stack?: string; kind: string }\n [attribute: string]: unknown\n}\n\nconst DEFAULT_SERVICE = 'connect-rn'\nconst DEFAULT_SITE = 'datadoghq.com'\nconst DEFAULT_FLUSH_INTERVAL_MS = 5_000\nconst DEFAULT_MAX_BATCH_SIZE = 50\n\nexport class DatadogHttpLogTransport implements LogTransport {\n private readonly intakeUrl: string\n private readonly service: string\n private readonly flushIntervalMs: number\n private readonly maxBatchSize: number\n\n private env: string | undefined\n private consent: TrackingConsent = 'granted'\n private queue: DatadogLogEntry[] = []\n private flushTimer: ReturnType<typeof setTimeout> | null = null\n\n constructor(options: DatadogHttpLogTransportOptions) {\n const site = options.site ?? DEFAULT_SITE\n this.service = options.service ?? DEFAULT_SERVICE\n this.env = options.env\n this.flushIntervalMs = options.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS\n this.maxBatchSize = options.maxBatchSize ?? DEFAULT_MAX_BATCH_SIZE\n // Browser/mobile logs intake; the client token authenticates via dd-api-key.\n this.intakeUrl =\n `https://browser-intake-${site}/api/v2/logs` +\n `?dd-api-key=${encodeURIComponent(options.clientToken)}` +\n `&ddsource=react-native&dd-evp-origin=react-native`\n }\n\n setEnv(environment: string): void {\n this.env = environment\n }\n\n setTrackingConsent(consent: TrackingConsent): void {\n this.consent = consent\n if (consent !== 'granted') {\n // Drop anything buffered when consent is withdrawn.\n this.queue = []\n this.clearTimer()\n }\n }\n\n log({ level, title, context, error }: LogRecord): void {\n if (this.consent !== 'granted') {\n return\n }\n\n const entry: DatadogLogEntry = {\n // Caller context first so the mandatory Datadog fields below always win \u2014\n // a future LogContext attribute named e.g. `message`/`status` can't\n // silently corrupt the record.\n ...context,\n ddsource: 'react-native',\n service: this.service,\n status: level,\n message: title,\n ...(this.env ? { ddtags: `env:${this.env}` } : {}),\n ...(error\n ? {\n error: {\n message: error.message,\n stack: error.stack,\n kind: error.name,\n },\n }\n : {}),\n }\n\n this.queue.push(entry)\n\n if (this.queue.length >= this.maxBatchSize) {\n this.flush()\n } else {\n this.scheduleFlush()\n }\n }\n\n /** Send the buffered batch. Fire-and-forget; network errors are swallowed. */\n flush(): void {\n this.clearTimer()\n if (this.queue.length === 0) {\n return\n }\n if (typeof fetch !== 'function') {\n // No fetch (e.g. SSR import) \u2014 drop rather than throw.\n this.queue = []\n return\n }\n\n const batch = this.queue\n this.queue = []\n\n fetch(this.intakeUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: serializeLogBatch(batch),\n }).catch(() => {\n // Swallow: logging must never break a user flow.\n })\n }\n\n private scheduleFlush(): void {\n if (this.flushTimer != null) {\n return\n }\n this.flushTimer = setTimeout(() => {\n this.flushTimer = null\n this.flush()\n }, this.flushIntervalMs)\n }\n\n private clearTimer(): void {\n if (this.flushTimer != null) {\n clearTimeout(this.flushTimer)\n this.flushTimer = null\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,iBAAiB;;;ACA1B,IAAM,sBAAsB;AASrB,SAAS,kBAAkB,OAAkC;AAClE,MAAI;AACF,WAAO,KAAK,UAAU,OAAO,uBAAuB,CAAC;AAAA,EACvD,QAAQ;AACN,WAAO,IAAI,MAAM,IAAI,eAAe,EAAE,KAAK,GAAG,CAAC;AAAA,EACjD;AACF;AAGA,SAAS,gBAAgB,QAAwB;AAC/C,QAAM,aAAa,OAAO,QAAQ,MAAM,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAClE,UAAM,aAAa,eAAe,KAAK;AAEvC,WAAO,eAAe,SAClB,CAAC,IACD,CAAC,GAAG,KAAK,UAAU,GAAG,CAAC,IAAI,UAAU,EAAE;AAAA,EAC7C,CAAC;AACD,SAAO,IAAI,WAAW,KAAK,GAAG,CAAC;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