@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/android/src/main/java/com/sentori/SentoriModule.kt +10 -0
- package/android/src/main/java/com/sentori/SentoriScreenshotCapture.kt +60 -2
- package/ios/SentoriModule.swift +10 -0
- package/ios/SentoriScreenshotCapture.swift +76 -2
- package/lib/handlers/promise.d.ts.map +1 -1
- package/lib/handlers/promise.js +6 -2
- package/lib/handlers/promise.js.map +1 -1
- package/lib/handlers/screenshot.d.ts +3 -2
- package/lib/handlers/screenshot.d.ts.map +1 -1
- package/lib/handlers/screenshot.js +48 -86
- package/lib/handlers/screenshot.js.map +1 -1
- package/lib/index.d.ts +4 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -5
- package/lib/index.js.map +1 -1
- package/lib/init.d.ts +8 -4
- package/lib/init.d.ts.map +1 -1
- package/lib/init.js.map +1 -1
- package/lib/mask.d.ts +11 -47
- package/lib/mask.d.ts.map +1 -1
- package/lib/mask.js +27 -116
- package/lib/mask.js.map +1 -1
- package/lib/native.d.ts +15 -0
- package/lib/native.d.ts.map +1 -1
- package/lib/native.js +22 -0
- package/lib/native.js.map +1 -1
- package/package.json +4 -9
- package/src/__tests__/screenshot.test.ts +6 -8
- package/src/handlers/promise.ts +7 -3
- package/src/handlers/screenshot.ts +47 -110
- package/src/index.ts +4 -5
- package/src/init.ts +8 -4
- package/src/mask.ts +41 -0
- package/src/native.ts +35 -0
- package/src/mask.tsx +0 -150
package/lib/mask.d.ts
CHANGED
|
@@ -1,52 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
import { type ViewProps } from 'react-native';
|
|
3
|
-
/** What we drive in the capture window: any handle with
|
|
4
|
-
* `setNativeProps({ opacity })`. RN's View instance satisfies this. */
|
|
5
|
-
type Maskable = {
|
|
6
|
-
setNativeProps?: (props: {
|
|
7
|
-
style?: {
|
|
8
|
-
opacity?: number;
|
|
9
|
-
};
|
|
10
|
-
}) => void;
|
|
11
|
-
};
|
|
1
|
+
type MaskQuery = () => string[];
|
|
12
2
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
export declare function setMaskedNode(node: null | Maskable | unknown): void;
|
|
17
|
-
export declare function unsetMaskedNode(node: null | Maskable | unknown): void;
|
|
18
|
-
/** Returns the current set of registered masked nodes + nativeIDs.
|
|
19
|
-
* Read by the native screenshotter layer (iOS / Android sub-E / F). */
|
|
20
|
-
export declare function getMaskedRegions(): {
|
|
21
|
-
nativeIds: Set<string>;
|
|
22
|
-
overlays: Set<Maskable>;
|
|
23
|
-
refs: Set<Maskable>;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Phase 48 sub-B — engage masking right before screenshot capture.
|
|
27
|
-
* Returns a function the caller must invoke once capture is done so
|
|
28
|
-
* the user never sees the black overlays.
|
|
29
|
-
*
|
|
30
|
-
* Two paths:
|
|
31
|
-
* - Overlays from `<MaskRegion>`: flip opacity 0 → 1 (cover children).
|
|
32
|
-
* - Imperative refs from `setMaskedNode`: flip opacity 1 → 0 on the
|
|
33
|
-
* view itself (whole subtree disappears for one frame).
|
|
3
|
+
* Register a callback the SDK calls right before each screenshot
|
|
4
|
+
* capture. Return the native-IDs (the `nativeID` prop on the RN
|
|
5
|
+
* `<View>`) that should be blacked-out in the captured image.
|
|
34
6
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*/
|
|
38
|
-
export declare function engageMasks(): () => void;
|
|
39
|
-
/**
|
|
40
|
-
* Declarative redaction. `<MaskRegion>{children}</MaskRegion>` keeps
|
|
41
|
-
* the children visible in normal flight; under capture the overlay's
|
|
42
|
-
* opacity is flipped to 1 and the children are hidden behind a black
|
|
43
|
-
* square in the rendered screenshot.
|
|
7
|
+
* Idempotent: a second call replaces the first. Pass `null` (or
|
|
8
|
+
* call `clearMaskQuery`) to detach.
|
|
44
9
|
*/
|
|
45
|
-
export declare function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export declare function __resetMaskedRegionsForTests(): void;
|
|
10
|
+
export declare function registerMaskQuery(query: MaskQuery): void;
|
|
11
|
+
/** Unregister. Mostly for tests / teardown. */
|
|
12
|
+
export declare function clearMaskQuery(): void;
|
|
13
|
+
/** Internal — read by `handlers/screenshot.ts` at capture time. */
|
|
14
|
+
export declare function getRegisteredMaskQuery(): MaskQuery | null;
|
|
51
15
|
export {};
|
|
52
16
|
//# sourceMappingURL=mask.d.ts.map
|
package/lib/mask.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mask.d.ts","sourceRoot":"","sources":["../src/mask.
|
|
1
|
+
{"version":3,"file":"mask.d.ts","sourceRoot":"","sources":["../src/mask.ts"],"names":[],"mappings":"AAgBA,KAAK,SAAS,GAAG,MAAM,MAAM,EAAE,CAAC;AAIhC;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAExD;AAED,+CAA+C;AAC/C,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAED,mEAAmE;AACnE,wBAAgB,sBAAsB,IAAI,SAAS,GAAG,IAAI,CAEzD"}
|
package/lib/mask.js
CHANGED
|
@@ -1,125 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
// Phase 42 sub-D.09/10 + Phase 48 sub-B — mark UI regions as "do not
|
|
3
|
-
// screenshot" AND actually redact them at capture time.
|
|
1
|
+
// v0.7.3 — mask discovery via consumer-supplied query callback.
|
|
4
2
|
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
// user never sees the overlay. The overlay uses `pointerEvents="none"`
|
|
11
|
-
// so it never intercepts touches.
|
|
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.
|
|
12
8
|
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const _maskedRefs = new Set();
|
|
22
|
-
const _maskedOverlays = new Set();
|
|
23
|
-
const _maskedNativeIds = new Set();
|
|
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
|
+
let _query = null;
|
|
24
17
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
export function setMaskedNode(node) {
|
|
29
|
-
if (!node || typeof node.setNativeProps !== 'function')
|
|
30
|
-
return;
|
|
31
|
-
_maskedRefs.add(node);
|
|
32
|
-
}
|
|
33
|
-
export function unsetMaskedNode(node) {
|
|
34
|
-
if (!node)
|
|
35
|
-
return;
|
|
36
|
-
_maskedRefs.delete(node);
|
|
37
|
-
}
|
|
38
|
-
/** Returns the current set of registered masked nodes + nativeIDs.
|
|
39
|
-
* Read by the native screenshotter layer (iOS / Android sub-E / F). */
|
|
40
|
-
export function getMaskedRegions() {
|
|
41
|
-
return { nativeIds: _maskedNativeIds, overlays: _maskedOverlays, refs: _maskedRefs };
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Phase 48 sub-B — engage masking right before screenshot capture.
|
|
45
|
-
* Returns a function the caller must invoke once capture is done so
|
|
46
|
-
* the user never sees the black overlays.
|
|
47
|
-
*
|
|
48
|
-
* Two paths:
|
|
49
|
-
* - Overlays from `<MaskRegion>`: flip opacity 0 → 1 (cover children).
|
|
50
|
-
* - Imperative refs from `setMaskedNode`: flip opacity 1 → 0 on the
|
|
51
|
-
* view itself (whole subtree disappears for one frame).
|
|
18
|
+
* Register a callback the SDK calls right before each screenshot
|
|
19
|
+
* capture. Return the native-IDs (the `nativeID` prop on the RN
|
|
20
|
+
* `<View>`) that should be blacked-out in the captured image.
|
|
52
21
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
22
|
+
* Idempotent: a second call replaces the first. Pass `null` (or
|
|
23
|
+
* call `clearMaskQuery`) to detach.
|
|
55
24
|
*/
|
|
56
|
-
export function
|
|
57
|
-
|
|
58
|
-
for (const o of _maskedOverlays) {
|
|
59
|
-
try {
|
|
60
|
-
o.setNativeProps?.({ style: { opacity: 1 } });
|
|
61
|
-
overlaysEngaged.push(o);
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// skip
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const refsEngaged = [];
|
|
68
|
-
for (const r of _maskedRefs) {
|
|
69
|
-
try {
|
|
70
|
-
r.setNativeProps?.({ style: { opacity: 0 } });
|
|
71
|
-
refsEngaged.push(r);
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
// skip
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return () => {
|
|
78
|
-
for (const o of overlaysEngaged) {
|
|
79
|
-
try {
|
|
80
|
-
o.setNativeProps?.({ style: { opacity: 0 } });
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
// skip
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
for (const r of refsEngaged) {
|
|
87
|
-
try {
|
|
88
|
-
r.setNativeProps?.({ style: { opacity: 1 } });
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
// skip
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
25
|
+
export function registerMaskQuery(query) {
|
|
26
|
+
_query = query;
|
|
95
27
|
}
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* opacity is flipped to 1 and the children are hidden behind a black
|
|
100
|
-
* square in the rendered screenshot.
|
|
101
|
-
*/
|
|
102
|
-
export function MaskRegion({ children, nativeID, ...rest }) {
|
|
103
|
-
const idRef = useRef(nativeID ?? `sentori-mask-${Math.random().toString(36).slice(2, 10)}`);
|
|
104
|
-
const overlayRef = useRef(null);
|
|
105
|
-
useEffect(() => {
|
|
106
|
-
const id = idRef.current;
|
|
107
|
-
_maskedNativeIds.add(id);
|
|
108
|
-
const overlay = overlayRef.current;
|
|
109
|
-
if (overlay)
|
|
110
|
-
_maskedOverlays.add(overlay);
|
|
111
|
-
return () => {
|
|
112
|
-
_maskedNativeIds.delete(id);
|
|
113
|
-
if (overlay)
|
|
114
|
-
_maskedOverlays.delete(overlay);
|
|
115
|
-
};
|
|
116
|
-
}, []);
|
|
117
|
-
return (_jsxs(View, { collapsable: false, nativeID: idRef.current, ...rest, children: [children, _jsx(View, { pointerEvents: "none", ref: overlayRef, style: [StyleSheet.absoluteFill, { backgroundColor: '#000', opacity: 0 }] })] }));
|
|
28
|
+
/** Unregister. Mostly for tests / teardown. */
|
|
29
|
+
export function clearMaskQuery() {
|
|
30
|
+
_query = null;
|
|
118
31
|
}
|
|
119
|
-
/**
|
|
120
|
-
export function
|
|
121
|
-
|
|
122
|
-
_maskedOverlays.clear();
|
|
123
|
-
_maskedNativeIds.clear();
|
|
32
|
+
/** Internal — read by `handlers/screenshot.ts` at capture time. */
|
|
33
|
+
export function getRegisteredMaskQuery() {
|
|
34
|
+
return _query;
|
|
124
35
|
}
|
|
125
36
|
//# sourceMappingURL=mask.js.map
|
package/lib/mask.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mask.js","sourceRoot":"","sources":["../src/mask.
|
|
1
|
+
{"version":3,"file":"mask.js","sourceRoot":"","sources":["../src/mask.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,EAAE;AACF,kEAAkE;AAClE,8DAA8D;AAC9D,mEAAmE;AACnE,oEAAoE;AACpE,qEAAqE;AACrE,EAAE;AACF,gEAAgE;AAChE,qEAAqE;AACrE,kEAAkE;AAClE,iEAAiE;AACjE,qEAAqE;AACrE,mEAAmE;AACnE,oBAAoB;AAIpB,IAAI,MAAM,GAAqB,IAAI,CAAC;AAEpC;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAgB;IAChD,MAAM,GAAG,KAAK,CAAC;AACjB,CAAC;AAED,+CAA+C;AAC/C,MAAM,UAAU,cAAc;IAC5B,MAAM,GAAG,IAAI,CAAC;AAChB,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,sBAAsB;IACpC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/lib/native.d.ts
CHANGED
|
@@ -37,4 +37,19 @@ export declare function startAnrWatchdog(options?: {
|
|
|
37
37
|
timeoutMs?: number;
|
|
38
38
|
}): void;
|
|
39
39
|
export declare function stopAnrWatchdog(): void;
|
|
40
|
+
/**
|
|
41
|
+
* v0.7.3 — drives the native screenshot path. JS side passes the
|
|
42
|
+
* current list of mask `nativeID`s (read from the consumer's
|
|
43
|
+
* registered mask query); native renders + redacts.
|
|
44
|
+
*
|
|
45
|
+
* Returns `null` on every failure mode: no native module bound
|
|
46
|
+
* (jest, bun test, web), method missing (older native build still
|
|
47
|
+
* deployed), capture failed (no key window, timed out, etc.).
|
|
48
|
+
* Callers must treat `null` as "no screenshot this round" — the
|
|
49
|
+
* error event still ships, just without a thumbnail.
|
|
50
|
+
*/
|
|
51
|
+
export declare function captureNativeScreenshotWithMask(maskedIds: string[]): Promise<null | {
|
|
52
|
+
base64: string;
|
|
53
|
+
mediaType: string;
|
|
54
|
+
}>;
|
|
40
55
|
//# sourceMappingURL=native.d.ts.map
|
package/lib/native.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAsDH,wBAAgB,eAAe,CAAC,MAAM,EAAE;IACtC,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CACd,GAAG,IAAI,CAMP;AAED,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAQ5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAMzC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IACzC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,GAAG,IAAI,CAMP;AAED,wBAAgB,eAAe,IAAI,IAAI,CAMtC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,+BAA+B,CACnD,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,IAAI,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAQvD"}
|
package/lib/native.js
CHANGED
|
@@ -80,4 +80,26 @@ export function stopAnrWatchdog() {
|
|
|
80
80
|
// ignore
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* v0.7.3 — drives the native screenshot path. JS side passes the
|
|
85
|
+
* current list of mask `nativeID`s (read from the consumer's
|
|
86
|
+
* registered mask query); native renders + redacts.
|
|
87
|
+
*
|
|
88
|
+
* Returns `null` on every failure mode: no native module bound
|
|
89
|
+
* (jest, bun test, web), method missing (older native build still
|
|
90
|
+
* deployed), capture failed (no key window, timed out, etc.).
|
|
91
|
+
* Callers must treat `null` as "no screenshot this round" — the
|
|
92
|
+
* error event still ships, just without a thumbnail.
|
|
93
|
+
*/
|
|
94
|
+
export async function captureNativeScreenshotWithMask(maskedIds) {
|
|
95
|
+
const n = native();
|
|
96
|
+
if (!n?.captureScreenshotWithMask)
|
|
97
|
+
return null;
|
|
98
|
+
try {
|
|
99
|
+
return await n.captureScreenshotWithMask(maskedIds);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
83
105
|
//# sourceMappingURL=native.js.map
|
package/lib/native.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAuCH,IAAI,OAA+C,CAAA;AAEnD,SAAS,MAAM;IACb,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,OAAO,CAAA;IACzC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,OAAO,CAAC,mBAAmB,CAEvC,CAAA;QACD,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAsB,SAAS,CAAC,CAAA;IACpE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,IAAI,CAAA;IAChB,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAI/B;IACC,IAAI,CAAC;QACH,MAAM,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,sBAAsB;IACxB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,MAAM,CAAC,GAAG,MAAM,EAAE,CAAA;IAClB,IAAI,CAAC,CAAC;QAAE,OAAO,EAAE,CAAA;IACjB,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,CAAC,YAAY,EAAE,CAAA;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAA;IACX,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB;IAChC,IAAI,CAAC;QACH,MAAM,EAAE,EAAE,sBAAsB,EAAE,EAAE,CAAA;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,sCAAsC;IACxC,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAIhC;IACC,IAAI,CAAC;QACH,MAAM,EAAE,EAAE,gBAAgB,EAAE,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,gCAAgC;IAClC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,IAAI,CAAC;QACH,MAAM,EAAE,EAAE,eAAe,EAAE,EAAE,CAAA;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,SAAS;IACX,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,SAAmB;IAEnB,MAAM,CAAC,GAAG,MAAM,EAAE,CAAA;IAClB,IAAI,CAAC,CAAC,EAAE,yBAAyB;QAAE,OAAO,IAAI,CAAA;IAC9C,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAA;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goliapkg/sentori-react-native",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "Sentori SDK for React Native \u2014 JS-layer error capture, native crash handlers (iOS / Android), batched transport, fetch + react-navigation tracing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://sentori.golia.jp",
|
|
@@ -41,8 +41,7 @@
|
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"expo-modules-core": ">=2.0",
|
|
43
43
|
"react": ">=18",
|
|
44
|
-
"react-native": ">=0.74"
|
|
45
|
-
"react-native-view-shot": ">=3.8"
|
|
44
|
+
"react-native": ">=0.74"
|
|
46
45
|
},
|
|
47
46
|
"peerDependenciesMeta": {
|
|
48
47
|
"@react-native-async-storage/async-storage": {
|
|
@@ -50,15 +49,11 @@
|
|
|
50
49
|
},
|
|
51
50
|
"expo-modules-core": {
|
|
52
51
|
"optional": true
|
|
53
|
-
},
|
|
54
|
-
"react-native-view-shot": {
|
|
55
|
-
"optional": true
|
|
56
52
|
}
|
|
57
53
|
},
|
|
58
54
|
"optionalDependencies": {
|
|
59
55
|
"@react-native-async-storage/async-storage": ">=1.23",
|
|
60
|
-
"expo-modules-core": ">=2.0"
|
|
61
|
-
"react-native-view-shot": ">=3.8"
|
|
56
|
+
"expo-modules-core": ">=2.0"
|
|
62
57
|
},
|
|
63
58
|
"devDependencies": {
|
|
64
59
|
"@types/bun": "latest",
|
|
@@ -69,6 +64,6 @@
|
|
|
69
64
|
"access": "public"
|
|
70
65
|
},
|
|
71
66
|
"dependencies": {
|
|
72
|
-
"@goliapkg/sentori-core": "0.
|
|
67
|
+
"@goliapkg/sentori-core": "0.7.0"
|
|
73
68
|
}
|
|
74
69
|
}
|
|
@@ -3,15 +3,13 @@ import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test';
|
|
|
3
3
|
import { setConfig, __resetForTests as resetConfig } from '../config';
|
|
4
4
|
import { uploadAttachment } from '../transport';
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// Unit coverage for the upload pipeline.
|
|
7
7
|
//
|
|
8
|
-
// `captureScreenshot()` itself goes through
|
|
9
|
-
// +
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
// runtime concern asserted via manual smoke + the iOS / Android
|
|
14
|
-
// XCTest / instrumentation tests in sub-E / sub-F.
|
|
8
|
+
// `captureScreenshot()` itself goes through the native module
|
|
9
|
+
// (v0.7.3+) which doesn't exist in the bun:test runtime, so we
|
|
10
|
+
// test it indirectly: `uploadAttachment` is the non-RN-API surface
|
|
11
|
+
// and that's what we hit hardest. The native render + mask redaction
|
|
12
|
+
// is exercised by the iOS XCTest / Android instrumentation tests.
|
|
15
13
|
|
|
16
14
|
const origFetch = globalThis.fetch;
|
|
17
15
|
afterEach(() => {
|
package/src/handlers/promise.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { coerceError } from '@goliapkg/sentori-core';
|
|
2
|
+
|
|
1
3
|
import { captureError } from '../capture';
|
|
2
4
|
|
|
3
5
|
type RejectionTracker = (opts: {
|
|
@@ -22,9 +24,11 @@ export const installPromiseHandler = (): void => {
|
|
|
22
24
|
allRejections: true,
|
|
23
25
|
onUnhandled: (_id, rejection) => {
|
|
24
26
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
// `coerceError` keeps the actual rejection visible. JS code
|
|
28
|
+
// routinely rejects with plain objects (`Promise.reject({code})`),
|
|
29
|
+
// which would otherwise collapse to the literal text
|
|
30
|
+
// `[object Object]` in the dashboard.
|
|
31
|
+
captureError(coerceError(rejection));
|
|
28
32
|
} catch {
|
|
29
33
|
// never throw
|
|
30
34
|
}
|
|
@@ -1,56 +1,32 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
1
|
+
// v0.7.3 — capture a screenshot of the current view tree on
|
|
2
|
+
// `captureException`. Off-main-thread, best-effort, opt-in.
|
|
3
3
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
4
|
+
// JS owns the registry of which regions to redact: the host app
|
|
5
|
+
// passes a thunk via `sentori.registerMaskQuery(() => string[])` that
|
|
6
|
+
// returns the `nativeID`s currently mounted as masked. We call it
|
|
7
|
+
// once per capture and forward the list to the native module, which
|
|
8
|
+
// renders the bitmap and paints black rectangles over the matching
|
|
9
|
+
// subviews in a single pass.
|
|
10
|
+
//
|
|
11
|
+
// History: pre-v0.7.3 went through `react-native-view-shot` (peer
|
|
12
|
+
// dep) and used a JS-side overlay-opacity trick (`<MaskRegion>` /
|
|
13
|
+
// `setMaskedNode`) to hide PII before snapshotting. That design put
|
|
14
|
+
// the SDK on the render path; a single SDK bug could break the host
|
|
15
|
+
// app's UI. v0.7.3 cuts that coupling — the SDK no longer ships
|
|
16
|
+
// React components, and the screenshot path runs entirely through
|
|
17
|
+
// the native module already used for native-crash captures.
|
|
18
|
+
//
|
|
19
|
+
// Performance:
|
|
20
|
+
// - Yield one paint via `requestAnimationFrame` before the native
|
|
21
|
+
// call so post-error UI state has committed.
|
|
22
|
+
// - 480 px on the longest edge, JPEG q=70 (iOS) / WEBP_LOSSY q=70
|
|
23
|
+
// (Android 11+). Typical payload 30-80 KB; multipart hard cap
|
|
24
|
+
// is 500 KB.
|
|
13
25
|
// - On any failure we silently return null. The error event still
|
|
14
26
|
// goes to the server; the user just doesn't see a thumbnail.
|
|
15
|
-
//
|
|
16
|
-
// `react-native-view-shot` is an OPTIONAL peer. We `require()` it
|
|
17
|
-
// lazily so apps that don't install it never pay the bundle cost
|
|
18
|
-
// or fail at import time. Without it, `captureScreenshot()` returns
|
|
19
|
-
// `null` immediately.
|
|
20
|
-
|
|
21
|
-
import { InteractionManager } from 'react-native';
|
|
22
|
-
|
|
23
|
-
import { engageMasks } from '../mask';
|
|
24
|
-
|
|
25
|
-
type CaptureRef = (
|
|
26
|
-
// Phase 42: the lib accepts a React ref or — when we pass `undefined` —
|
|
27
|
-
// shoots the root window. We always go for the root (no per-component
|
|
28
|
-
// ref) so the screenshot lines up with what the user just saw.
|
|
29
|
-
refOrUndefined: undefined,
|
|
30
|
-
opts: {
|
|
31
|
-
format?: 'jpg' | 'png' | 'webm';
|
|
32
|
-
quality?: number;
|
|
33
|
-
result?: 'base64' | 'data-uri' | 'tmpfile';
|
|
34
|
-
width?: number;
|
|
35
|
-
height?: number;
|
|
36
|
-
},
|
|
37
|
-
) => Promise<string>;
|
|
38
|
-
|
|
39
|
-
type ViewShotModule = { captureRef?: CaptureRef; default?: { captureRef?: CaptureRef } };
|
|
40
|
-
|
|
41
|
-
function loadCaptureRef(): CaptureRef | null {
|
|
42
|
-
try {
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
44
|
-
const mod = require('react-native-view-shot') as ViewShotModule;
|
|
45
|
-
return mod.captureRef ?? mod.default?.captureRef ?? null;
|
|
46
|
-
} catch {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
27
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const CAPTURE_TIMEOUT_MS = 1500;
|
|
28
|
+
import { getRegisteredMaskQuery } from '../mask';
|
|
29
|
+
import { captureNativeScreenshotWithMask } from '../native';
|
|
54
30
|
|
|
55
31
|
/** What `captureScreenshot()` hands back when it succeeds. */
|
|
56
32
|
export type ScreenshotBlob = {
|
|
@@ -60,73 +36,34 @@ export type ScreenshotBlob = {
|
|
|
60
36
|
|
|
61
37
|
/**
|
|
62
38
|
* Take one screenshot, yielding the JS thread first. Returns null on
|
|
63
|
-
* any error (
|
|
64
|
-
* Caller is responsible for opt-in checks
|
|
39
|
+
* any error (no native module bound, native side refused, capture
|
|
40
|
+
* timed out, etc.). Caller is responsible for opt-in checks
|
|
41
|
+
* (`config.screenshotsEnabled`).
|
|
65
42
|
*/
|
|
66
43
|
export async function captureScreenshot(): Promise<ScreenshotBlob | null> {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// Wait for the in-flight RN interaction batch to drain. This is
|
|
71
|
-
// why screenshot capture doesn't visibly stall the user's last
|
|
72
|
-
// action — we let React commit before we ask the OS to render.
|
|
73
|
-
await new Promise<void>((resolve) => {
|
|
74
|
-
InteractionManager.runAfterInteractions(() => resolve());
|
|
75
|
-
});
|
|
44
|
+
// Yield one paint frame so the post-error UI has committed before
|
|
45
|
+
// we ask the OS to snapshot it.
|
|
76
46
|
await new Promise<void>((resolve) => {
|
|
77
47
|
requestAnimationFrame(() => resolve());
|
|
78
48
|
});
|
|
79
49
|
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const base64 = await withTimeout(
|
|
95
|
-
captureRef(undefined, {
|
|
96
|
-
format: 'jpg',
|
|
97
|
-
quality: WEBP_QUALITY,
|
|
98
|
-
result: 'base64',
|
|
99
|
-
// Long-edge cap. RN view-shot scales preserving aspect ratio
|
|
100
|
-
// when only one dimension is set.
|
|
101
|
-
width: MAX_LONG_EDGE_PX,
|
|
102
|
-
}),
|
|
103
|
-
CAPTURE_TIMEOUT_MS,
|
|
104
|
-
);
|
|
105
|
-
restoreMasks();
|
|
106
|
-
if (!base64) return null;
|
|
107
|
-
// view-shot doesn't ship a WebP encoder on every RN version.
|
|
108
|
-
// JPEG q=70 fits the budget too (typical 40-100 KB) and every
|
|
109
|
-
// version handles it identically. We can swap to WebP once the
|
|
110
|
-
// RN minimum we support has it everywhere.
|
|
111
|
-
return { base64, mediaType: 'image/jpeg' };
|
|
112
|
-
} catch {
|
|
113
|
-
restoreMasks();
|
|
114
|
-
return null;
|
|
50
|
+
// Read the consumer-supplied mask query once per capture. If
|
|
51
|
+
// the host never called `registerMaskQuery`, no mask is applied
|
|
52
|
+
// and the full screenshot ships — sane default: SDK does nothing
|
|
53
|
+
// unless told to.
|
|
54
|
+
const query = getRegisteredMaskQuery();
|
|
55
|
+
let maskedIds: string[] = [];
|
|
56
|
+
if (query) {
|
|
57
|
+
try {
|
|
58
|
+
maskedIds = query();
|
|
59
|
+
} catch {
|
|
60
|
+
// A throwing query is the host's bug, not ours; skip mask
|
|
61
|
+
// rather than skip the screenshot.
|
|
62
|
+
maskedIds = [];
|
|
63
|
+
}
|
|
115
64
|
}
|
|
116
|
-
}
|
|
117
65
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
p.then(
|
|
122
|
-
(v) => {
|
|
123
|
-
clearTimeout(t);
|
|
124
|
-
resolve(v);
|
|
125
|
-
},
|
|
126
|
-
() => {
|
|
127
|
-
clearTimeout(t);
|
|
128
|
-
resolve(null as unknown as T);
|
|
129
|
-
},
|
|
130
|
-
);
|
|
131
|
-
});
|
|
66
|
+
const result = await captureNativeScreenshotWithMask(maskedIds);
|
|
67
|
+
if (!result) return null;
|
|
68
|
+
return { base64: result.base64, mediaType: result.mediaType };
|
|
132
69
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { init } from './init';
|
|
|
2
2
|
import { addBreadcrumb } from './breadcrumbs';
|
|
3
3
|
import { setUser, getUser, captureError, captureException, captureStep } from './capture';
|
|
4
4
|
import { ErrorBoundary } from './error-boundary';
|
|
5
|
-
import {
|
|
5
|
+
import { clearMaskQuery, registerMaskQuery } from './mask';
|
|
6
6
|
import {
|
|
7
7
|
endSession,
|
|
8
8
|
markSessionCrashed,
|
|
@@ -18,9 +18,8 @@ export const sentori = {
|
|
|
18
18
|
captureException,
|
|
19
19
|
captureStep,
|
|
20
20
|
ErrorBoundary,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
unsetMaskedNode,
|
|
21
|
+
registerMaskQuery,
|
|
22
|
+
clearMaskQuery,
|
|
24
23
|
startSession,
|
|
25
24
|
endSession,
|
|
26
25
|
markSessionCrashed,
|
|
@@ -38,7 +37,7 @@ export {
|
|
|
38
37
|
setUser,
|
|
39
38
|
} from './capture';
|
|
40
39
|
export { ErrorBoundary } from './error-boundary';
|
|
41
|
-
export {
|
|
40
|
+
export { clearMaskQuery, registerMaskQuery } from './mask';
|
|
42
41
|
export {
|
|
43
42
|
startAnrWatchdog,
|
|
44
43
|
stopAnrWatchdog,
|
package/src/init.ts
CHANGED
|
@@ -33,10 +33,14 @@ export type InitOptions = {
|
|
|
33
33
|
* foreground (`AppState` → `active`), ends it on background.
|
|
34
34
|
* Drives crash-free rate. Set `false` to opt out. */
|
|
35
35
|
sessions?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
36
|
+
/** Capture a screenshot of the current screen on
|
|
37
|
+
* `captureException`. Opt-in. The capture runs through the
|
|
38
|
+
* bundled native module — no extra peer dep required since
|
|
39
|
+
* v0.7.3. To redact PII regions, register a mask query via
|
|
40
|
+
* `sentori.registerMaskQuery(() => string[])` and put
|
|
41
|
+
* `nativeID="..."` on the `<View>`s the SDK should black out.
|
|
42
|
+
* The image is webp q=70 / jpeg q=70 at 480 px max, < 100 KB
|
|
43
|
+
* typical. */
|
|
40
44
|
screenshot?: boolean;
|
|
41
45
|
/** Phase 46: record the last N steps (route changes, custom
|
|
42
46
|
* breadcrumbs) leading up to a crash. On `captureException`
|