@blipit/react-native 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.4.0
2
+
3
+ - Stuck screens and flows: `waitForReady` with `Blipit.reportReady()`, and `startFlow`, `flowStep` and `endFlow`. When the app never reaches its first usable screen, or a flow such as sign-in never finishes, Blipit opens a Stuck issue with the last step and the steps before it. Only time on screen counts; the time limits come from Blipit.
4
+
1
5
  ## 0.3.0
2
6
 
3
7
  - `<BlipitReporter showButton>` around your app and `showReport()` from your own menu open the bug reporter: Take a screenshot or Skip, then a full-screen editor with the tools above and below the image, pinch, two-finger pan and double-tap zoom up to 5x, pen, box and arrow marks, then a title, what happened and an optional email, and Send. Screenshots need `react-native-view-shot` (optional peer dependency); without it the report is sent as text.
package/README.md CHANGED
@@ -55,6 +55,34 @@ Blipit.showReport();
55
55
 
56
56
  The reporter asks first: Take a screenshot or Skip. The screenshot opens full screen with the tools above and below it; pinch or double-tap to zoom, mark the problem, then add a title and what happened and send. Without `react-native-view-shot` the report is sent as text. Reports arrive under Bug reports at app.blipit.io.
57
57
 
58
+ ## Stuck screens and flows
59
+
60
+ Some failures never crash: the splash screen keeps spinning, or a sign-in promise never settles. Tell Blipit when the app is ready and wrap the flows that must finish:
61
+
62
+ ```tsx
63
+ Blipit.init({ key: "<public key>", project: <project id>, waitForReady: true });
64
+
65
+ Blipit.reportReady();
66
+
67
+ Blipit.startFlow("sign-in");
68
+ Blipit.flowStep("sign-in", "google-picker");
69
+ Blipit.endFlow("sign-in");
70
+ ```
71
+
72
+ With `waitForReady: true`, call `Blipit.reportReady()` once the first usable screen shows, for example in the first screen's effect after its data loads.
73
+
74
+ If one does not finish in time, Blipit opens a **Stuck** issue with the flow, the last step, the screen when it is known, how long it waited and the steps before it. Only time on screen counts: while the app is in the background the clock stops, so a sign-in that sends people to a browser is not cut short. Blipit sets the time limits on its side and the SDK picks them up with its settings, so they can change without an app release. Nothing is decided before those settings arrive.
75
+
76
+ Call `startFlow` when the person starts the action (taps Continue with Google), not when the screen opens. `endFlow` covers every way out, including the person cancelling. Flow and step names are sent as you write them: use fixed names such as `sign-in` or `google-picker`, never emails, phone numbers or other personal data.
77
+
78
+ ## Store declarations
79
+
80
+ What to declare when you ship an app with Blipit:
81
+
82
+ - **Apple App Store**: the native crash library inside the package ships its own privacy manifest, and Blipit's JavaScript code uses no required-reason APIs. In App Store Connect, App Privacy, declare crash data, performance data and other diagnostic data under App Functionality, not linked, no tracking. Blipit uses no IDFA, no App Tracking Transparency prompt and no background modes. If you call `setUser` with an id or email, declare those as linked to the person.
83
+ - **Google Play**: in the Data safety form declare App info and performance, Crash logs and Diagnostics: collected, not shared, processed in transit with encryption, not optional, for App functionality and Analytics. Blipit adds no permissions, reads no Android ID, IMEI or advertising id, and starts no WorkManager job or foreground service. If you call `setUser`, also declare User IDs or Email address.
84
+ - **Huawei AppGallery**: the Android path needs neither Google Play services nor HMS Core. In your privacy statement, list crash and diagnostic data sent to Blipit (Louward Labs FZC LLC) for app stability, and the same items in the AppGallery Connect privacy section.
85
+
58
86
  ## Performance
59
87
 
60
88
  Pass `tracesSampleRate: 0.2` to `init` and screen loads and requests show up on the Performance page.
