@goliapkg/sentori-react-native 0.7.1 → 0.7.3

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/src/mask.ts ADDED
@@ -0,0 +1,41 @@
1
+ // v0.7.3 — mask discovery via consumer-supplied query callback.
2
+ //
3
+ // The SDK does not own a registry of masked regions. The host app
4
+ // keeps its own (e.g. a `Set<string>` updated as `<Maskable>`
5
+ // components mount/unmount) and hands the SDK a thunk that returns
6
+ // the current list of native-IDs to redact. The SDK calls the thunk
7
+ // once per screenshot capture — cheap, called rarely, only on error.
8
+ //
9
+ // Why this shape: a logging SDK should never live on the render
10
+ // path. Earlier iterations exported `<MaskRegion>` (React component)
11
+ // and `setMaskedNode` (imperative ref helper), which forced every
12
+ // PII-bearing UI file to import from the SDK and put SDK bugs in
13
+ // the user's render tree. This module is JS-only — no React, no JSX,
14
+ // no native module touch — so swapping or removing the SDK doesn't
15
+ // affect rendering.
16
+
17
+ type MaskQuery = () => string[];
18
+
19
+ let _query: MaskQuery | null = null;
20
+
21
+ /**
22
+ * Register a callback the SDK calls right before each screenshot
23
+ * capture. Return the native-IDs (the `nativeID` prop on the RN
24
+ * `<View>`) that should be blacked-out in the captured image.
25
+ *
26
+ * Idempotent: a second call replaces the first. Pass `null` (or
27
+ * call `clearMaskQuery`) to detach.
28
+ */
29
+ export function registerMaskQuery(query: MaskQuery): void {
30
+ _query = query;
31
+ }
32
+
33
+ /** Unregister. Mostly for tests / teardown. */
34
+ export function clearMaskQuery(): void {
35
+ _query = null;
36
+ }
37
+
38
+ /** Internal — read by `handlers/screenshot.ts` at capture time. */
39
+ export function getRegisteredMaskQuery(): MaskQuery | null {
40
+ return _query;
41
+ }
package/src/native.ts CHANGED
@@ -11,6 +11,18 @@ type SentoriNativeModule = {
11
11
  release: string
12
12
  token: string
13
13
  }) => void
