yaver-feedback-react-native 0.8.7 → 0.8.9
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/README.md +23 -0
- package/dist/MachinePickerScreen.js +2 -2
- package/dist/YaverFeedback.js +178 -30
- package/dist/__tests__/AuthDevices.test.js +7 -7
- package/dist/__tests__/BlackBox.hotReload.test.d.ts +1 -0
- package/dist/__tests__/BlackBox.hotReload.test.js +204 -0
- package/dist/__tests__/P2PClient.test.js +56 -0
- package/dist/__tests__/YaverFeedback.test.js +9 -0
- package/dist/__tests__/types.test.js +2 -0
- package/dist/_core/constants.d.ts +6 -2
- package/dist/_core/constants.js +6 -2
- package/dist/types.d.ts +29 -0
- package/package.json +1 -1
- package/src/MachinePickerScreen.tsx +2 -2
- package/src/YaverFeedback.ts +174 -30
- package/src/__tests__/AuthDevices.test.ts +7 -7
- package/src/__tests__/BlackBox.hotReload.test.ts +226 -0
- package/src/__tests__/P2PClient.test.ts +70 -0
- package/src/__tests__/YaverFeedback.test.ts +11 -0
- package/src/__tests__/types.test.ts +2 -0
- package/src/_core/constants.ts +6 -2
- package/src/types.ts +29 -0
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Visual feedback SDK for Yaver. Lets testers and developers shake their phone and then keep a small quick-access icon on screen for hot reload, vibing, and screenshot & fix flows straight to a Yaver agent running on a dev machine.
|
|
4
4
|
|
|
5
|
+
Haptics ownership rule: when your app is paired with Yaver, app-level haptics should belong to Yaver Feedback alone. If the host app also fires its own `expo-haptics` calls, you risk duplicated tactile feedback and a larger native-module crash surface during guest/runtime flows.
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
@@ -618,6 +620,7 @@ YaverFeedback.init({
|
|
|
618
620
|
// Optional
|
|
619
621
|
agentUrl: 'http://192.168.1.10:18080', // Agent URL (auto-discovered if omitted)
|
|
620
622
|
trigger: 'shake', // 'shake' | 'floating-button' | 'manual'
|
|
623
|
+
disableShakeGesture: false, // Non-default: disable shake + promote quick icon to 'always'
|
|
621
624
|
enabled: true, // Default: __DEV__ (auto-disabled in production)
|
|
622
625
|
maxRecordingDuration: 120, // Max recording duration in seconds (default: 120)
|
|
623
626
|
feedbackMode: 'batch', // 'live' | 'narrated' | 'batch' (default: 'batch')
|
|
@@ -662,6 +665,26 @@ SDK yields shake handling to Yaver's native overlay — see the
|
|
|
662
665
|
YaverFeedback.init({ authToken, trigger: 'shake' });
|
|
663
666
|
```
|
|
664
667
|
|
|
668
|
+
### No-shake build option
|
|
669
|
+
|
|
670
|
+
If another surface owns motion / haptics and you want the SDK without shake detection, enable the non-default `disableShakeGesture` option:
|
|
671
|
+
|
|
672
|
+
```typescript
|
|
673
|
+
YaverFeedback.init({
|
|
674
|
+
authToken,
|
|
675
|
+
trigger: 'shake',
|
|
676
|
+
disableShakeGesture: true,
|
|
677
|
+
});
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
Effects:
|
|
681
|
+
|
|
682
|
+
- `ShakeDetector` is not started.
|
|
683
|
+
- If `quickIcon` was unset / `'auto'`, the SDK promotes it to `'always'`.
|
|
684
|
+
- The user opens feedback through the draggable quick icon or your own manual trigger.
|
|
685
|
+
|
|
686
|
+
This is useful when Yaver Feedback should remain the only haptic/shake owner and the host app should not bind its own motion-triggered entry point.
|
|
687
|
+
|
|
665
688
|
### Floating Button
|
|
666
689
|
|
|
667
690
|
A small draggable "Y" button overlays the app. Tap to open the feedback modal.
|
|
@@ -121,8 +121,8 @@ const YaverMachinePickerScreen = ({ token, currentDeviceId, onPick, onCancel, })
|
|
|
121
121
|
// yellows from phone↔backend clock skew around the 89-90 s mark.
|
|
122
122
|
//
|
|
123
123
|
// `runnerDown` intentionally does NOT flip the dot. That flag
|
|
124
|
-
// tracks whether the AI runner (claude-code
|
|
125
|
-
// healthy — a separate concern from "can I reach this machine?"
|
|
124
|
+
// tracks whether the AI runner (claude-code / codex / opencode)
|
|
125
|
+
// is healthy — a separate concern from "can I reach this machine?"
|
|
126
126
|
// Mobile app surfaces runner issues via a separate badge, not
|
|
127
127
|
// this dot. Picker's job is reachability, nothing more.
|
|
128
128
|
const effectivelyReachable = probe?.reachable === true;
|
package/dist/YaverFeedback.js
CHANGED
|
@@ -13,10 +13,13 @@ const preferences_1 = require("./preferences");
|
|
|
13
13
|
// (mobile/ios/Yaver/YaverInfo.{swift,m} + Android counterpart); a
|
|
14
14
|
// standalone app bundled by its own developer has no such module.
|
|
15
15
|
// When the SDK is loaded through Yaver's Hermes-push guest runtime we
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
// the
|
|
16
|
+
// run in HOST MODE: dormant by default (no shake detector, no auto
|
|
17
|
+
// BlackBox, no QuickActionIcon — Yaver's host shell owns those), but
|
|
18
|
+
// we DO register a DeviceEventEmitter listener so Yaver's overlay can
|
|
19
|
+
// flip the SDK live at runtime. When the user shakes inside the guest
|
|
20
|
+
// app and taps "Feedback" on the Yaver overlay, AppDelegate dispatches
|
|
21
|
+
// `yaverFeedback:startReport` into this bridge; the listener wakes the
|
|
22
|
+
// SDK and opens the modal in-place over the running guest UI.
|
|
20
23
|
function isRunningInsideYaverHost() {
|
|
21
24
|
try {
|
|
22
25
|
return !!react_native_1.NativeModules?.YaverInfo;
|
|
@@ -25,11 +28,108 @@ function isRunningInsideYaverHost() {
|
|
|
25
28
|
return false;
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
// by
|
|
31
|
-
//
|
|
32
|
-
|
|
31
|
+
// Two distinct compile-time modes for a guest app like sfmg / talos:
|
|
32
|
+
//
|
|
33
|
+
// YAVER_HOST_MODE — bundled by Yaver's agent (/dev/build-native) for
|
|
34
|
+
// loading inside Yaver mobile. SDK code is in the
|
|
35
|
+
// bundle but boots PASSIVE: no shake detector, no
|
|
36
|
+
// auto-BlackBox, no container UI. Yaver's host
|
|
37
|
+
// overlay owns the shake gesture; when the user
|
|
38
|
+
// taps "Feedback" on Yaver's overlay, AppDelegate
|
|
39
|
+
// dispatches yaverFeedback:hostActivate into this
|
|
40
|
+
// bridge and the SDK runtime-flips active for a
|
|
41
|
+
// single feedback session.
|
|
42
|
+
//
|
|
43
|
+
// YAVER_SDK_MODE — sfmg's own standalone TestFlight / Play Store
|
|
44
|
+
// build, with the Yaver SDK embedded. SDK boots
|
|
45
|
+
// active: shake → modal directly, no Yaver host
|
|
46
|
+
// involved. Default for normal `expo build`.
|
|
47
|
+
//
|
|
48
|
+
// Both can be forced at build time via process.env. When neither is
|
|
49
|
+
// set, fall back to runtime detection: if the YaverInfo native module
|
|
50
|
+
// exists (we're inside Yaver), assume HOST_MODE; else SDK_MODE. This
|
|
51
|
+
// keeps older bundles (built before the agent learned to set the env)
|
|
52
|
+
// working unchanged.
|
|
53
|
+
const YAVER_HOST_MODE_BUILD = (() => {
|
|
54
|
+
try {
|
|
55
|
+
const v = process.env?.YAVER_HOST_MODE;
|
|
56
|
+
return v === 'true' || v === '1' || v === true || v === 1;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
})();
|
|
62
|
+
const YAVER_SDK_MODE_BUILD = (() => {
|
|
63
|
+
try {
|
|
64
|
+
const v = process.env?.YAVER_SDK_MODE;
|
|
65
|
+
return v === 'true' || v === '1' || v === true || v === 1;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
})();
|
|
71
|
+
// Effective mode after considering build flags AND runtime detection.
|
|
72
|
+
const IS_HOST_MODE = YAVER_HOST_MODE_BUILD ||
|
|
73
|
+
(!YAVER_SDK_MODE_BUILD && isRunningInsideYaverHost());
|
|
74
|
+
// Tracks whether we've been runtime-activated by the host (sfmg-in-Yaver
|
|
75
|
+
// case). Independent of `enabled` so we can tell "host turned us on for
|
|
76
|
+
// one shot" apart from "developer toggled enabled programmatically".
|
|
77
|
+
let hostActivated = false;
|
|
78
|
+
// Host-activation listener. Always registered when in HOST mode so a
|
|
79
|
+
// Yaver overlay tap can wake the SDK even before the guest's
|
|
80
|
+
// YaverFeedback.init() runs. AppDelegate (mobile/ios/Yaver/AppDelegate.
|
|
81
|
+
// swift::handleFeedbackTap) sends `yaverFeedback:startReport` into the
|
|
82
|
+
// guest bridge when the user picks Feedback on the shake overlay.
|
|
83
|
+
//
|
|
84
|
+
// Activation flow:
|
|
85
|
+
// 1. Try Yaver's existing bearer (NativeModules.YaverInfo.
|
|
86
|
+
// inheritedAuthToken, populated by Yaver mobile's auth.ts on
|
|
87
|
+
// sign-in). Validate against /auth/validate before trusting.
|
|
88
|
+
// 2. If valid: setAuthToken + open feedback modal in-place (the
|
|
89
|
+
// modal already supports hot reload, screenshot, vibing chat).
|
|
90
|
+
// 3. If missing or invalid: open the SDK's own login screen.
|
|
91
|
+
if (IS_HOST_MODE) {
|
|
92
|
+
try {
|
|
93
|
+
const { DeviceEventEmitter } = require('react-native');
|
|
94
|
+
DeviceEventEmitter.addListener('yaverFeedback:startReport', () => {
|
|
95
|
+
hostActivated = true;
|
|
96
|
+
enabled = true;
|
|
97
|
+
void (async () => {
|
|
98
|
+
const yi = react_native_1.NativeModules?.YaverInfo;
|
|
99
|
+
const inheritedToken = String(yi?.inheritedAuthToken || '').trim();
|
|
100
|
+
const inheritedAgent = String(yi?.inheritedAgentUrl || '').trim();
|
|
101
|
+
const inheritedDevice = String(yi?.inheritedDeviceId || '').trim();
|
|
102
|
+
if (inheritedToken) {
|
|
103
|
+
// Lazy-import auth.ts so module load doesn't drag the auth
|
|
104
|
+
// network code into the active set when the SDK is dormant.
|
|
105
|
+
const { validateToken } = require('./auth');
|
|
106
|
+
const user = await validateToken(inheritedToken).catch(() => null);
|
|
107
|
+
if (user) {
|
|
108
|
+
// Seed config + connect the SDK to the host's auth.
|
|
109
|
+
if (!config) {
|
|
110
|
+
YaverFeedback.init({
|
|
111
|
+
authToken: inheritedToken,
|
|
112
|
+
agentUrl: inheritedAgent || undefined,
|
|
113
|
+
preferredDeviceId: inheritedDevice || undefined,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
await YaverFeedback.setAuthToken(inheritedToken);
|
|
117
|
+
await YaverFeedback.startReport();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// No token, or token invalid — fall through to the SDK's own
|
|
122
|
+
// login screen. The user picks an OAuth provider; on success
|
|
123
|
+
// the modal continues with the new token.
|
|
124
|
+
if (!config) {
|
|
125
|
+
YaverFeedback.init({});
|
|
126
|
+
}
|
|
127
|
+
YaverFeedback.showLogin();
|
|
128
|
+
})();
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
catch { /* react-native unavailable in jsdom unit tests */ }
|
|
132
|
+
}
|
|
33
133
|
let config = null;
|
|
34
134
|
let enabled = false;
|
|
35
135
|
let p2pClient = null;
|
|
@@ -102,17 +202,37 @@ class YaverFeedback {
|
|
|
102
202
|
* via `YaverDiscovery` on the first `startReport()` call.
|
|
103
203
|
*/
|
|
104
204
|
static init(cfg) {
|
|
105
|
-
if (YAVER_HOST_SUPPRESS) {
|
|
106
|
-
// Running inside Yaver's super-host — yield to Yaver's native UX.
|
|
107
|
-
enabled = false;
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
205
|
config = {
|
|
111
206
|
trigger: 'shake',
|
|
112
207
|
maxRecordingDuration: 120,
|
|
113
208
|
autoLogin: true,
|
|
114
209
|
...cfg,
|
|
115
210
|
};
|
|
211
|
+
if (IS_HOST_MODE) {
|
|
212
|
+
// sfmg / talos / etc. running inside Yaver mobile (compile-time
|
|
213
|
+
// YAVER_HOST_MODE or runtime-detected). Store config so a later
|
|
214
|
+
// host activation (yaverFeedback:startReport from AppDelegate)
|
|
215
|
+
// can open the modal — but skip the side effects Yaver's host
|
|
216
|
+
// shell owns: shake detector, auto-BlackBox, QuickActionIcon.
|
|
217
|
+
enabled = false;
|
|
218
|
+
// Configure auth endpoints + strict-native-auth even in passive
|
|
219
|
+
// mode so a host-activated session uses the same login routing
|
|
220
|
+
// the standalone path would.
|
|
221
|
+
(0, auth_1.configureAuthEndpoints)({
|
|
222
|
+
convexSiteUrl: cfg.authConvexSiteUrl,
|
|
223
|
+
webBaseUrl: cfg.authWebBaseUrl,
|
|
224
|
+
});
|
|
225
|
+
(0, auth_1.setStrictNativeAuth)(cfg.strictNativeAuth === true);
|
|
226
|
+
if (!config.convexUrl) {
|
|
227
|
+
config.convexUrl = cfg.authConvexSiteUrl ?? auth_1.DEFAULT_CONVEX_SITE_URL;
|
|
228
|
+
}
|
|
229
|
+
maxErrors = cfg.maxCapturedErrors ?? 5;
|
|
230
|
+
errorBuffer = [];
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (config.disableShakeGesture && (!config.quickIcon || config.quickIcon === 'auto')) {
|
|
234
|
+
config.quickIcon = 'always';
|
|
235
|
+
}
|
|
116
236
|
firstShakeFired = false;
|
|
117
237
|
// Route the in-SDK login screen to prod yaver.io by default; callers may
|
|
118
238
|
// override for staging via authConvexSiteUrl / authWebBaseUrl.
|
|
@@ -129,12 +249,18 @@ class YaverFeedback {
|
|
|
129
249
|
if (!config.convexUrl) {
|
|
130
250
|
config.convexUrl = cfg.authConvexSiteUrl ?? auth_1.DEFAULT_CONVEX_SITE_URL;
|
|
131
251
|
}
|
|
132
|
-
// Default: enabled only in dev
|
|
252
|
+
// Default: enabled. Pre-0.8.8 the SDK only enabled shake in dev
|
|
253
|
+
// builds (`__DEV__`), but apps that bundle the SDK explicitly *want*
|
|
254
|
+
// shake to work in TestFlight / Play Store builds — that's the
|
|
255
|
+
// primary use case (a tester finds a bug in a release build and
|
|
256
|
+
// shakes to report it). Dev builds get shake too. Apps that want
|
|
257
|
+
// to disable shake pass `enabled: false` (or
|
|
258
|
+
// `disableShakeGesture: true` for finer-grained control).
|
|
133
259
|
if (cfg.enabled !== undefined) {
|
|
134
260
|
enabled = cfg.enabled;
|
|
135
261
|
}
|
|
136
262
|
else {
|
|
137
|
-
enabled =
|
|
263
|
+
enabled = !cfg.disableShakeGesture;
|
|
138
264
|
}
|
|
139
265
|
// Hydrate cached auth token + preferred device from AsyncStorage so the
|
|
140
266
|
// SDK reconnects silently on subsequent launches. If autoLogin is false
|
|
@@ -165,7 +291,7 @@ class YaverFeedback {
|
|
|
165
291
|
shakeDetector.stop();
|
|
166
292
|
shakeDetector = null;
|
|
167
293
|
}
|
|
168
|
-
if (enabled && config.trigger === 'shake') {
|
|
294
|
+
if (enabled && config.trigger === 'shake' && !config.disableShakeGesture) {
|
|
169
295
|
shakeDetector = new ShakeDetector_1.ShakeDetector();
|
|
170
296
|
shakeDetector.start(() => {
|
|
171
297
|
YaverFeedback.notifyShake();
|
|
@@ -226,18 +352,40 @@ class YaverFeedback {
|
|
|
226
352
|
});
|
|
227
353
|
}
|
|
228
354
|
});
|
|
229
|
-
//
|
|
230
|
-
//
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
// the SSE channel retried with
|
|
234
|
-
//
|
|
235
|
-
//
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
//
|
|
355
|
+
// BlackBox auto-start (0.8.8+).
|
|
356
|
+
//
|
|
357
|
+
// 0.7.6 auto-started BlackBox immediately, which produced a
|
|
358
|
+
// Hermes rope-string SIGSEGV on iOS 18.3.1 when the agent was in
|
|
359
|
+
// bootstrap / needs-auth mode: the SSE channel retried with
|
|
360
|
+
// exponential backoff on 401s, generating a tight string-concat
|
|
361
|
+
// + JSON-parse loop that collided with react-native-view-shot's
|
|
362
|
+
// internal string handling during Screenshot & Fix. We rolled it
|
|
363
|
+
// back to manual-start (host calls BlackBox.start() after auth).
|
|
364
|
+
//
|
|
365
|
+
// The fix that lets us auto-start safely now:
|
|
366
|
+
// 1. Defer the start by 500ms so init() returns, the JS bridge
|
|
367
|
+
// settles, and any first-launch auth-token round trip on
|
|
368
|
+
// another thread completes before SSE opens.
|
|
369
|
+
// 2. Only start when we have BOTH an agentUrl AND an authToken
|
|
370
|
+
// — without the token, the connect() call would 401 and we'd
|
|
371
|
+
// reproduce the original loop.
|
|
372
|
+
// 3. Caller can opt out with cfg.autoStartBlackBox = false.
|
|
373
|
+
//
|
|
374
|
+
// SFMG used to call BlackBox.start() inside YaverFeedbackWidget
|
|
375
|
+
// after auth — that path still works (start() is idempotent), so
|
|
376
|
+
// upgrading SDK without removing the manual call is safe.
|
|
377
|
+
if (cfg.autoStartBlackBox !== false) {
|
|
378
|
+
setTimeout(() => {
|
|
379
|
+
if (config?.agentUrl && (config?.authToken || p2pAuthToken)) {
|
|
380
|
+
try {
|
|
381
|
+
BlackBox_1.BlackBox.start();
|
|
382
|
+
}
|
|
383
|
+
catch (err) {
|
|
384
|
+
console.warn('[YaverFeedback] BlackBox auto-start failed:', err);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}, 500);
|
|
388
|
+
}
|
|
241
389
|
}
|
|
242
390
|
// NOTE: We intentionally do NOT hook ErrorUtils.setGlobalHandler().
|
|
243
391
|
// Sentry, Crashlytics, Bugsnag, and other tools all compete for that
|
|
@@ -552,7 +700,7 @@ class YaverFeedback {
|
|
|
552
700
|
BlackBox_1.BlackBox.start(); // restart with previous config
|
|
553
701
|
}
|
|
554
702
|
// Restart shake detector if trigger is 'shake'
|
|
555
|
-
if (config?.trigger === 'shake' && !shakeDetector) {
|
|
703
|
+
if (config?.trigger === 'shake' && !config?.disableShakeGesture && !shakeDetector) {
|
|
556
704
|
shakeDetector = new ShakeDetector_1.ShakeDetector();
|
|
557
705
|
shakeDetector.start(() => {
|
|
558
706
|
YaverFeedback.notifyShake();
|
|
@@ -29,10 +29,10 @@ describe('auth device listing', () => {
|
|
|
29
29
|
platform: 'linux',
|
|
30
30
|
isOnline: true,
|
|
31
31
|
isGuest: true,
|
|
32
|
-
hostName: '
|
|
33
|
-
hostEmail: '
|
|
32
|
+
hostName: 'Host User',
|
|
33
|
+
hostEmail: 'host@example.com',
|
|
34
34
|
accessScope: 'shared-scoped',
|
|
35
|
-
quicHost: '
|
|
35
|
+
quicHost: '198.51.100.20',
|
|
36
36
|
quicPort: 18080,
|
|
37
37
|
lastHeartbeat: 456,
|
|
38
38
|
},
|
|
@@ -49,7 +49,7 @@ describe('auth device listing', () => {
|
|
|
49
49
|
expect(result.shared[0]).toMatchObject({
|
|
50
50
|
deviceId: 'guest-1',
|
|
51
51
|
isGuest: true,
|
|
52
|
-
hostEmail: '
|
|
52
|
+
hostEmail: 'host@example.com',
|
|
53
53
|
accessScope: 'shared-scoped',
|
|
54
54
|
});
|
|
55
55
|
});
|
|
@@ -64,10 +64,10 @@ describe('auth device listing', () => {
|
|
|
64
64
|
platform: 'linux',
|
|
65
65
|
isOnline: true,
|
|
66
66
|
isGuest: true,
|
|
67
|
-
hostName: '
|
|
68
|
-
hostEmail: '
|
|
67
|
+
hostName: 'Host User',
|
|
68
|
+
hostEmail: 'host@example.com',
|
|
69
69
|
accessScope: 'shared-scoped',
|
|
70
|
-
quicHost: '
|
|
70
|
+
quicHost: '198.51.100.20',
|
|
71
71
|
quicPort: 18080,
|
|
72
72
|
lastHeartbeat: 789,
|
|
73
73
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Hot-reload command-channel coverage for BlackBox.
|
|
3
|
+
//
|
|
4
|
+
// The agent uses BlackBox's SSE channel as a back-channel to push
|
|
5
|
+
// "reload" / "reload_bundle" commands into a running guest app
|
|
6
|
+
// (see desktop/agent/blackbox.go::BroadcastCommand). This test
|
|
7
|
+
// pins the SDK's contract:
|
|
8
|
+
//
|
|
9
|
+
// 1. onCommand(handler) registers a handler and returns an
|
|
10
|
+
// unsubscribe function that actually unsubscribes.
|
|
11
|
+
// 2. start() opens the SSE command-stream against the agent
|
|
12
|
+
// with the proper URL + headers.
|
|
13
|
+
// 3. When the SSE stream delivers a JSON message of the form
|
|
14
|
+
// {type:"command", command:{command:"reload", data:...}},
|
|
15
|
+
// the registered handler fires with the inner command.
|
|
16
|
+
// 4. start() also schedules the periodic flush — proving start
|
|
17
|
+
// is idempotent over multiple calls.
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
const BlackBox_1 = require("../BlackBox");
|
|
20
|
+
const YaverFeedback_1 = require("../YaverFeedback");
|
|
21
|
+
jest.mock('react-native', () => ({
|
|
22
|
+
Platform: { OS: 'ios' },
|
|
23
|
+
}));
|
|
24
|
+
// Drive Date.now / setTimeout deterministically.
|
|
25
|
+
jest.useFakeTimers();
|
|
26
|
+
const mockFetch = jest.fn();
|
|
27
|
+
global.fetch = mockFetch;
|
|
28
|
+
class MockAbortController {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.signal = { aborted: false };
|
|
31
|
+
this.abort = jest.fn(() => {
|
|
32
|
+
this.signal.aborted = true;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
global.AbortController = MockAbortController;
|
|
37
|
+
// Helper to build an SSE streaming body.
|
|
38
|
+
function sseBody(messages) {
|
|
39
|
+
const enc = new TextEncoder();
|
|
40
|
+
const chunks = messages.map((m) => `data: ${JSON.stringify(m)}\n\n`);
|
|
41
|
+
return new ReadableStream({
|
|
42
|
+
start(controller) {
|
|
43
|
+
for (const c of chunks)
|
|
44
|
+
controller.enqueue(enc.encode(c));
|
|
45
|
+
controller.close();
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
jest.clearAllMocks();
|
|
51
|
+
// Default: every POST (events) and the SSE GET both succeed.
|
|
52
|
+
mockFetch.mockImplementation((url) => {
|
|
53
|
+
if (url.includes('/blackbox/command-stream')) {
|
|
54
|
+
return Promise.resolve({
|
|
55
|
+
ok: true,
|
|
56
|
+
body: sseBody([]),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return Promise.resolve({
|
|
60
|
+
ok: true,
|
|
61
|
+
json: () => Promise.resolve({}),
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
YaverFeedback_1.YaverFeedback.init({
|
|
65
|
+
agentUrl: 'http://localhost:18080',
|
|
66
|
+
authToken: 'tok',
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
afterEach(() => {
|
|
70
|
+
BlackBox_1.BlackBox.stop();
|
|
71
|
+
});
|
|
72
|
+
describe('BlackBox hot-reload command channel', () => {
|
|
73
|
+
it('onCommand returns an unsubscribe that removes the handler', () => {
|
|
74
|
+
const a = jest.fn();
|
|
75
|
+
const b = jest.fn();
|
|
76
|
+
const offA = BlackBox_1.BlackBox.onCommand(a);
|
|
77
|
+
const offB = BlackBox_1.BlackBox.onCommand(b);
|
|
78
|
+
// Both subscribed — calling internal dispatch directly via the
|
|
79
|
+
// public surface isn't easy without SSE mockery, but
|
|
80
|
+
// deregistering should still leave only `b` registered after
|
|
81
|
+
// offA(), then no handlers after offB().
|
|
82
|
+
offA();
|
|
83
|
+
offB();
|
|
84
|
+
// Re-subscribe and confirm subscription returns a fresh unsub.
|
|
85
|
+
const offC = BlackBox_1.BlackBox.onCommand(jest.fn());
|
|
86
|
+
expect(typeof offC).toBe('function');
|
|
87
|
+
offC();
|
|
88
|
+
});
|
|
89
|
+
it('start() opens SSE against /blackbox/command-stream with bearer + device headers', async () => {
|
|
90
|
+
BlackBox_1.BlackBox.start({ deviceId: 'dev-abc', appName: 'sfmg' });
|
|
91
|
+
// Allow the async fetch in connectSSE to fire.
|
|
92
|
+
await Promise.resolve();
|
|
93
|
+
await Promise.resolve();
|
|
94
|
+
const sseCall = mockFetch.mock.calls.find(([url]) => String(url).includes('/blackbox/command-stream'));
|
|
95
|
+
expect(sseCall).toBeDefined();
|
|
96
|
+
const [url, init] = sseCall;
|
|
97
|
+
expect(String(url)).toContain('http://localhost:18080/blackbox/command-stream');
|
|
98
|
+
expect(String(url)).toContain('device=dev-abc');
|
|
99
|
+
expect(init.headers).toEqual(expect.objectContaining({
|
|
100
|
+
Authorization: 'Bearer tok',
|
|
101
|
+
Accept: 'text/event-stream',
|
|
102
|
+
'X-Device-ID': 'dev-abc',
|
|
103
|
+
'X-App-Name': 'sfmg',
|
|
104
|
+
}));
|
|
105
|
+
});
|
|
106
|
+
it('dispatches a {type:"command", command:{command:"reload"}} SSE frame to handlers', async () => {
|
|
107
|
+
// SSE body delivers one reload command, then closes.
|
|
108
|
+
mockFetch.mockImplementation((url) => {
|
|
109
|
+
if (url.includes('/blackbox/command-stream')) {
|
|
110
|
+
return Promise.resolve({
|
|
111
|
+
ok: true,
|
|
112
|
+
body: sseBody([
|
|
113
|
+
{ type: 'command', command: { command: 'reload', data: {} } },
|
|
114
|
+
]),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({}) });
|
|
118
|
+
});
|
|
119
|
+
const seen = [];
|
|
120
|
+
BlackBox_1.BlackBox.onCommand((cmd) => seen.push(cmd));
|
|
121
|
+
BlackBox_1.BlackBox.start({ deviceId: 'dev-1', appName: 'sfmg' });
|
|
122
|
+
// Drain the microtask + reader queue. The reader is async but
|
|
123
|
+
// the body is fully buffered + the stream closes immediately,
|
|
124
|
+
// so a few microtask flushes are enough.
|
|
125
|
+
for (let i = 0; i < 10; i++)
|
|
126
|
+
await Promise.resolve();
|
|
127
|
+
expect(seen).toEqual([
|
|
128
|
+
expect.objectContaining({ command: 'reload', data: {} }),
|
|
129
|
+
]);
|
|
130
|
+
});
|
|
131
|
+
it('dispatches a reload_bundle command (carries bundleUrl payload)', async () => {
|
|
132
|
+
mockFetch.mockImplementation((url) => {
|
|
133
|
+
if (url.includes('/blackbox/command-stream')) {
|
|
134
|
+
return Promise.resolve({
|
|
135
|
+
ok: true,
|
|
136
|
+
body: sseBody([
|
|
137
|
+
{
|
|
138
|
+
type: 'command',
|
|
139
|
+
command: {
|
|
140
|
+
command: 'reload_bundle',
|
|
141
|
+
data: { bundleUrl: '/dev/native-bundle' },
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
]),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({}) });
|
|
148
|
+
});
|
|
149
|
+
const seen = [];
|
|
150
|
+
BlackBox_1.BlackBox.onCommand((cmd) => seen.push(cmd));
|
|
151
|
+
BlackBox_1.BlackBox.start({ deviceId: 'dev-1', appName: 'sfmg' });
|
|
152
|
+
for (let i = 0; i < 10; i++)
|
|
153
|
+
await Promise.resolve();
|
|
154
|
+
expect(seen).toEqual([
|
|
155
|
+
expect.objectContaining({
|
|
156
|
+
command: 'reload_bundle',
|
|
157
|
+
data: expect.objectContaining({ bundleUrl: '/dev/native-bundle' }),
|
|
158
|
+
}),
|
|
159
|
+
]);
|
|
160
|
+
});
|
|
161
|
+
it('handler exception does not break sibling handlers', async () => {
|
|
162
|
+
mockFetch.mockImplementation((url) => {
|
|
163
|
+
if (url.includes('/blackbox/command-stream')) {
|
|
164
|
+
return Promise.resolve({
|
|
165
|
+
ok: true,
|
|
166
|
+
body: sseBody([
|
|
167
|
+
{ type: 'command', command: { command: 'reload' } },
|
|
168
|
+
]),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({}) });
|
|
172
|
+
});
|
|
173
|
+
const sibling = jest.fn();
|
|
174
|
+
BlackBox_1.BlackBox.onCommand(() => {
|
|
175
|
+
throw new Error('caller bug — should not break the dispatch loop');
|
|
176
|
+
});
|
|
177
|
+
BlackBox_1.BlackBox.onCommand(sibling);
|
|
178
|
+
BlackBox_1.BlackBox.start({ deviceId: 'dev-1', appName: 'sfmg' });
|
|
179
|
+
for (let i = 0; i < 10; i++)
|
|
180
|
+
await Promise.resolve();
|
|
181
|
+
expect(sibling).toHaveBeenCalledWith(expect.objectContaining({ command: 'reload' }));
|
|
182
|
+
});
|
|
183
|
+
it('ignores non-command SSE frames (events/log/whatever)', async () => {
|
|
184
|
+
mockFetch.mockImplementation((url) => {
|
|
185
|
+
if (url.includes('/blackbox/command-stream')) {
|
|
186
|
+
return Promise.resolve({
|
|
187
|
+
ok: true,
|
|
188
|
+
body: sseBody([
|
|
189
|
+
{ type: 'log', logLine: 'hi' },
|
|
190
|
+
{ type: 'lifecycle', message: 'started' },
|
|
191
|
+
{ ping: 1 },
|
|
192
|
+
]),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve({}) });
|
|
196
|
+
});
|
|
197
|
+
const handler = jest.fn();
|
|
198
|
+
BlackBox_1.BlackBox.onCommand(handler);
|
|
199
|
+
BlackBox_1.BlackBox.start({ deviceId: 'dev-1', appName: 'sfmg' });
|
|
200
|
+
for (let i = 0; i < 10; i++)
|
|
201
|
+
await Promise.resolve();
|
|
202
|
+
expect(handler).not.toHaveBeenCalled();
|
|
203
|
+
});
|
|
204
|
+
});
|
|
@@ -195,5 +195,61 @@ describe('P2PClient', () => {
|
|
|
195
195
|
message: 'Reload request acknowledged. Agent is rebuilding the bundle.',
|
|
196
196
|
}));
|
|
197
197
|
});
|
|
198
|
+
it('dev mode hits /dev/reload with bearer auth', async () => {
|
|
199
|
+
mockFetch.mockResolvedValue({
|
|
200
|
+
ok: true,
|
|
201
|
+
json: () => Promise.resolve({ ok: true }),
|
|
202
|
+
});
|
|
203
|
+
const client = new P2PClient_1.P2PClient('http://localhost:18080', 'tok');
|
|
204
|
+
await client.reloadApp('dev');
|
|
205
|
+
expect(mockFetch).toHaveBeenCalledWith('http://localhost:18080/dev/reload', expect.objectContaining({
|
|
206
|
+
method: 'POST',
|
|
207
|
+
headers: expect.objectContaining({ Authorization: 'Bearer tok' }),
|
|
208
|
+
}));
|
|
209
|
+
});
|
|
210
|
+
it('bundle mode hits /dev/reload-app with mode + projectName in body', async () => {
|
|
211
|
+
mockFetch.mockResolvedValue({
|
|
212
|
+
ok: true,
|
|
213
|
+
json: () => Promise.resolve({ ok: true }),
|
|
214
|
+
});
|
|
215
|
+
const client = new P2PClient_1.P2PClient('http://localhost:18080', 'tok');
|
|
216
|
+
await client.reloadApp('bundle', { projectName: 'sfmg' });
|
|
217
|
+
const [url, init] = mockFetch.mock.calls[0];
|
|
218
|
+
expect(url).toBe('http://localhost:18080/dev/reload-app');
|
|
219
|
+
expect(init.method).toBe('POST');
|
|
220
|
+
expect(JSON.parse(init.body)).toEqual(expect.objectContaining({ mode: 'bundle', projectName: 'sfmg' }));
|
|
221
|
+
expect(init.headers).toEqual(expect.objectContaining({
|
|
222
|
+
Authorization: 'Bearer tok',
|
|
223
|
+
'Content-Type': 'application/json',
|
|
224
|
+
}));
|
|
225
|
+
});
|
|
226
|
+
it('dev mode falls back to /dev/reload-app when /dev/reload 4xxs', async () => {
|
|
227
|
+
// First call: /dev/reload 404. Second: /dev/reload-app 200.
|
|
228
|
+
mockFetch
|
|
229
|
+
.mockResolvedValueOnce({ ok: false, status: 404, json: () => Promise.resolve({}) })
|
|
230
|
+
.mockResolvedValueOnce({ ok: true, json: () => Promise.resolve({ ok: true }) });
|
|
231
|
+
const client = new P2PClient_1.P2PClient('http://localhost:18080', 'tok');
|
|
232
|
+
const result = await client.reloadApp('dev', { projectName: 'sfmg' });
|
|
233
|
+
expect(mockFetch).toHaveBeenCalledTimes(2);
|
|
234
|
+
expect(mockFetch.mock.calls[0][0]).toBe('http://localhost:18080/dev/reload');
|
|
235
|
+
expect(mockFetch.mock.calls[1][0]).toBe('http://localhost:18080/dev/reload-app');
|
|
236
|
+
expect(result.ok).toBe(true);
|
|
237
|
+
});
|
|
238
|
+
it('surfaces nativeChangesDetected so the host can prompt for rebuild', async () => {
|
|
239
|
+
mockFetch.mockResolvedValue({
|
|
240
|
+
ok: true,
|
|
241
|
+
json: () => Promise.resolve({
|
|
242
|
+
ok: true,
|
|
243
|
+
nativeChangesDetected: true,
|
|
244
|
+
changeClass: 'native_required',
|
|
245
|
+
}),
|
|
246
|
+
});
|
|
247
|
+
const client = new P2PClient_1.P2PClient('http://localhost:18080', 'tok');
|
|
248
|
+
const result = await client.reloadApp('dev');
|
|
249
|
+
expect(result.nativeChangesDetected).toBe(true);
|
|
250
|
+
expect(result.changeClass).toBe('native_required');
|
|
251
|
+
// Caller-visible message must distinguish native-required from JS-only.
|
|
252
|
+
expect(result.message).toMatch(/native|rebuild/i);
|
|
253
|
+
});
|
|
198
254
|
});
|
|
199
255
|
});
|
|
@@ -76,6 +76,15 @@ describe('YaverFeedback', () => {
|
|
|
76
76
|
expect(cfg.maxRecordingDuration).toBe(60);
|
|
77
77
|
expect(cfg.strictNativeAuth).toBe(true);
|
|
78
78
|
});
|
|
79
|
+
it('promotes quick icon to always when shake is disabled', () => {
|
|
80
|
+
YaverFeedback_1.YaverFeedback.init({
|
|
81
|
+
authToken: 'tok',
|
|
82
|
+
disableShakeGesture: true,
|
|
83
|
+
});
|
|
84
|
+
const cfg = YaverFeedback_1.YaverFeedback.getConfig();
|
|
85
|
+
expect(cfg.disableShakeGesture).toBe(true);
|
|
86
|
+
expect(cfg.quickIcon).toBe('always');
|
|
87
|
+
});
|
|
79
88
|
it('with enabled=false sets enabled to false', () => {
|
|
80
89
|
YaverFeedback_1.YaverFeedback.init({
|
|
81
90
|
authToken: 'tok',
|
|
@@ -17,11 +17,13 @@ describe('React Native SDK types', () => {
|
|
|
17
17
|
authToken: 'tok',
|
|
18
18
|
agentUrl: 'http://192.168.1.10:18080',
|
|
19
19
|
trigger: 'shake',
|
|
20
|
+
disableShakeGesture: true,
|
|
20
21
|
enabled: true,
|
|
21
22
|
maxRecordingDuration: 60,
|
|
22
23
|
strictNativeAuth: true,
|
|
23
24
|
};
|
|
24
25
|
expect(config.trigger).toBe('shake');
|
|
26
|
+
expect(config.disableShakeGesture).toBe(true);
|
|
25
27
|
expect(config.strictNativeAuth).toBe(true);
|
|
26
28
|
});
|
|
27
29
|
it('accepts all trigger types', () => {
|