package/dist/index.cjs CHANGED
@@ -38,11 +38,15 @@ __export(index_exports, {
38
38
  captureMessage: () => import_react_native3.captureMessage,
39
39
  captureSecurity: () => captureSecurity,
40
40
  dsn: () => dsn,
41
+ endFlow: () => endFlow,
42
+ flowStep: () => flowStep,
41
43
  flush: () => import_react_native3.flush,
42
44
  init: () => init2,
45
+ reportReady: () => reportReady,
43
46
  setTag: () => import_react_native3.setTag,
44
47
  setUser: () => import_react_native3.setUser,
45
48
  showReport: () => showReport,
49
+ startFlow: () => startFlow,
46
50
  withIdentity: () => withIdentity,
47
51
  wrap: () => import_react_native3.wrap
48
52
  });
@@ -475,6 +479,13 @@ var ReportClient = class {
475
479
  if (!res.ok) throw new Error(`Blipit returned ${res.status}`);
476
480
  return text2;
477
481
  }
482
+ async settings() {
483
+ return JSON.parse(await this.call("/api/v1/feedback/settings", { method: "GET" }));
484
+ }
485
+ async event(body) {
486
+ const res = await this.fetcher(`${this.endpoint}/api/v1/events`, { method: "POST", headers: { "X-Blipit-Key": this.key, "Content-Type": "application/json" }, body: JSON.stringify(body) });
487
+ return res.ok || res.status >= 400 && res.status < 500 && res.status !== 408 && res.status !== 429;
488
+ }
478
489
  async send(body) {
479
490
  const json = JSON.parse(await this.call("/api/v1/feedback", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }));
480
491
  if (typeof json.upload_token !== "string") throw new Error("Blipit returned no upload token");
@@ -524,6 +535,141 @@ function zoomAround(zoom, pan, next, focal, view, image) {
524
535
  }
525
536
  var strokeFor = (image) => Math.max(4, image.width / 130);
526
537
 