14
+ /**
15
+ * v0.7.3 — JS-triggered screenshot with consumer-supplied mask IDs.
16
+ * `maskedIds` are RN `nativeID` strings; native walks the view
17
+ * tree, finds each subview by identifier, and paints a black
18
+ * rectangle over its frame in the captured bitmap. Resolves to
19
+ * `null` if there's no key window / API < 24 (Android) / render
20
+ * timed out. Replaced the previous `react-native-view-shot`
21
+ * peer-dep path.
22
+ */
23
+ captureScreenshotWithMask?: (
24
+ maskedIds: string[],
25
+ ) => Promise<null | { base64: string; mediaType: string }>
14
26
  /**
15
27
  * Phase 22 sub-D / sub-E: cross-platform main-thread watchdog.
16
28
  * Android: 5 s / 1 s defaults (matches the OS ANR threshold).
@@ -114,3 +126,26 @@ export function stopAnrWatchdog(): void {
114
126
  // ignore
115
127
  }
116
128
  }
129
+
130
+ /**
131
+ * v0.7.3 — drives the native screenshot path. JS side passes the
132
+ * current list of mask `nativeID`s (read from the consumer's
133
+ * registered mask query); native renders + redacts.
134
+ *
135
+ * Returns `null` on every failure mode: no native module bound
136
+ * (jest, bun test, web), method missing (older native build still
137
+ * deployed), capture failed (no key window, timed out, etc.).
138
+ * Callers must treat `null` as "no screenshot this round" — the
139
+ * error event still ships, just without a thumbnail.
140
+ */
141
+ export async function captureNativeScreenshotWithMask(
142
+ maskedIds: string[],
143
+ ): Promise<null | { base64: string; mediaType: string }> {
144
+ const n = native()
145
+ if (!n?.captureScreenshotWithMask) return null
146
+ try {
147
+ return await n.captureScreenshotWithMask(maskedIds)
148
+ } catch {
149
+ return null
150
+ }
151
+ }
package/src/mask.tsx DELETED
@@ -1,150 +0,0 @@
1
- // Phase 42 sub-D.09/10 + Phase 48 sub-B — mark UI regions as "do not
2
- // screenshot" AND actually redact them at capture time.
3
- //
4
- // `<MaskRegion>` renders its children normally, plus a black overlay
5
- // `<View>` that sits on top of them with `opacity: 0`. Right before
6
- // `captureScreenshot()` calls into react-native-view-shot, the SDK
7
- // flips every registered overlay to `opacity: 1` (black square covers
8
- // the children), captures, then flips back to `opacity: 0` so the
9
- // user never sees the overlay. The overlay uses `pointerEvents="none"`
10
- // so it never intercepts touches.
11
- //
12
- // `setMaskedNode(ref)` is the imperative escape hatch for views you
13
- // can't wrap. We can't inject an overlay into a foreign view, so the
14
- // imperative path falls back to setting the registered view's own
15
- // `opacity: 0` for the capture window — content underneath may show
16
- // through, but that beats sending the sensitive content to the server.
17
- // Prefer `<MaskRegion>` when you control the subtree.
18
-
19
- import React, { type ReactNode, useEffect, useRef } from 'react';
20
- import { StyleSheet, View, type ViewProps } from 'react-native';
21
-
22
- /** What we drive in the capture window: any handle with
23
- * `setNativeProps({ opacity })`. RN's View instance satisfies this. */
24
- type Maskable = {
25
- setNativeProps?: (props: { style?: { opacity?: number } }) => void;
26
- };
27
-
28
- const _maskedRefs = new Set<Maskable>();
29
- const _maskedOverlays = new Set<Maskable>();
30
- const _maskedNativeIds = new Set<string>();
31
-
32
- /**
33
- * Imperative registration: pass a ref obtained via `useRef()` /
34
- * `createRef()` to a `<View>` you want hidden from screenshots.
35
- */
36
- export function setMaskedNode(node: null | Maskable | unknown): void {
37
- if (!node || typeof (node as Maskable).setNativeProps !== 'function') return;
38
- _maskedRefs.add(node as Maskable);
39
- }
40
-
41
- export function unsetMaskedNode(node: null | Maskable | unknown): void {
42
- if (!node) return;
43
- _maskedRefs.delete(node as Maskable);
44
- }
45
-
46
- /** Returns the current set of registered masked nodes + nativeIDs.
47
- * Read by the native screenshotter layer (iOS / Android sub-E / F). */
48
- export function getMaskedRegions(): {
49
- nativeIds: Set<string>;
50
- overlays: Set<Maskable>;
51
- refs: Set<Maskable>;
52
- } {
53
- return { nativeIds: _maskedNativeIds, overlays: _maskedOverlays, refs: _maskedRefs };
54
- }
55
-
56
- /**
57
- * Phase 48 sub-B — engage masking right before screenshot capture.
58
- * Returns a function the caller must invoke once capture is done so
59
- * the user never sees the black overlays.
60
- *
61
- * Two paths:
62
- * - Overlays from `<MaskRegion>`: flip opacity 0 → 1 (cover children).
63
- * - Imperative refs from `setMaskedNode`: flip opacity 1 → 0 on the
64
- * view itself (whole subtree disappears for one frame).
65
- *
66
- * All `setNativeProps` calls are best-effort — a failure on one
67
- * doesn't block the others or the capture.
68
- */
69
- export function engageMasks(): () => void {
70
- const overlaysEngaged: Maskable[] = [];
71
- for (const o of _maskedOverlays) {
72
- try {
73
- o.setNativeProps?.({ style: { opacity: 1 } });
74
- overlaysEngaged.push(o);
75
- } catch {
76
- // skip
77
- }
78
- }
79
- const refsEngaged: Maskable[] = [];
80
- for (const r of _maskedRefs) {
81
- try {
82
- r.setNativeProps?.({ style: { opacity: 0 } });
83
- refsEngaged.push(r);
84
- } catch {
85
- // skip
86
- }
87
- }
88
- return () => {
89
- for (const o of overlaysEngaged) {
90
- try {
91
- o.setNativeProps?.({ style: { opacity: 0 } });
92
- } catch {
93
- // skip
94
- }
95
- }
96
- for (const r of refsEngaged) {
97
- try {
98
- r.setNativeProps?.({ style: { opacity: 1 } });
99
- } catch {
100
- // skip
101
- }
102
- }
103
- };
104
- }
105
-
106
- /**
107
- * Declarative redaction. `<MaskRegion>{children}</MaskRegion>` keeps
108
- * the children visible in normal flight; under capture the overlay's
109
- * opacity is flipped to 1 and the children are hidden behind a black
110
- * square in the rendered screenshot.
111
- */
112
- export function MaskRegion({
113
- children,
114
- nativeID,
115
- ...rest
116
- }: { children: ReactNode; nativeID?: string } & ViewProps): React.JSX.Element {
117
- const idRef = useRef<string>(
118
- nativeID ?? `sentori-mask-${Math.random().toString(36).slice(2, 10)}`,
119
- );
120
- const overlayRef = useRef<null | View>(null);
121
-
122
- useEffect(() => {
123
- const id = idRef.current;
124
- _maskedNativeIds.add(id);
125
- const overlay = overlayRef.current as null | Maskable;
126
- if (overlay) _maskedOverlays.add(overlay);
127
- return () => {
128
- _maskedNativeIds.delete(id);
129
- if (overlay) _maskedOverlays.delete(overlay);
130
- };
131
- }, []);
132
-
133
- return (
134
- <View collapsable={false} nativeID={idRef.current} {...rest}>
135
- {children}
136
- <View
137
- pointerEvents="none"
138
- ref={overlayRef}
139
- style={[StyleSheet.absoluteFill, { backgroundColor: '#000', opacity: 0 }]}
140
- />
141
- </View>
142
- );
143
- }
144
-
145
- /** Test-only — flush registration tables. */
146
- export function __resetMaskedRegionsForTests(): void {
147
- _maskedRefs.clear();
148
- _maskedOverlays.clear();
149
- _maskedNativeIds.clear();
150
- }