@lucida-analytics/react-native 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +169 -2
- package/android/src/main/kotlin/com/lucida/reactnative/LucidaReplayModule.kt +96 -0
- package/dist/index.d.ts +784 -0
- package/dist/index.js +1765 -0
- package/ios/LucidaReplay.m +10 -0
- package/ios/LucidaReplay.swift +61 -0
- package/package.json +44 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/README.md
CHANGED
|
@@ -1,3 +1,170 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lucida-analytics/react-native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React Native SDK on top of `@lucida-analytics/sdk-core` (queue, batching, retry, identity, sessions, consent,
|
|
4
|
+
local flag evaluation). Native modules are injected, never imported, so the package has no native
|
|
5
|
+
dependency and tests run without React Native.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
9
|
+
import { AppState } from "react-native";
|
|
10
|
+
import { LucidaProvider, useFeatureFlag, useCapture } from "@lucida-analytics/react-native";
|
|
11
|
+
|
|
12
|
+
<LucidaProvider apiKey="lc_pk_..." options={{
|
|
13
|
+
apiHost: "https://ingest.example.com",
|
|
14
|
+
asyncStorage: AsyncStorage, appState: AppState,
|
|
15
|
+
appVersion: "1.4.0", platform: "ios",
|
|
16
|
+
}}>
|
|
17
|
+
<App />
|
|
18
|
+
</LucidaProvider>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or imperatively: `const client = await createClient(key, config)` (storage hydrates first, hence async).
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- **Capture**: `POST /v1/batch`, 20 events / 5 s, retry with backoff, offline batches persisted to
|
|
26
|
+
AsyncStorage (`offlineTransport`). No gzip (React Native has no `CompressionStream`).
|
|
27
|
+
- **Lifecycle** (`appState` adapter): `$app_opened`, `$app_backgrounded` (flushes),
|
|
28
|
+
`$app_installed`, `$app_updated` (needs `appVersion`).
|
|
29
|
+
- **Identity/consent**: `identify`, `alias`, `reset`, `register*`, `group`, `optIn`/`optOut`. With
|
|
30
|
+
`consent: { mode: "opt_in" }` nothing is written to AsyncStorage or sent before consent.
|
|
31
|
+
- **Flags**: `localFlags` evaluated on device (same evaluator and vectors as the web SDK), the rest via
|
|
32
|
+
`POST /v1/flags`. Hooks: `useFeatureFlag`, `useFeatureFlagVariant`, `useFeatureFlagPayload`,
|
|
33
|
+
`useActiveFeatureFlags`, `FeatureGate`.
|
|
34
|
+
- **Screens**: `useScreen("Home")`, or react-navigation (optional peer):
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
const ref = useNavigationContainerRef();
|
|
38
|
+
const { onReady, onStateChange } = screenTracker(client, ref);
|
|
39
|
+
<NavigationContainer ref={ref} onReady={onReady} onStateChange={onStateChange} />
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Route params are not sent unless `includeParams: true` (they often contain PII).
|
|
43
|
+
|
|
44
|
+
## Install attribution
|
|
45
|
+
|
|
46
|
+
Pass `installInfo: () => NativeModules.LucidaReplay.installInfo()` to `createClient` and the first-open
|
|
47
|
+
`$app_installed` carries: Android Play Install Referrer (`$install_store=google_play`, `$install_referrer`,
|
|
48
|
+
`$install_referrer_click_ts`, `$install_begin_ts`, parsed `$utm_*`, click ids `$gclid`/`$gbraid`/`$wbraid`/`$fbclid`/
|
|
49
|
+
`$ttclid`/`$msclkid`) or iOS Apple Search Ads via AdServices (`$install_store=app_store`, `$install_adservices_attribution`,
|
|
50
|
+
`$utm_*`, `$asa_*`; the token is POSTed as text/plain with a 10 s timeout, 404 retried). Any failure still sends the
|
|
51
|
+
event with `$install_store` only. Disable with `installAttribution: false`. The Android module needs
|
|
52
|
+
`com.android.installreferrer:installreferrer` (Apache-2.0) in the app's Gradle dependencies. Pure parsers are exported:
|
|
53
|
+
`installReferrerProps`, `appStoreInstallProps`.
|
|
54
|
+
|
|
55
|
+
## Hooks, person profiles, flags, privacy, autocapture
|
|
56
|
+
|
|
57
|
+
- `beforeSend: [hook, ...]`: ordered `(event) => event | null`; return a changed event to amend, `null` to drop. A hook that throws is
|
|
58
|
+
logged (when `debug`) and skipped: the event continues as it was before that hook. `sampleHook(0.1)` keeps ~10% and adds `$sample_rate`.
|
|
59
|
+
Hooks run as events enter the queue (a wrapper on the queue's `enqueue`, since `@lucida-analytics/sdk-core` is shared with the web SDK).
|
|
60
|
+
- `personProfiles`: `"always"` (default), `"identified_only"` (events carry `$process_person_profile: false` until identify, alias, group or
|
|
61
|
+
a person-property write; persisted, cleared by `reset()`), `"never"` (identify/alias/setPersonProperties are no-ops with a debug warning, `$set` is stripped).
|
|
62
|
+
- Flags: `flagOptions: { bootstrap: { distinctId, isIdentified, flags, payloads }, sendFeatureFlagEvent, preload, evaluationContexts }`,
|
|
63
|
+
`disableRemoteFeatureFlags: true` (never calls `/v1/flags`) with `client.updateFlags(flags, payloads, { merge })` for flags your own backend
|
|
64
|
+
evaluated, `onFlags`, `setPersonPropertiesForFlags(props, reload?)`, `setGroupPropertiesForFlags`, reset variants.
|
|
65
|
+
- Interventions: `client.onIntervention((i) => ...)` receives in-session interventions fired for this person (`{id, name, event, payload, fired_at}`);
|
|
66
|
+
polls `GET /v1/interventions` every 15 s while a listener is set, after analytics consent. See `docs/guides/interventions.md`.
|
|
67
|
+
- Queue/network: `flushAt`, `flushIntervalMs`, `maxQueueSize`, `maxBatchSize`, `maxRetries`, `retryDelayMs`, `requestTimeoutMs`,
|
|
68
|
+
`dataMode: "wifi"` + `network: { isWifi() }` (inject NetInfo), `sessionIdleMs` / `sessionMaxMs`, `disableGeoip`, `disabled`, `client.debug(true)`.
|
|
69
|
+
- Person helpers: `setPersonProperties`, `capture(event, props, { set, setOnce })`, `getAnonymousId`, `reuseAnonymousId`, `isOptedOut`, `openURL(url, referrer)` (`$deep_link_opened`).
|
|
70
|
+
- Tracing headers: `tracingHeaders: ["api.example.com", ".corp.io"]`, then call your backend through `client.fetch` to add
|
|
71
|
+
`X-Lucida-Distinct-Id` / `X-Lucida-Session-Id` (never to the Lucida host; analytics consent required).
|
|
72
|
+
- Autocapture: `autocapture: { enabled: true, ignoreLabels, maxElements, propsAllowList, customLabelProp, noCaptureProp, rageTap }`, then
|
|
73
|
+
`<View onTouchEnd={touchHandler(client.autocapture)}>` at the root. Elements are the touched fiber's ancestors that carry an
|
|
74
|
+
`accessibilityLabel` / `testID`; `<View lucidaNoCapture>` excludes a subtree. It reads React internals (`_targetInst`), so treat it as best effort.
|
|
75
|
+
Text-field values are never read. `$rageclick` fires after repeated taps.
|
|
76
|
+
- Replay privacy: `replay: { maskText, maskAllTextInputs, maskAllImages, maskSandboxedViews, sampleRate, throttleMs }` (the native modules receive the mask flags),
|
|
77
|
+
`client.replay.start()/stop()/isRecording()`.
|
|
78
|
+
|
|
79
|
+
Not built: push registration (needs a scope decision).
|
|
80
|
+
|
|
81
|
+
## Session replay (wireframe)
|
|
82
|
+
|
|
83
|
+
Off by default. The native view hierarchy is encoded natively by the Lucida iOS / Android SDK wireframe
|
|
84
|
+
encoder (inputs and secure fields never carry text; other text is starred unless `maskText: false`); this package
|
|
85
|
+
owns consent (analytics **and** replay), session/window ids, `seq` (resets when the session rotates), structure
|
|
86
|
+
dedupe and delivery to `POST /v1/replay`.
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import { NativeModules } from "react-native";
|
|
90
|
+
createClient("lc_pk_...", { replay: { enabled: true, module: NativeModules.LucidaReplay, snapshotIntervalMs: 5000 } });
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Screenshot mode: `replay: { mode: "screenshot", screenshotQuality: 0.4 }`. The native module draws the window into a
|
|
94
|
+
bitmap, paints inputs, secure fields, `<LucidaMask>` views, images and (unless `maskText: false`) text over, and only then
|
|
95
|
+
encodes JPEG (the same `ScreenshotCapture` / `UIKitScreenshot` code the native SDKs use); at most one frame a second.
|
|
96
|
+
|
|
97
|
+
Native contract (`NativeReplayModule` in `src/replay.ts`): `captureWireframe({ screen, maskText, maskAllTextInputs, maskAllImages, maskSandboxedViews }): Promise<string>` (plus `mode: "screenshot", screenshotQuality` in screenshot mode)
|
|
98
|
+
resolves JSON text `{"width","height","events":[meta (type 4), fullSnapshot (type 2)]}`, or `""` when nothing can
|
|
99
|
+
be captured. Reference implementations, linked as ordinary React Native native modules:
|
|
100
|
+
|
|
101
|
+
- iOS: `ios/LucidaReplay.swift` + `.m`, calling `ReplayBridge.capture` from the `Lucida` Swift package (add it as a pod/SPM dependency).
|
|
102
|
+
- Android: `android/src/main/kotlin/com/lucida/reactnative/LucidaReplayModule.kt`, calling `WireframeCapture.capture`
|
|
103
|
+
from `lucida-android`; register the module in a `ReactPackage` of your app.
|
|
104
|
+
|
|
105
|
+
These two files are not compiled in this repository (no React Native toolchain); everything they call is covered
|
|
106
|
+
by `swift test` (ReplayBridgeTests) and `make sdk-android` (ReplayBridgeTest). Verify them in a real app before shipping.
|
|
107
|
+
|
|
108
|
+
### Session replay: privacy additions
|
|
109
|
+
|
|
110
|
+
Every remote value below arrives in `GET /v1/config` and only ever adds masking to what the app configured.
|
|
111
|
+
|
|
112
|
+
- **Masked screens** (P-M17): `replay: { maskScreens: ["Checkout", "Pay*"] }` plus the project's `replay_mask_screens`
|
|
113
|
+
(case-insensitive, `*` = any run of characters, whole screen name as passed to `client.screen`). On a matching screen the
|
|
114
|
+
native encoder masks every text, input value and image whatever `maskText` or `<LucidaUnmask>` say (`maskScreen: true` in
|
|
115
|
+
the capture options); screenshots paint them all over.
|
|
116
|
+
- **Text patterns** (P-M46): `replay: { maskTextPatterns: ["\\d{4,}"] }` plus `replay_mask_text_patterns` (regular
|
|
117
|
+
expressions; one that does not compile is ignored). The native encoder stars matches in shown text and paints matching views
|
|
118
|
+
in screenshots (`maskTextPatterns` in the capture options); JS stars them again in the returned wireframe.
|
|
119
|
+
- **`$dead_swipe`** (P-M46, `captureDeadSwipes`, default true, fed by `<LucidaTouchCapture>` or
|
|
120
|
+
`client.replay.swipeBegan()` / `swipeEnded(dx, dy)`): a swipe of 48 pt or more after which the starred wireframe is unchanged
|
|
121
|
+
~700 ms later. Properties: `$screen_name`, `$swipe_direction` (`left|right|up|down`), `$swipe_distance`. Never text or
|
|
122
|
+
view content; at most one per 2 s.
|
|
123
|
+
- **Controlled exposure** (P-L12): when the project sends `replay_exposure_fields` and `replay_exposure_key`,
|
|
124
|
+
`client.captureSensitive("card_number", value)` (field = your `testID`) encrypts the value natively with RSA-OAEP-SHA256
|
|
125
|
+
(`encryptSensitive(pkcs1, n, e, plain)`, a blocking synchronous method of the LucidaReplay module) and sends
|
|
126
|
+
`$sensitive_capture` (`$exposure_field`, `$exposure_kid`, `$exposure_ciphertext`, `$screen_name`, `$exposure_truncated`
|
|
127
|
+
when cut to 190 bytes). Only an audited reveal on the server can read it. Never pass a secure field; identical values are
|
|
128
|
+
sent once per session; nothing is persisted; a missing or failing native method sends nothing.
|
|
129
|
+
|
|
130
|
+
### Encrypting the offline queue at rest
|
|
131
|
+
|
|
132
|
+
The same native module exposes two blocking synchronous methods, `encryptQueue` / `decryptQueue`: AES-256-GCM with a key the
|
|
133
|
+
platform keeps (iOS Keychain via the iOS SDK's `KeychainQueueCipher`, Android Keystore via `KeystoreQueueCipher`), generated on
|
|
134
|
+
first use. Wire it with `nativeQueueCipher`:
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
createClient("lc_pk_...", { asyncStorage, queueCipher: nativeQueueCipher(NativeModules.LucidaReplay) });
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Only the offline queue (`lc_offline`) is encrypted. A lost or rotated key reads as an empty queue, and a native failure on
|
|
141
|
+
encrypt stores an empty value, never plaintext. Blocking sync methods need JSI, so they do not work under the remote JS debugger.
|
|
142
|
+
Covered by `test/native-cipher.test.ts` (native module mocked with real AES-GCM); the native halves are verified in step 5 below.
|
|
143
|
+
|
|
144
|
+
### Verifying the native modules in a real app (G35)
|
|
145
|
+
|
|
146
|
+
Not done in this repository (no RN toolchain, no Xcode/Gradle builds on the dev disk). Exact steps:
|
|
147
|
+
|
|
148
|
+
1. `npx @react-native-community/cli init LucidaProbe` (RN >= 0.74), then `pnpm add file:<repo>/sdks/react-native` (or `pnpm pack` it).
|
|
149
|
+
2. iOS: add the `Lucida` Swift package (`sdks/ios`) via SPM, copy `ios/LucidaReplay.swift` and `LucidaReplay.m` into the app target
|
|
150
|
+
(create a bridging header if Xcode asks), `cd ios && pod install`, build for a simulator. Expect: it compiles; `NativeModules.LucidaReplay.captureWireframe({screen:"Home",maskText:true})` resolves JSON starting `{"width"`.
|
|
151
|
+
3. Android: add `include ':lucida-android'` / `project(':lucida-android').projectDir = new File('<repo>/sdks/android/lucida-android')` and the `lucida-core` module,
|
|
152
|
+
copy `android/src/main/kotlin/com/lucida/reactnative/*.kt`, register the package in `MainApplication`, `./gradlew :app:assembleDebug`. Expect the same JSON.
|
|
153
|
+
4. In JS: `createClient("lc_pk_...", { replay: { enabled: true, module: NativeModules.LucidaReplay }, flagStream: true })`, grant consent, open a screen, and confirm
|
|
154
|
+
`POST /v1/replay` chunks arrive and `GET /v1/flags/stream` connects (RN's `fetch` usually cannot stream response bodies; then the SDK silently polls every `pollMs`).
|
|
155
|
+
5. Queue cipher: with `queueCipher: nativeQueueCipher(NativeModules.LucidaReplay)` go offline, capture an event, and confirm the `lc_offline` AsyncStorage value is
|
|
156
|
+
opaque base64 (no event name in it) and that the event is delivered after reconnecting and an app restart.
|
|
157
|
+
6. Native unit coverage that exists today: `swift test` (sdks/ios, ReplayBridgeTests) and `make sdk-android` (ReplayBridgeTest).
|
|
158
|
+
|
|
159
|
+
## In-app guides
|
|
160
|
+
|
|
161
|
+
Kinds `modal`, `banner`, `announcement`, `slideout`, `tour`, `carousel` (Back / Next with a slide pager) and, with an
|
|
162
|
+
anchoring presenter, `tooltip` / `hotspot`. A step's `native_id` anchors it to a native view: wrap it in `<GuideAnchor testID="checkout">` (React Native cannot look views up by testID from JS) and mount `<LucidaGuides />` as the last child of the app root: the bubble is drawn next
|
|
163
|
+
to the view and follows it on scroll and relayout; a hotspot is a pulsing dot that opens the step. When the view does not
|
|
164
|
+
appear within `wait_ms` (default 3 s, max 15 s) the SDK sends `$guide_target_missing {step_id, selector}` and shows the step
|
|
165
|
+
unanchored; a view gone for 2 s closes the step. The resolved `appearance` tokens (background, text, accent, radius,
|
|
166
|
+
font) apply, with `appearance.dark.tokens` when `theme_mode` is dark, or auto and the device is dark.
|
|
167
|
+
|
|
168
|
+
## Out of scope
|
|
169
|
+
|
|
170
|
+
Push registration and attribution.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
package com.lucida.reactnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.Promise
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
7
|
+
import com.facebook.react.bridge.ReactMethod
|
|
8
|
+
import com.facebook.react.bridge.ReadableMap
|
|
9
|
+
import com.facebook.react.bridge.UiThreadUtil
|
|
10
|
+
import com.lucida.android.KeystoreQueueCipher
|
|
11
|
+
import com.lucida.android.WireframeCapture
|
|
12
|
+
import com.lucida.core.ExposureKey
|
|
13
|
+
import com.lucida.core.SensitiveCapture
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* React Native module `NativeModules.LucidaReplay`. Contract: see src/replay.ts (NativeReplayModule).
|
|
17
|
+
* Not compiled in this repository's CI (needs the React Native toolchain); the logic it calls
|
|
18
|
+
* (WireframeCapture -> ViewHierarchy -> ReplayBridge -> Wireframe, KeystoreQueueCipher) is covered by `make sdk-android`.
|
|
19
|
+
*/
|
|
20
|
+
class LucidaReplayModule(ctx: ReactApplicationContext) : ReactContextBaseJavaModule(ctx) {
|
|
21
|
+
override fun getName() = "LucidaReplay"
|
|
22
|
+
|
|
23
|
+
// Android Keystore AES-256-GCM key, created on first use; same ciphertext format as the Android SDK's queue cipher.
|
|
24
|
+
private val cipher by lazy { KeystoreQueueCipher() }
|
|
25
|
+
|
|
26
|
+
/** Blocking on purpose: the JS queue storage is synchronous (see src/native-cipher.ts). Fails closed with "". */
|
|
27
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
28
|
+
fun encryptQueue(plain: String): String = runCatching { cipher.encrypt(plain) }.getOrDefault("")
|
|
29
|
+
|
|
30
|
+
/** null when the value cannot be decrypted (key lost or rotated); the queue then starts empty. */
|
|
31
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
32
|
+
fun decryptQueue(value: String): String? = runCatching { cipher.decrypt(value) }.getOrNull()
|
|
33
|
+
|
|
34
|
+
/** Blocking synchronous (P-L12, src/sensitive.ts): RSA-OAEP with SHA-256 and MGF1-SHA-256 over (n, e); "" on failure. */
|
|
35
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
36
|
+
fun encryptSensitive(pkcs1: String, n: String, e: String, plain: String): String =
|
|
37
|
+
SensitiveCapture.encrypt(plain.toByteArray(Charsets.UTF_8), ExposureKey("", n, e, pkcs1)) ?: ""
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Install attribution (src/install.ts): resolves `{platform: "android", referrer, clickTs, beginTs}` from the Play Install
|
|
41
|
+
* Referrer, or null when the library is absent or the service is unavailable. Needs `com.android.installreferrer:installreferrer`.
|
|
42
|
+
*/
|
|
43
|
+
@ReactMethod
|
|
44
|
+
fun installInfo(promise: Promise) {
|
|
45
|
+
try {
|
|
46
|
+
val client = com.android.installreferrer.api.InstallReferrerClient.newBuilder(reactApplicationContext).build()
|
|
47
|
+
client.startConnection(object : com.android.installreferrer.api.InstallReferrerStateListener {
|
|
48
|
+
override fun onInstallReferrerSetupFinished(code: Int) {
|
|
49
|
+
try {
|
|
50
|
+
val m = Arguments.createMap()
|
|
51
|
+
m.putString("platform", "android")
|
|
52
|
+
if (code == com.android.installreferrer.api.InstallReferrerClient.InstallReferrerResponse.OK) {
|
|
53
|
+
val r = client.installReferrer
|
|
54
|
+
m.putString("referrer", r.installReferrer)
|
|
55
|
+
m.putDouble("clickTs", r.referrerClickTimestampSeconds.toDouble())
|
|
56
|
+
m.putDouble("beginTs", r.installBeginTimestampSeconds.toDouble())
|
|
57
|
+
}
|
|
58
|
+
promise.resolve(m)
|
|
59
|
+
} catch (_: Throwable) {
|
|
60
|
+
promise.resolve(null)
|
|
61
|
+
}
|
|
62
|
+
try { client.endConnection() } catch (_: Throwable) {}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override fun onInstallReferrerServiceDisconnected() = Unit
|
|
66
|
+
})
|
|
67
|
+
} catch (_: Throwable) { // includes NoClassDefFoundError
|
|
68
|
+
promise.resolve(null)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Resolves the JSON text of one wireframe (or masked screenshot) capture, or "" when there is no resumed Activity. */
|
|
73
|
+
@ReactMethod
|
|
74
|
+
fun captureWireframe(options: ReadableMap, promise: Promise) {
|
|
75
|
+
val screen = if (options.hasKey("screen")) options.getString("screen") ?: "Unknown" else "Unknown"
|
|
76
|
+
val maskText = if (options.hasKey("maskText")) options.getBoolean("maskText") else true
|
|
77
|
+
fun flag(k: String) = if (options.hasKey(k)) options.getBoolean(k) else true
|
|
78
|
+
val maskInputs = flag("maskAllTextInputs")
|
|
79
|
+
val maskImages = flag("maskAllImages")
|
|
80
|
+
val maskSandboxed = flag("maskSandboxedViews")
|
|
81
|
+
// Screenshot mode: JPEG quality 0..100; masks are painted on the bitmap before it is encoded (ScreenshotCapture).
|
|
82
|
+
val shots = options.hasKey("mode") && options.getString("mode") == "screenshot"
|
|
83
|
+
val quality = if (!shots) null else Math.round(100 * (if (options.hasKey("screenshotQuality")) options.getDouble("screenshotQuality") else 0.4)).toInt()
|
|
84
|
+
val maskScreen = options.hasKey("maskScreen") && options.getBoolean("maskScreen") // P-M17
|
|
85
|
+
val patterns = if (options.hasKey("maskTextPatterns")) options.getArray("maskTextPatterns")?.toArrayList()?.filterIsInstance<String>() ?: emptyList() else emptyList() // P-M46
|
|
86
|
+
val activity = currentActivity
|
|
87
|
+
if (activity == null) {
|
|
88
|
+
promise.resolve("")
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
// View access must happen on the main thread.
|
|
92
|
+
UiThreadUtil.runOnUiThread {
|
|
93
|
+
promise.resolve(runCatching { WireframeCapture.capture(activity, screen, maskText, maskInputs, maskImages, maskSandboxed, quality, maskScreen, patterns) }.getOrDefault(""))
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|