538
+ // src/stuck.ts
539
+ var STARTUP = "startup";
540
+ function limitsFrom(value) {
541
+ const v = value;
542
+ if (!v || typeof v.startup_ms !== "number" || typeof v.flow_ms !== "number") return null;
543
+ return { startupMs: v.startup_ms, flowMs: v.flow_ms };
544
+ }
545
+ function cleanName(value, max) {
546
+ if (typeof value !== "string") return null;
547
+ const clean = value.replace(/\s+/g, " ").trim().slice(0, max);
548
+ return clean || null;
549
+ }
550
+ var FlowWatch = class {
551
+ open = /* @__PURE__ */ new Map();
552
+ foreground = false;
553
+ start(name, now) {
554
+ this.open.delete(name);
555
+ this.open.set(name, { step: null, spent: 0, since: this.foreground ? now : null });
556
+ }
557
+ step(name, step) {
558
+ const flow = this.open.get(name);
559
+ if (!flow) return false;
560
+ flow.step = step;
561
+ return true;
562
+ }
563
+ end(name) {
564
+ return this.open.delete(name);
565
+ }
566
+ get empty() {
567
+ return this.open.size === 0;
568
+ }
569
+ setForeground(on, now) {
570
+ if (on === this.foreground) return;
571
+ this.foreground = on;
572
+ for (const flow of this.open.values()) {
573
+ if (on) flow.since = now;
574
+ else {
575
+ flow.spent += now - (flow.since ?? now);
576
+ flow.since = null;
577
+ }
578
+ }
579
+ }
580
+ due(now, limits) {
581
+ if (!limits) return [];
582
+ const out = [];
583
+ for (const [name, flow] of this.open) {
584
+ const waited = flow.spent + (flow.since === null ? 0 : now - flow.since);
585
+ const limit = name === STARTUP ? limits.startupMs : limits.flowMs;
586
+ if (limit > 0 && waited >= limit) {
587
+ out.push({ name, step: flow.step, waitedMs: waited });
588
+ this.open.delete(name);
589
+ }
590
+ }
591
+ return out;
592
+ }
593
+ };
594
+ var hex = (n) => Array.from({ length: n }, () => Math.floor(Math.random() * 16).toString(16)).join("");
595
+ function stuckEvent(flow, trail, info, at = /* @__PURE__ */ new Date()) {
596
+ const kind = flow.name === STARTUP ? "startup" : "flow";
597
+ const stuck2 = { kind, waited_ms: Math.round(flow.waitedMs) };
598
+ if (kind === "flow") stuck2.flow = flow.name;
599
+ if (flow.step) stuck2.step = flow.step;
600
+ return {
601
+ event_id: hex(32),
602
+ timestamp: at.toISOString(),
603
+ platform: "react-native",
604
+ level: "warning",
605
+ message: `stuck: ${kind} ${kind === "flow" ? flow.name : kind}`,
606
+ stuck: stuck2,
607
+ contexts: { os: { name: info.os, version: info.osVersion } },
608
+ sdk: { name: "@blipit/react-native", version: info.version },
609
+ ...trail.length ? { breadcrumbs: trail } : {},
610
+ ...info.release ? { release: info.release } : {},
611
+ ...info.environment ? { environment: info.environment } : {}
612
+ };
613
+ }
614
+ function createStuck(transport, info, clock = Date.now) {
615
+ const watch = new FlowWatch();
616
+ const trail = [];
617
+ const pending = [];
618
+ let limits = null;
619
+ let fetchedAt = -Infinity;
620
+ let timer = null;
621
+ const crumb = (message) => {
622
+ trail.push({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), category: "custom", message });
623
+ if (trail.length > 30) trail.shift();
624
+ };
625
+ const fetchLimits = () => {
626
+ fetchedAt = clock();
627
+ transport.settings().then((s2) => limits = limitsFrom(s2?.stuck) ?? limits, () => void 0);
628
+ };
629
+ const flush2 = () => {
630
+ for (const body of pending.splice(0)) {
631
+ transport.event(body).then(
632
+ (ok) => !ok && pending.length < 10 && pending.push(body),
633
+ () => pending.length < 10 && pending.push(body)
634
+ );
635
+ }
636
+ };
637
+ const tick = () => {
638
+ if (!limits && clock() - fetchedAt > 6e4) fetchLimits();
639
+ for (const flow of watch.due(clock(), limits)) if (pending.length < 10) pending.push(stuckEvent(flow, trail.slice(), info));
640
+ flush2();
641
+ if (watch.empty && timer) {
642
+ clearInterval(timer);
643
+ timer = null;
644
+ }
645
+ };
646
+ const schedule = () => {
647
+ if (!timer) timer = setInterval(tick, 1e3);
648
+ };
649
+ return {
650
+ tick,
651
+ get limits() {
652
+ return limits;
653
+ },
654
+ setForeground(on) {
655
+ watch.setForeground(on, clock());
656
+ if (on) schedule();
657
+ },
658
+ start(name) {
659
+ if (!limits && clock() - fetchedAt > 6e4) fetchLimits();
660
+ watch.start(name, clock());
661
+ crumb(`flow ${name} started`);
662
+ schedule();
663
+ },
664
+ step(name, step) {
665
+ if (watch.step(name, step)) crumb(`flow ${name}: ${step}`);
666
+ },
667
+ end(name) {
668
+ if (watch.end(name)) crumb(`flow ${name} finished`);
669
+ }
670
+ };
671
+ }
672
+
527
673
  // src/reporter.tsx
528
674
  var import_react = require("react");
529
675
  var import_react_native = require("react-native");
@@ -953,7 +1099,7 @@ var s = import_react_native.StyleSheet.create({
953
1099
  // src/index.ts
954
1100
  var import_react_native3 = require("@sentry/react-native");
955
1101
  var DEFAULT_ENDPOINT = "https://in.blipit.io";
956
- var VERSION = "0.3.0";
1102
+ var VERSION = "0.4.0";
957
1103
  var PACKAGE = { name: "npm:@blipit/react-native", version: VERSION };
958
1104
  function withIdentity(user) {
959
1105
  return (event, hint) => {
@@ -974,7 +1120,7 @@ function dsn(key, project, endpoint = DEFAULT_ENDPOINT) {
974
1120
  var MISSING_KEY = "[blipit] Blipit.init got no key, so Blipit is off and nothing is sent. Pass the project's public key (app.blipit.io, Keys); with Expo, check that EXPO_PUBLIC_BLIPIT_KEY is set at build time.";
975
1121
  var MISSING_PROJECT = "[blipit] Blipit.init got no project id, so Blipit is off and nothing is sent. Pass project with the id from the project's Keys page at app.blipit.io.";
976
1122
  function init2(options) {
977
- const { key, publicKey, project, endpoint, ...rest } = options ?? {};
1123
+ const { key, publicKey, project, endpoint, waitForReady, ...rest } = options ?? {};
978
1124
  const k = (key ?? publicKey ?? "").trim();
979
1125
  if (!k) {
980
1126
  console.warn(MISSING_KEY);
@@ -991,9 +1137,37 @@ function init2(options) {
991
1137
  ...rest,
992
1138
  beforeSend: withIdentity(rest.beforeSend)
993
1139
  });
994
- configureReporter(new ReportClient(endpoint ?? DEFAULT_ENDPOINT, k), () => deviceContext(rest.release));
1140
+ const client = new ReportClient(endpoint ?? DEFAULT_ENDPOINT, k);
1141
+ configureReporter(client, () => deviceContext(rest.release));
1142
+ if (!stuck) {
1143
+ stuck = createStuck(client, { release: rest.release, environment: rest.environment, os: import_react_native2.Platform.OS, osVersion: String(import_react_native2.Platform.Version), version: VERSION });
1144
+ try {
1145
+ stuck.setForeground(import_react_native2.AppState.currentState !== "background");
1146
+ import_react_native2.AppState.addEventListener("change", (state) => stuck?.setForeground(state !== "background"));
1147
+ } catch {
1148
+ stuck.setForeground(true);
1149
+ }
1150
+ if (waitForReady) stuck.start(STARTUP);
1151
+ }
995
1152
  return true;
996
1153
  }
1154
+ var stuck = null;
1155
+ function reportReady() {
1156
+ stuck?.end(STARTUP);
1157
+ }
1158
+ function startFlow(name) {
1159
+ const flow = cleanName(name, 64);
1160
+ if (flow) stuck?.start(flow);
1161
+ }
1162
+ function flowStep(name, step) {
1163
+ const flow = cleanName(name, 64);
1164
+ const s2 = cleanName(step, 128);
1165
+ if (flow && s2) stuck?.step(flow, s2);
1166
+ }
1167
+ function endFlow(name) {
1168
+ const flow = cleanName(name, 64);
1169
+ if (flow) stuck?.end(flow);
1170
+ }
997
1171
  function deviceContext(release) {
998
1172
  const { width, height, scale } = import_react_native2.Dimensions.get("window");
999
1173
  let language = "";
@@ -1034,11 +1208,15 @@ function captureSecurity(kind, actor, details = {}) {
1034
1208
  captureMessage,
1035
1209
  captureSecurity,
1036
1210
  dsn,
1211
+ endFlow,
1212
+ flowStep,
1037
1213
  flush,
1038
1214
  init,
1215
+ reportReady,
1039
1216
  setTag,
1040
1217
  setUser,
1041
1218
  showReport,
1219
+ startFlow,
1042
1220
  withIdentity,
1043
1221
  wrap
1044
1222
  });
package/dist/index.d.cts CHANGED
@@ -10,7 +10,7 @@ declare function BlipitReporter({ children, showButton }: {
10
10
  }): react.JSX.Element;
11
11
 
12
12
  declare const DEFAULT_ENDPOINT = "https://in.blipit.io";
13
- declare const VERSION = "0.3.0";
13
+ declare const VERSION = "0.4.0";
14
14
  type BeforeSend = NonNullable<ReactNativeOptions["beforeSend"]>;
15
15
  declare function withIdentity(user?: BeforeSend): BeforeSend;
16
16
  interface BlipitOptions extends Omit<ReactNativeOptions, "dsn"> {
@@ -18,6 +18,7 @@ interface BlipitOptions extends Omit<ReactNativeOptions, "dsn"> {
18
18
  publicKey?: string;
19
19
  project: string | number;
20
20
  endpoint?: string;
21
+ waitForReady?: boolean;
21
22
  }
22
23
  interface SecurityDetails {
23
24
  outcome?: string;
@@ -28,6 +29,10 @@ interface SecurityDetails {
28
29
  }
29
30
  declare function dsn(key: string, project: string | number, endpoint?: string): string;
30
31
  declare function init(options: BlipitOptions): boolean;
32
+ declare function reportReady(): void;
33
+ declare function startFlow(name: string): void;
34
+ declare function flowStep(name: string, step: string): void;
35
+ declare function endFlow(name: string): void;
31
36
  declare function captureSecurity(kind: string, actor: string, details?: SecurityDetails): void;
32
37
 
33
- export { type BlipitOptions, BlipitReporter, DEFAULT_ENDPOINT, type SecurityDetails, VERSION, captureSecurity, dsn, init, showReport, withIdentity };
38
+ export { type BlipitOptions, BlipitReporter, DEFAULT_ENDPOINT, type SecurityDetails, VERSION, captureSecurity, dsn, endFlow, flowStep, init, reportReady, showReport, startFlow, withIdentity };
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@ declare function BlipitReporter({ children, showButton }: {
10
10
  }): react.JSX.Element;
11
11
 
12
12
  declare const DEFAULT_ENDPOINT = "https://in.blipit.io";
13
- declare const VERSION = "0.3.0";
13
+ declare const VERSION = "0.4.0";
14
14
  type BeforeSend = NonNullable<ReactNativeOptions["beforeSend"]>;
15
15
  declare function withIdentity(user?: BeforeSend): BeforeSend;
16
16
  interface BlipitOptions extends Omit<ReactNativeOptions, "dsn"> {
@@ -18,6 +18,7 @@ interface BlipitOptions extends Omit<ReactNativeOptions, "dsn"> {
18
18
  publicKey?: string;
19
19
  project: string | number;
20
20
  endpoint?: string;
21
+ waitForReady?: boolean;
21
22
  }
22
23
  interface SecurityDetails {
23
24
  outcome?: string;
@@ -28,6 +29,10 @@ interface SecurityDetails {
28
29
  }
29
30
  declare function dsn(key: string, project: string | number, endpoint?: string): string;
30
31
  declare function init(options: BlipitOptions): boolean;
32
+ declare function reportReady(): void;
33
+ declare function startFlow(name: string): void;
34
+ declare function flowStep(name: string, step: string): void;
35
+ declare function endFlow(name: string): void;
31
36
  declare function captureSecurity(kind: string, actor: string, details?: SecurityDetails): void;
32
37
 
33
- export { type BlipitOptions, BlipitReporter, DEFAULT_ENDPOINT, type SecurityDetails, VERSION, captureSecurity, dsn, init, showReport, withIdentity };
38
+ export { type BlipitOptions, BlipitReporter, DEFAULT_ENDPOINT, type SecurityDetails, VERSION, captureSecurity, dsn, endFlow, flowStep, init, reportReady, showReport, startFlow, withIdentity };
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
7
7
 
8
8
  // src/index.ts
9
9
  import * as Sentry from "@sentry/react-native";
10
- import { Dimensions, Platform as Platform2 } from "react-native";
10
+ import { AppState, Dimensions, Platform as Platform2 } from "react-native";
11
11
 
12
12
  // src/report-strings.ts
13
13
  var REPORT_STRINGS = {
@@ -434,6 +434,13 @@ var ReportClient = class {
434
434
  if (!res.ok) throw new Error(`Blipit returned ${res.status}`);
435
435
  return text2;
436
436
  }
437
+ async settings() {
438
+ return JSON.parse(await this.call("/api/v1/feedback/settings", { method: "GET" }));
439
+ }
440
+ async event(body) {
441
+ const res = await this.fetcher(`${this.endpoint}/api/v1/events`, { method: "POST", headers: { "X-Blipit-Key": this.key, "Content-Type": "application/json" }, body: JSON.stringify(body) });
442
+ return res.ok || res.status >= 400 && res.status < 500 && res.status !== 408 && res.status !== 429;
443
+ }
437
444
  async send(body) {
438
445
  const json = JSON.parse(await this.call("/api/v1/feedback", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }));
439
446
  if (typeof json.upload_token !== "string") throw new Error("Blipit returned no upload token");
@@ -483,6 +490,141 @@ function zoomAround(zoom, pan, next, focal, view, image) {
483
490
  }
484
491
  var strokeFor = (image) => Math.max(4, image.width / 130);
485
492
 
493
+ // src/stuck.ts
494
+ var STARTUP = "startup";
495
+ function limitsFrom(value) {
496
+ const v = value;
497
+ if (!v || typeof v.startup_ms !== "number" || typeof v.flow_ms !== "number") return null;
498
+ return { startupMs: v.startup_ms, flowMs: v.flow_ms };
499
+ }
500
+ function cleanName(value, max) {
501
+ if (typeof value !== "string") return null;
502
+ const clean = value.replace(/\s+/g, " ").trim().slice(0, max);
503
+ return clean || null;
504
+ }
505
+ var FlowWatch = class {
506
+ open = /* @__PURE__ */ new Map();
507
+ foreground = false;
508
+ start(name, now) {
509
+ this.open.delete(name);
510
+ this.open.set(name, { step: null, spent: 0, since: this.foreground ? now : null });
511
+ }
512
+ step(name, step) {
513
+ const flow = this.open.get(name);
514
+ if (!flow) return false;
515
+ flow.step = step;
516
+ return true;
517
+ }
518
+ end(name) {
519
+ return this.open.delete(name);
520
+ }
521
+ get empty() {
522
+ return this.open.size === 0;
523
+ }
524
+ setForeground(on, now) {
525
+ if (on === this.foreground) return;
526
+ this.foreground = on;
527
+ for (const flow of this.open.values()) {
528
+ if (on) flow.since = now;
529
+ else {
530
+ flow.spent += now - (flow.since ?? now);
531
+ flow.since = null;
532
+ }
533
+ }
534
+ }
535
+ due(now, limits) {
536
+ if (!limits) return [];
537
+ const out = [];
538
+ for (const [name, flow] of this.open) {
539
+ const waited = flow.spent + (flow.since === null ? 0 : now - flow.since);
540
+ const limit = name === STARTUP ? limits.startupMs : limits.flowMs;
541
+ if (limit > 0 && waited >= limit) {
542
+ out.push({ name, step: flow.step, waitedMs: waited });
543
+ this.open.delete(name);
544
+ }
545
+ }
546
+ return out;
547
+ }
548
+ };
549
+ var hex = (n) => Array.from({ length: n }, () => Math.floor(Math.random() * 16).toString(16)).join("");
550
+ function stuckEvent(flow, trail, info, at = /* @__PURE__ */ new Date()) {
551
+ const kind = flow.name === STARTUP ? "startup" : "flow";
552
+ const stuck2 = { kind, waited_ms: Math.round(flow.waitedMs) };
553
+ if (kind === "flow") stuck2.flow = flow.name;
554
+ if (flow.step) stuck2.step = flow.step;
555
+ return {
556
+ event_id: hex(32),
557
+ timestamp: at.toISOString(),
558
+ platform: "react-native",
559
+ level: "warning",
560
+ message: `stuck: ${kind} ${kind === "flow" ? flow.name : kind}`,
561
+ stuck: stuck2,
562
+ contexts: { os: { name: info.os, version: info.osVersion } },
563
+ sdk: { name: "@blipit/react-native", version: info.version },
564
+ ...trail.length ? { breadcrumbs: trail } : {},
565
+ ...info.release ? { release: info.release } : {},
566
+ ...info.environment ? { environment: info.environment } : {}
567
+ };
568
+ }
569
+ function createStuck(transport, info, clock = Date.now) {
570
+ const watch = new FlowWatch();
571
+ const trail = [];
572
+ const pending = [];
573
+ let limits = null;
574
+ let fetchedAt = -Infinity;
575
+ let timer = null;
576
+ const crumb = (message) => {
577
+ trail.push({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), category: "custom", message });
578
+ if (trail.length > 30) trail.shift();
579
+ };
580
+ const fetchLimits = () => {
581
+ fetchedAt = clock();
582
+ transport.settings().then((s2) => limits = limitsFrom(s2?.stuck) ?? limits, () => void 0);
583
+ };
584
+ const flush2 = () => {
585
+ for (const body of pending.splice(0)) {
586
+ transport.event(body).then(
587
+ (ok) => !ok && pending.length < 10 && pending.push(body),
588
+ () => pending.length < 10 && pending.push(body)
589
+ );
590
+ }
591
+ };
592
+ const tick = () => {
593
+ if (!limits && clock() - fetchedAt > 6e4) fetchLimits();
594
+ for (const flow of watch.due(clock(), limits)) if (pending.length < 10) pending.push(stuckEvent(flow, trail.slice(), info));
595
+ flush2();
596
+ if (watch.empty && timer) {
597
+ clearInterval(timer);
598
+ timer = null;
599
+ }
600
+ };
601
+ const schedule = () => {
602
+ if (!timer) timer = setInterval(tick, 1e3);
603
+ };
604
+ return {
605
+ tick,
606
+ get limits() {
607
+ return limits;
608
+ },
609
+ setForeground(on) {
610
+ watch.setForeground(on, clock());
611
+ if (on) schedule();
612
+ },
613
+ start(name) {
614
+ if (!limits && clock() - fetchedAt > 6e4) fetchLimits();
615
+ watch.start(name, clock());
616
+ crumb(`flow ${name} started`);
617
+ schedule();
618
+ },
619
+ step(name, step) {
620
+ if (watch.step(name, step)) crumb(`flow ${name}: ${step}`);
621
+ },
622
+ end(name) {
623
+ if (watch.end(name)) crumb(`flow ${name} finished`);
624
+ }
625
+ };
626
+ }
627
+
486
628
  // src/reporter.tsx
487
629
  import { useEffect, useMemo, useRef, useState } from "react";
488
630
  import {
@@ -928,7 +1070,7 @@ var s = StyleSheet.create({
928
1070
  // src/index.ts
929
1071
  import { captureException, captureMessage as captureMessage2, setUser, setTag, addBreadcrumb, flush, wrap } from "@sentry/react-native";
930
1072
  var DEFAULT_ENDPOINT = "https://in.blipit.io";
931
- var VERSION = "0.3.0";
1073
+ var VERSION = "0.4.0";
932
1074
  var PACKAGE = { name: "npm:@blipit/react-native", version: VERSION };
933
1075
  function withIdentity(user) {
934
1076
  return (event, hint) => {
@@ -949,7 +1091,7 @@ function dsn(key, project, endpoint = DEFAULT_ENDPOINT) {
949
1091
  var MISSING_KEY = "[blipit] Blipit.init got no key, so Blipit is off and nothing is sent. Pass the project's public key (app.blipit.io, Keys); with Expo, check that EXPO_PUBLIC_BLIPIT_KEY is set at build time.";
950
1092
  var MISSING_PROJECT = "[blipit] Blipit.init got no project id, so Blipit is off and nothing is sent. Pass project with the id from the project's Keys page at app.blipit.io.";
951
1093
  function init2(options) {
952
- const { key, publicKey, project, endpoint, ...rest } = options ?? {};
1094
+ const { key, publicKey, project, endpoint, waitForReady, ...rest } = options ?? {};
953
1095
  const k = (key ?? publicKey ?? "").trim();
954
1096
  if (!k) {
955
1097
  console.warn(MISSING_KEY);
@@ -966,9 +1108,37 @@ function init2(options) {
966
1108
  ...rest,
967
1109
  beforeSend: withIdentity(rest.beforeSend)
968
1110
  });
969
- configureReporter(new ReportClient(endpoint ?? DEFAULT_ENDPOINT, k), () => deviceContext(rest.release));
1111
+ const client = new ReportClient(endpoint ?? DEFAULT_ENDPOINT, k);
1112
+ configureReporter(client, () => deviceContext(rest.release));
1113
+ if (!stuck) {
1114
+ stuck = createStuck(client, { release: rest.release, environment: rest.environment, os: Platform2.OS, osVersion: String(Platform2.Version), version: VERSION });
1115
+ try {
1116
+ stuck.setForeground(AppState.currentState !== "background");
1117
+ AppState.addEventListener("change", (state) => stuck?.setForeground(state !== "background"));
1118
+ } catch {
1119
+ stuck.setForeground(true);
1120
+ }
1121
+ if (waitForReady) stuck.start(STARTUP);
1122
+ }
970
1123
  return true;
971
1124
  }
1125
+ var stuck = null;
1126
+ function reportReady() {
1127
+ stuck?.end(STARTUP);
1128
+ }
1129
+ function startFlow(name) {
1130
+ const flow = cleanName(name, 64);
1131
+ if (flow) stuck?.start(flow);
1132
+ }
1133
+ function flowStep(name, step) {
1134
+ const flow = cleanName(name, 64);
1135
+ const s2 = cleanName(step, 128);
1136
+ if (flow && s2) stuck?.step(flow, s2);
1137
+ }
1138
+ function endFlow(name) {
1139
+ const flow = cleanName(name, 64);
1140
+ if (flow) stuck?.end(flow);
1141
+ }
972
1142
  function deviceContext(release) {
973
1143
  const { width, height, scale } = Dimensions.get("window");
974
1144
  let language = "";
@@ -1008,11 +1178,15 @@ export {
1008
1178
  captureMessage2 as captureMessage,
1009
1179
  captureSecurity,
1010
1180
  dsn,
1181
+ endFlow,
1182
+ flowStep,
1011
1183
  flush,
1012
1184
  init2 as init,
1185
+ reportReady,
1013
1186
  setTag,
1014
1187
  setUser,
1015
1188
  showReport,
1189
+ startFlow,
1016
1190
  withIdentity,
1017
1191
  wrap
1018
1192
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blipit/react-native",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Blipit error monitoring for React Native and Expo. Know your app broke before your users tell you.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -61,6 +61,6 @@
61
61
  "scripts": {
62
62
  "build": "tsup src/index.ts --format esm,cjs --dts --clean --external react-native-view-shot",
63
63
  "typecheck": "tsc -p tsconfig.json --noEmit",
64
- "test": "node --experimental-strip-types --experimental-test-module-mocks --import ./test/tsx-hook.mjs --test test/init.test.ts test/report.test.ts"
64
+ "test": "node --experimental-strip-types --experimental-test-module-mocks --import ./test/tsx-hook.mjs --test test/init.test.ts test/report.test.ts test/stuck.test.ts"
65
65
  }
66
66
  }