@blipit/react-native 0.5.0 → 0.6.1

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/dist/index.js CHANGED
@@ -6,11 +6,95 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  });
7
7
 
8
8
  // src/index.ts
9
- import { AppState, Dimensions, Platform as Platform2 } from "react-native";
9
+ import { AppState, Dimensions as Dimensions2, Platform as Platform2 } from "react-native";
10
+
11
+ // src/mismatch.ts
12
+ var blocked = false;
13
+ async function checkPlatformMismatch(res) {
14
+ if (res.status !== 409) return false;
15
+ let body = null;
16
+ try {
17
+ body = JSON.parse(await (typeof res.clone === "function" ? res.clone() : res).text());
18
+ } catch {
19
+ }
20
+ if (body?.reason !== "platform_mismatch") return false;
21
+ if (!blocked) {
22
+ blocked = true;
23
+ const message = typeof body.error === "string" ? body.error : "This key belongs to a Blipit project for another platform.";
24
+ console.error(`[blipit] BLIPIT IS NOT SENDING: ${message} Nothing more is sent with this key until the app restarts.`);
25
+ }
26
+ return true;
27
+ }
28
+ function guardPlatform(fetcher) {
29
+ return (async (...args) => {
30
+ if (blocked) return new Response(null, { status: 409 });
31
+ const res = await fetcher(...args);
32
+ await checkPlatformMismatch(res);
33
+ return res;
34
+ });
35
+ }
36
+
37
+ // src/triggers.ts
38
+ var TRIGGERS = ["shake", "screenshot", "two_finger", "crash"];
39
+ var PICKER_MAX = 3;
40
+ var PICKER_SIDE = 480;
41
+ var PICKER_SETTLE_MS = 700;
42
+ var PICKER_IDLE_MS = 18e4;
43
+ var isTrigger = (v) => typeof v === "string" && TRIGGERS.includes(v);
44
+ function createDebounce(gapMs = 1500, now = Date.now) {
45
+ let last = -Infinity;
46
+ return {
47
+ allow(open2) {
48
+ const t = now();
49
+ if (open2 || t - last < gapMs) return false;
50
+ last = t;
51
+ return true;
52
+ }
53
+ };
54
+ }
55
+ var parseReportButton = (json2) => !!json2 && typeof json2 === "object" && json2.report_button === true;
56
+ function userHeaders(user) {
57
+ const out = {};
58
+ if (user?.id) out["X-Blipit-User-Id"] = user.id;
59
+ if (user?.email) out["X-Blipit-User-Email"] = user.email;
60
+ return out;
61
+ }
62
+ function pickerSize(width, height, side = PICKER_SIDE) {
63
+ const scale = Math.min(1, side / Math.max(width, height, 1));
64
+ return { width: Math.max(1, Math.round(width * scale)), height: Math.max(1, Math.round(height * scale)) };
65
+ }
66
+ var ScreenShots = class {
67
+ items = [];
68
+ hiddenAt = 0;
69
+ add(shot) {
70
+ this.items = [shot, ...this.items.filter((s2) => s2.name !== shot.name)].slice(0, PICKER_MAX);
71
+ }
72
+ list(except) {
73
+ return this.items.filter((s2) => s2.name !== except);
74
+ }
75
+ clear() {
76
+ this.items = [];
77
+ }
78
+ background(at) {
79
+ this.hiddenAt = at;
80
+ }
81
+ foreground(at) {
82
+ if (this.hiddenAt && at - this.hiddenAt >= PICKER_IDLE_MS) this.clear();
83
+ this.hiddenAt = 0;
84
+ }
85
+ };
86
+ function lastFatal(queue) {
87
+ for (let i = queue.length - 1; i >= 0; i--) {
88
+ const e = queue[i];
89
+ if (e?.level === "fatal" && e.exception?.handled === false && typeof e.event_id === "string" && /^[0-9a-f]{32}$/.test(e.event_id)) return e.event_id;
90
+ }
91
+ return void 0;
92
+ }
10
93
 
11
94
  // src/nuggets.ts
12
- var VERSION = "0.5.0";
95
+ var VERSION = "0.6.1";
13
96
  var SDK_NAME = "@blipit/react-native";
97
+ var SDK_HEADER = `${SDK_NAME}/${VERSION}`;
14
98
  var DEFAULT_ENDPOINT = "https://in.blipit.io";
15
99
  var CATEGORIES = /* @__PURE__ */ new Set(["ui.click", "ui.input", "navigation", "http", "console", "query", "custom"]);
16
100
  var CRUMB_LEVELS = /* @__PURE__ */ new Set(["error", "warning", "info", "debug"]);
@@ -53,6 +137,7 @@ var Nuggets = class {
53
137
  user;
54
138
  tags = {};
55
139
  lastEventId;
140
+ crashId;
56
141
  enabled;
57
142
  onError;
58
143
  crumbs = [];
@@ -69,13 +154,14 @@ var Nuggets = class {
69
154
  this.endpoint = (options.endpoint ?? DEFAULT_ENDPOINT).replace(/\/api\/v1\/events.*$/, "").replace(/\/+$/, "");
70
155
  this.key = options.key;
71
156
  this.enabled = options.enabled !== false;
72
- this.fetcher = options.fetch ?? ((...a) => fetch(...a));
157
+ this.fetcher = guardPlatform(options.fetch ?? ((...a) => fetch(...a)));
73
158
  this.now = options.now ?? Date.now;
74
159
  try {
75
160
  const saved = JSON.parse(options.store?.load() ?? "[]");
76
161
  if (Array.isArray(saved)) this.queue = saved.slice(-QUEUE_MAX);
77
162
  } catch {
78
163
  }
164
+ this.crashId = lastFatal(this.queue);
79
165
  }
80
166
  get pending() {
81
167
  return this.queue.length;
@@ -195,7 +281,7 @@ var Nuggets = class {
195
281
  }
196
282
  }
197
283
  post(path, body) {
198
- return this.fetcher(this.url(path), { method: "POST", headers: { "Content-Type": "application/json", "X-Blipit-Key": this.key }, body: JSON.stringify(body) });
284
+ return this.fetcher(this.url(path), { method: "POST", headers: { "Content-Type": "application/json", "X-Blipit-Key": this.key, "X-Blipit-Sdk": SDK_HEADER }, body: JSON.stringify(body) });
199
285
  }
200
286
  async send(event) {
201
287
  try {
@@ -306,11 +392,11 @@ function instrument(core2, g = globalThis) {
306
392
  }
307
393
  const proto = g.XMLHttpRequest?.prototype;
308
394
  if (proto?.open && proto.send) {
309
- const open = proto.open;
395
+ const open2 = proto.open;
310
396
  const send = proto.send;
311
397
  proto.open = function(method, url, ...rest) {
312
398
  this._blipit = [String(method).toUpperCase(), String(url)];
313
- return open.call(this, method, url, ...rest);
399
+ return open2.call(this, method, url, ...rest);
314
400
  };
315
401
  proto.send = function(...args) {
316
402
  const meta = this._blipit;
@@ -352,7 +438,17 @@ function json(v) {
352
438
  }
353
439
 
354
440
  // src/native.ts
355
- import { NativeModules } from "react-native";
441
+ import { NativeEventEmitter, NativeModules } from "react-native";
442
+ function onNativeTrigger(handle) {
443
+ const b = bridge();
444
+ if (!b) return void 0;
445
+ try {
446
+ const sub = new NativeEventEmitter(b).addListener("BlipitReportTrigger", (e) => handle(e?.trigger, e?.crashId));
447
+ return () => sub.remove();
448
+ } catch {
449
+ return void 0;
450
+ }
451
+ }
356
452
  var bridge = () => NativeModules.BlipitNuggets;
357
453
  function nativeInfo() {
358
454
  const b = bridge();
@@ -444,7 +540,15 @@ var REPORT_STRINGS = {
444
540
  "recError": "The recording could not be made. You can still send the report.",
445
541
  "uploadingVideo": "Uploading recording\u2026",
446
542
  "close": "Close",
447
- "noShot": "The screenshot could not be taken. You can still send the report."
543
+ "noShot": "The screenshot could not be taken. You can still send the report.",
544
+ "shotAsk": "Report a bug with this screen?",
545
+ "report": "Report",
546
+ "notNow": "Not now",
547
+ "crashAsk": "The app closed unexpectedly. Tell us what you were doing?",
548
+ "tellUs": "Tell us",
549
+ "pickTitle": "Which screen is the bug on?",
550
+ "pickNow": "Current screen",
551
+ "pickBefore": "Earlier screen"
448
552
  },
449
553
  "ar": {
450
554
  "title": "\u0627\u0644\u0625\u0628\u0644\u0627\u063A \u0639\u0646 \u062E\u0637\u0623",
@@ -477,7 +581,15 @@ var REPORT_STRINGS = {
477
581
  "recError": "\u062A\u0639\u0630\u0651\u0631 \u0625\u0646\u0634\u0627\u0621 \u0627\u0644\u062A\u0633\u062C\u064A\u0644. \u0644\u0627 \u064A\u0632\u0627\u0644 \u0628\u0625\u0645\u0643\u0627\u0646\u0643 \u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0628\u0644\u0627\u063A.",
478
582
  "uploadingVideo": "\u062C\u0627\u0631\u064D \u0631\u0641\u0639 \u0627\u0644\u062A\u0633\u062C\u064A\u0644\u2026",
479
583
  "close": "\u0625\u063A\u0644\u0627\u0642",
480
- "noShot": "\u062A\u0639\u0630\u0651\u0631 \u0627\u0644\u062A\u0642\u0627\u0637 \u0644\u0642\u0637\u0629 \u0627\u0644\u0634\u0627\u0634\u0629. \u0644\u0627 \u064A\u0632\u0627\u0644 \u0628\u0625\u0645\u0643\u0627\u0646\u0643 \u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0628\u0644\u0627\u063A."
584
+ "noShot": "\u062A\u0639\u0630\u0651\u0631 \u0627\u0644\u062A\u0642\u0627\u0637 \u0644\u0642\u0637\u0629 \u0627\u0644\u0634\u0627\u0634\u0629. \u0644\u0627 \u064A\u0632\u0627\u0644 \u0628\u0625\u0645\u0643\u0627\u0646\u0643 \u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u0628\u0644\u0627\u063A.",
585
+ "shotAsk": "\u0647\u0644 \u062A\u0631\u064A\u062F \u0627\u0644\u0625\u0628\u0644\u0627\u063A \u0639\u0646 \u062E\u0637\u0623 \u0641\u064A \u0647\u0630\u0647 \u0627\u0644\u0634\u0627\u0634\u0629\u061F",
586
+ "report": "\u0625\u0628\u0644\u0627\u063A",
587
+ "notNow": "\u0644\u064A\u0633 \u0627\u0644\u0622\u0646",
588
+ "crashAsk": "\u0623\u064F\u063A\u0644\u0642 \u0627\u0644\u062A\u0637\u0628\u064A\u0642 \u0628\u0634\u0643\u0644 \u063A\u064A\u0631 \u0645\u062A\u0648\u0642\u0639. \u0623\u062E\u0628\u0631\u0646\u0627 \u0628\u0645\u0627 \u0643\u0646\u062A \u062A\u0641\u0639\u0644\u0647\u061F",
589
+ "tellUs": "\u0623\u062E\u0628\u0631\u0646\u0627",
590
+ "pickTitle": "\u0641\u064A \u0623\u064A \u0634\u0627\u0634\u0629 \u064A\u0638\u0647\u0631 \u0627\u0644\u062E\u0637\u0623\u061F",
591
+ "pickNow": "\u0627\u0644\u0634\u0627\u0634\u0629 \u0627\u0644\u062D\u0627\u0644\u064A\u0629",
592
+ "pickBefore": "\u0634\u0627\u0634\u0629 \u0633\u0627\u0628\u0642\u0629"
481
593
  },
482
594
  "de": {
483
595
  "title": "Fehler melden",
@@ -510,7 +622,15 @@ var REPORT_STRINGS = {
510
622
  "recError": "Die Aufnahme konnte nicht erstellt werden. Sie k\xF6nnen den Bericht trotzdem senden.",
511
623
  "uploadingVideo": "Aufnahme wird hochgeladen\u2026",
512
624
  "close": "Schlie\xDFen",
513
- "noShot": "Der Screenshot konnte nicht erstellt werden. Sie k\xF6nnen die Meldung trotzdem senden."
625
+ "noShot": "Der Screenshot konnte nicht erstellt werden. Sie k\xF6nnen die Meldung trotzdem senden.",
626
+ "shotAsk": "Einen Fehler mit diesem Bildschirm melden?",
627
+ "report": "Melden",
628
+ "notNow": "Nicht jetzt",
629
+ "crashAsk": "Die App wurde unerwartet beendet. M\xF6chten Sie uns sagen, was Sie gerade getan haben?",
630
+ "tellUs": "Erz\xE4hlen",
631
+ "pickTitle": "Auf welchem Bildschirm ist der Fehler?",
632
+ "pickNow": "Aktueller Bildschirm",
633
+ "pickBefore": "Fr\xFCherer Bildschirm"
514
634
  },
515
635
  "es": {
516
636
  "title": "Reportar un error",
@@ -543,7 +663,15 @@ var REPORT_STRINGS = {
543
663
  "recError": "No se pudo hacer la grabaci\xF3n. A\xFAn puedes enviar el informe.",
544
664
  "uploadingVideo": "Subiendo grabaci\xF3n\u2026",
545
665
  "close": "Cerrar",
546
- "noShot": "No se pudo tomar la captura. Aun as\xED puedes enviar el reporte."
666
+ "noShot": "No se pudo tomar la captura. Aun as\xED puedes enviar el reporte.",
667
+ "shotAsk": "\xBFInformar de un error con esta pantalla?",
668
+ "report": "Informar",
669
+ "notNow": "Ahora no",
670
+ "crashAsk": "La aplicaci\xF3n se cerr\xF3 inesperadamente. \xBFNos cuenta qu\xE9 estaba haciendo?",
671
+ "tellUs": "Contarlo",
672
+ "pickTitle": "\xBFEn qu\xE9 pantalla est\xE1 el error?",
673
+ "pickNow": "Pantalla actual",
674
+ "pickBefore": "Pantalla anterior"
547
675
  },
548
676
  "fr": {
549
677
  "title": "Signaler un bug",
@@ -576,7 +704,15 @@ var REPORT_STRINGS = {
576
704
  "recError": "L\u2019enregistrement n\u2019a pas pu \xEAtre effectu\xE9. Vous pouvez quand m\xEAme envoyer le rapport.",
577
705
  "uploadingVideo": "Envoi de l\u2019enregistrement\u2026",
578
706
  "close": "Fermer",
579
- "noShot": "La capture d\u2019\xE9cran a \xE9chou\xE9. Vous pouvez quand m\xEAme envoyer le signalement."
707
+ "noShot": "La capture d\u2019\xE9cran a \xE9chou\xE9. Vous pouvez quand m\xEAme envoyer le signalement.",
708
+ "shotAsk": "Signaler un bug avec cet \xE9cran ?",
709
+ "report": "Signaler",
710
+ "notNow": "Plus tard",
711
+ "crashAsk": "L\u2019application s\u2019est ferm\xE9e de fa\xE7on inattendue. Dites-nous ce que vous faisiez ?",
712
+ "tellUs": "Raconter",
713
+ "pickTitle": "Sur quel \xE9cran se trouve le bug ?",
714
+ "pickNow": "\xC9cran actuel",
715
+ "pickBefore": "\xC9cran pr\xE9c\xE9dent"
580
716
  },
581
717
  "it": {
582
718
  "title": "Segnala un bug",
@@ -609,7 +745,15 @@ var REPORT_STRINGS = {
609
745
  "recError": "Non \xE8 stato possibile registrare. Puoi comunque inviare la segnalazione.",
610
746
  "uploadingVideo": "Caricamento della registrazione\u2026",
611
747
  "close": "Chiudi",
612
- "noShot": "Non \xE8 stato possibile acquisire lo screenshot. Puoi comunque inviare la segnalazione."
748
+ "noShot": "Non \xE8 stato possibile acquisire lo screenshot. Puoi comunque inviare la segnalazione.",
749
+ "shotAsk": "Segnalare un bug con questa schermata?",
750
+ "report": "Segnala",
751
+ "notNow": "Non ora",
752
+ "crashAsk": "L\u2019app si \xE8 chiusa in modo imprevisto. Ci dice cosa stava facendo?",
753
+ "tellUs": "Racconta",
754
+ "pickTitle": "In quale schermata si trova il bug?",
755
+ "pickNow": "Schermata attuale",
756
+ "pickBefore": "Schermata precedente"
613
757
  },
614
758
  "ja": {
615
759
  "title": "\u4E0D\u5177\u5408\u3092\u5831\u544A",
@@ -642,7 +786,15 @@ var REPORT_STRINGS = {
642
786
  "recError": "\u9332\u753B\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u30EC\u30DD\u30FC\u30C8\u306F\u305D\u306E\u307E\u307E\u9001\u4FE1\u3067\u304D\u307E\u3059\u3002",
643
787
  "uploadingVideo": "\u9332\u753B\u3092\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u4E2D\u2026",
644
788
  "close": "\u9589\u3058\u308B",
645
- "noShot": "\u30B9\u30AF\u30EA\u30FC\u30F3\u30B7\u30E7\u30C3\u30C8\u3092\u64AE\u5F71\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u5831\u544A\u306F\u3053\u306E\u307E\u307E\u9001\u4FE1\u3067\u304D\u307E\u3059\u3002"
789
+ "noShot": "\u30B9\u30AF\u30EA\u30FC\u30F3\u30B7\u30E7\u30C3\u30C8\u3092\u64AE\u5F71\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u5831\u544A\u306F\u3053\u306E\u307E\u307E\u9001\u4FE1\u3067\u304D\u307E\u3059\u3002",
790
+ "shotAsk": "\u3053\u306E\u753B\u9762\u3067\u4E0D\u5177\u5408\u3092\u5831\u544A\u3057\u307E\u3059\u304B\uFF1F",
791
+ "report": "\u5831\u544A\u3059\u308B",
792
+ "notNow": "\u4ECA\u306F\u3057\u306A\u3044",
793
+ "crashAsk": "\u30A2\u30D7\u30EA\u304C\u4E88\u671F\u305B\u305A\u7D42\u4E86\u3057\u307E\u3057\u305F\u3002\u4F55\u3092\u3057\u3066\u3044\u305F\u304B\u6559\u3048\u3066\u3044\u305F\u3060\u3051\u307E\u3059\u304B\uFF1F",
794
+ "tellUs": "\u4F1D\u3048\u308B",
795
+ "pickTitle": "\u4E0D\u5177\u5408\u304C\u3042\u308B\u306E\u306F\u3069\u306E\u753B\u9762\u3067\u3059\u304B\uFF1F",
796
+ "pickNow": "\u73FE\u5728\u306E\u753B\u9762",
797
+ "pickBefore": "\u524D\u306E\u753B\u9762"
646
798
  },
647
799
  "nl": {
648
800
  "title": "Bug melden",
@@ -675,7 +827,15 @@ var REPORT_STRINGS = {
675
827
  "recError": "De opname kon niet worden gemaakt. Je kunt het rapport nog steeds versturen.",
676
828
  "uploadingVideo": "Opname uploaden\u2026",
677
829
  "close": "Sluiten",
678
- "noShot": "De schermafbeelding kon niet worden gemaakt. Je kunt de melding toch versturen."
830
+ "noShot": "De schermafbeelding kon niet worden gemaakt. Je kunt de melding toch versturen.",
831
+ "shotAsk": "Een bug melden met dit scherm?",
832
+ "report": "Melden",
833
+ "notNow": "Niet nu",
834
+ "crashAsk": "De app is onverwacht gesloten. Vertelt u ons wat u aan het doen was?",
835
+ "tellUs": "Vertellen",
836
+ "pickTitle": "Op welk scherm zit de bug?",
837
+ "pickNow": "Huidig scherm",
838
+ "pickBefore": "Eerder scherm"
679
839
  },
680
840
  "pt": {
681
841
  "title": "Reportar um erro",
@@ -708,7 +868,15 @@ var REPORT_STRINGS = {
708
868
  "recError": "N\xE3o foi poss\xEDvel gravar. Voc\xEA ainda pode enviar o relat\xF3rio.",
709
869
  "uploadingVideo": "Enviando grava\xE7\xE3o\u2026",
710
870
  "close": "Fechar",
711
- "noShot": "N\xE3o foi poss\xEDvel fazer a captura. Voc\xEA ainda pode enviar o relat\xF3rio."
871
+ "noShot": "N\xE3o foi poss\xEDvel fazer a captura. Voc\xEA ainda pode enviar o relat\xF3rio.",
872
+ "shotAsk": "Reportar um erro com esta tela?",
873
+ "report": "Reportar",
874
+ "notNow": "Agora n\xE3o",
875
+ "crashAsk": "O app fechou inesperadamente. Conte o que voc\xEA estava fazendo?",
876
+ "tellUs": "Contar",
877
+ "pickTitle": "Em qual tela est\xE1 o erro?",
878
+ "pickNow": "Tela atual",
879
+ "pickBefore": "Tela anterior"
712
880
  },
713
881
  "tr": {
714
882
  "title": "Hata bildir",
@@ -741,7 +909,15 @@ var REPORT_STRINGS = {
741
909
  "recError": "Kay\u0131t yap\u0131lamad\u0131. Raporu yine de g\xF6nderebilirsiniz.",
742
910
  "uploadingVideo": "Kay\u0131t y\xFCkleniyor\u2026",
743
911
  "close": "Kapat",
744
- "noShot": "Ekran g\xF6r\xFCnt\xFCs\xFC al\u0131namad\u0131. Bildirimi yine de g\xF6nderebilirsiniz."
912
+ "noShot": "Ekran g\xF6r\xFCnt\xFCs\xFC al\u0131namad\u0131. Bildirimi yine de g\xF6nderebilirsiniz.",
913
+ "shotAsk": "Bu ekranla bir hata bildirilsin mi?",
914
+ "report": "Bildir",
915
+ "notNow": "\u015Eimdi de\u011Fil",
916
+ "crashAsk": "Uygulama beklenmedik \u015Fekilde kapand\u0131. Ne yapt\u0131\u011F\u0131n\u0131z\u0131 bize anlat\u0131r m\u0131s\u0131n\u0131z?",
917
+ "tellUs": "Anlat",
918
+ "pickTitle": "Hata hangi ekranda?",
919
+ "pickNow": "Ge\xE7erli ekran",
920
+ "pickBefore": "\xD6nceki ekran"
745
921
  },
746
922
  "zh": {
747
923
  "title": "\u62A5\u544A\u95EE\u9898",
@@ -774,7 +950,15 @@ var REPORT_STRINGS = {
774
950
  "recError": "\u65E0\u6CD5\u5B8C\u6210\u5F55\u5236\u3002\u4F60\u4ECD\u7136\u53EF\u4EE5\u53D1\u9001\u62A5\u544A\u3002",
775
951
  "uploadingVideo": "\u6B63\u5728\u4E0A\u4F20\u5F55\u5236\u5185\u5BB9\u2026",
776
952
  "close": "\u5173\u95ED",
777
- "noShot": "\u65E0\u6CD5\u622A\u53D6\u5C4F\u5E55\u3002\u60A8\u4ECD\u7136\u53EF\u4EE5\u53D1\u9001\u62A5\u544A\u3002"
953
+ "noShot": "\u65E0\u6CD5\u622A\u53D6\u5C4F\u5E55\u3002\u60A8\u4ECD\u7136\u53EF\u4EE5\u53D1\u9001\u62A5\u544A\u3002",
954
+ "shotAsk": "\u8981\u7528\u6B64\u5C4F\u5E55\u62A5\u544A\u95EE\u9898\u5417\uFF1F",
955
+ "report": "\u62A5\u544A",
956
+ "notNow": "\u4EE5\u540E\u518D\u8BF4",
957
+ "crashAsk": "\u5E94\u7528\u610F\u5916\u5173\u95ED\u3002\u80FD\u544A\u8BC9\u6211\u4EEC\u4F60\u5F53\u65F6\u5728\u505A\u4EC0\u4E48\u5417\uFF1F",
958
+ "tellUs": "\u544A\u8BC9\u6211\u4EEC",
959
+ "pickTitle": "\u95EE\u9898\u51FA\u73B0\u5728\u54EA\u4E2A\u5C4F\u5E55\uFF1F",
960
+ "pickNow": "\u5F53\u524D\u5C4F\u5E55",
961
+ "pickBefore": "\u4E4B\u524D\u7684\u5C4F\u5E55"
778
962
  }
779
963
  };
780
964
 
@@ -815,6 +999,7 @@ function feedbackBody(input) {
815
999
  };
816
1000
  if (input.title.trim()) body.title = input.title.trim();
817
1001
  if (input.email?.trim()) body.email = input.email.trim();
1002
+ if (input.eventId && /^[0-9a-f]{32}$/.test(input.eventId)) body.event_id = input.eventId;
818
1003
  if (input.image) {
819
1004
  const list = annotations(input.shapes ?? [], input.image.width, input.image.height);
820
1005
  if (list.length) body.annotations = [{ position: 0, shapes: list }];
@@ -828,19 +1013,19 @@ var ReportClient = class {
828
1013
  constructor(endpoint, key, fetcher = (...a) => fetch(...a)) {
829
1014
  this.endpoint = endpoint.replace(/\/+$/, "");
830
1015
  this.key = key;
831
- this.fetcher = fetcher;
1016
+ this.fetcher = guardPlatform(fetcher);
832
1017
  }
833
1018
  async call(path, init2) {
834
- const res = await this.fetcher(`${this.endpoint}${path}`, { ...init2, headers: { "X-Blipit-Key": this.key, ...init2.headers } });
1019
+ const res = await this.fetcher(`${this.endpoint}${path}`, { ...init2, headers: { "X-Blipit-Key": this.key, "X-Blipit-Sdk": SDK_HEADER, ...init2.headers } });
835
1020
  const text2 = await res.text();
836
1021
  if (!res.ok) throw new Error(`Blipit returned ${res.status}`);
837
1022
  return text2;
838
1023
  }
839
- async settings() {
840
- return JSON.parse(await this.call("/api/v1/feedback/settings", { method: "GET" }));
1024
+ async settings(user) {
1025
+ return JSON.parse(await this.call("/api/v1/feedback/settings", { method: "GET", headers: userHeaders(user) }));
841
1026
  }
842
1027
  async event(body) {
843
- 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) });
1028
+ const res = await this.fetcher(`${this.endpoint}/api/v1/events`, { method: "POST", headers: { "X-Blipit-Key": this.key, "X-Blipit-Sdk": SDK_HEADER, "Content-Type": "application/json" }, body: JSON.stringify(body) });
844
1029
  return res.ok || res.status >= 400 && res.status < 500 && res.status !== 408 && res.status !== 429;
845
1030
  }
846
1031
  async send(body) {
@@ -1031,6 +1216,7 @@ function createStuck(transport, info, clock = Date.now) {
1031
1216
  import { useEffect, useMemo, useRef, useState } from "react";
1032
1217
  import {
1033
1218
  ActivityIndicator,
1219
+ Dimensions,
1034
1220
  I18nManager,
1035
1221
  Image,
1036
1222
  KeyboardAvoidingView,
@@ -1050,13 +1236,46 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
1050
1236
  var C = { navy: "#0B1A3A", card: "#1A2135", brand: "#3882F6", muted: "#98A6BE", mark: "#FF3B30", danger: "#FF7A6E", white: "#FFFFFF" };
1051
1237
  var opener = null;
1052
1238
  var config = null;
1053
- function configureReporter(client, device) {
1054
- config = { client, device };
1239
+ var open = false;
1240
+ var serverButton = false;
1241
+ var onServerButton = null;
1242
+ var currentScreen;
1243
+ var settle;
1244
+ var debounce = createDebounce();
1245
+ var screens = new ScreenShots();
1246
+ function configureReporter(client, device, o = { picker: true }) {
1247
+ config = { client, device, picker: o.picker };
1248
+ if (!o.picker) screens.clear();
1055
1249
  }
1056
1250
  function showReport() {
1057
1251
  if (!config) console.warn("[blipit] call Blipit.init before showReport");
1058
1252
  else if (!opener) console.warn("[blipit] wrap your app in <BlipitReporter> to use showReport");
1059
- else opener();
1253
+ else opener({ picker: config.picker, crashId: null });
1254
+ }
1255
+ function reportTrigger(trigger, crashId) {
1256
+ if (!config || !opener || !debounce.allow(open)) return;
1257
+ opener({ picker: false, crashId: trigger === "crash" ? crashId : null });
1258
+ }
1259
+ function setServerButton(on) {
1260
+ serverButton = on;
1261
+ onServerButton?.(on);
1262
+ }
1263
+ function noteScreen(name) {
1264
+ if (!name || !config?.picker) return;
1265
+ currentScreen = name;
1266
+ if (settle) clearTimeout(settle);
1267
+ settle = setTimeout(async () => {
1268
+ settle = void 0;
1269
+ const shooter = viewShot();
1270
+ if (open || !shooter || currentScreen !== name || !config?.picker) return;
1271
+ try {
1272
+ const { width, height } = Dimensions.get("window");
1273
+ const size = pickerSize(width, height);
1274
+ const uri = await shooter.captureScreen({ format: "jpg", quality: 0.6, result: "data-uri", ...size });
1275
+ if (!open && currentScreen === name && config?.picker) screens.add({ name, uri, ...size });
1276
+ } catch {
1277
+ }
1278
+ }, PICKER_SETTLE_MS);
1060
1279
  }
1061
1280
  function viewShot() {
1062
1281
  try {
@@ -1079,19 +1298,32 @@ function BlipitReporter({ children, showButton = false }) {
1079
1298
  const [shot, setShot] = useState(null);
1080
1299
  const [flat, setFlat] = useState(null);
1081
1300
  const [notice, setNotice] = useState(null);
1301
+ const [wantPicker, setWantPicker] = useState(false);
1302
+ const [crashId, setCrashId] = useState(null);
1303
+ const [earlier, setEarlier] = useState([]);
1304
+ const [server, setServer] = useState(serverButton);
1082
1305
  const shapes = useRef([]);
1083
1306
  useEffect(() => {
1084
- opener = () => {
1307
+ opener = (o) => {
1085
1308
  shapes.current = [];
1086
1309
  setShot(null);
1087
1310
  setFlat(null);
1088
1311
  setNotice(null);
1312
+ setEarlier([]);
1313
+ setWantPicker(o.picker);
1314
+ setCrashId(o.crashId);
1089
1315
  setStage("choice");
1090
1316
  };
1317
+ onServerButton = setServer;
1318
+ setServer(serverButton);
1091
1319
  return () => {
1092
1320
  opener = null;
1321
+ onServerButton = null;
1093
1322
  };
1094
1323
  }, []);
1324
+ useEffect(() => {
1325
+ open = stage !== "closed";
1326
+ }, [stage]);
1095
1327
  const capture = async () => {
1096
1328
  const shooter = viewShot();
1097
1329
  setStage("closed");
@@ -1101,7 +1333,9 @@ function BlipitReporter({ children, showButton = false }) {
1101
1333
  const uri = await shooter.captureScreen({ format: "jpg", quality: 0.9, result: "tmpfile" });
1102
1334
  const size = await new Promise((ok, fail) => Image.getSize(uri, (width, height) => ok({ width, height }), fail));
1103
1335
  setShot({ uri, ...size });
1104
- setStage("editor");
1336
+ const before = wantPicker ? screens.list(currentScreen) : [];
1337
+ setEarlier(before);
1338
+ setStage(before.length ? "pick" : "editor");
1105
1339
  } catch (err) {
1106
1340
  if (!shooter) console.warn("[blipit] install react-native-view-shot to attach screenshots to bug reports");
1107
1341
  setNotice(t("noShot"));
@@ -1110,7 +1344,7 @@ function BlipitReporter({ children, showButton = false }) {
1110
1344
  };
1111
1345
  return /* @__PURE__ */ jsxs(View, { style: { flex: 1 }, children: [
1112
1346
  children,
1113
- showButton && stage === "closed" ? /* @__PURE__ */ jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: t("title"), onPress: () => opener?.(), style: ({ pressed }) => [s.fab, pressed && { opacity: 0.85 }], children: [
1347
+ (showButton || server) && stage === "closed" ? /* @__PURE__ */ jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: t("title"), onPress: showReport, style: ({ pressed }) => [s.fab, pressed && { opacity: 0.85 }], children: [
1114
1348
  /* @__PURE__ */ jsx(Text, { style: s.fabIcon, children: "!" }),
1115
1349
  /* @__PURE__ */ jsx(Text, { style: s.fabText, children: t("title") })
1116
1350
  ] }) : null,
@@ -1133,6 +1367,28 @@ function BlipitReporter({ children, showButton = false }) {
1133
1367
  )
1134
1368
  ] })
1135
1369
  ] }) : null,
1370
+ stage === "pick" && shot ? /* @__PURE__ */ jsxs(View, { style: s.pad, children: [
1371
+ /* @__PURE__ */ jsx(Bar, { children: /* @__PURE__ */ jsx(BarButton, { label: t("mBack"), glyph: "\u2039", onPress: () => setStage("choice") }) }),
1372
+ /* @__PURE__ */ jsx(Text, { style: s.h1, children: t("pickTitle") }),
1373
+ /* @__PURE__ */ jsx(ScrollView, { contentContainerStyle: s.thumbs, children: [shot, ...earlier].map((item, i) => /* @__PURE__ */ jsxs(
1374
+ Pressable,
1375
+ {
1376
+ accessibilityRole: "button",
1377
+ accessibilityLabel: i === 0 ? t("pickNow") : t("pickBefore"),
1378
+ onPress: () => {
1379
+ setShot(item);
1380
+ setEarlier([]);
1381
+ setStage("editor");
1382
+ },
1383
+ style: ({ pressed }) => [s.thumb, pressed && { opacity: 0.85 }],
1384
+ children: [
1385
+ /* @__PURE__ */ jsx(Image, { source: { uri: item.uri }, style: [s.thumbImage, { aspectRatio: item.width / Math.max(1, item.height) }], resizeMode: "contain", accessibilityIgnoresInvertColors: true }),
1386
+ /* @__PURE__ */ jsx(Text, { style: s.thumbText, numberOfLines: 1, children: i === 0 ? t("pickNow") : t("pickBefore") })
1387
+ ]
1388
+ },
1389
+ i
1390
+ )) })
1391
+ ] }) : null,
1136
1392
  stage === "editor" && shot ? /* @__PURE__ */ jsx(
1137
1393
  Editor,
1138
1394
  {
@@ -1155,6 +1411,7 @@ function BlipitReporter({ children, showButton = false }) {
1155
1411
  flat,
1156
1412
  shapes: shapes.current,
1157
1413
  notice,
1414
+ eventId: crashId,
1158
1415
  onBack: () => setStage(shot ? "editor" : "choice"),
1159
1416
  onDone: () => setStage("closed")
1160
1417
  }
@@ -1284,7 +1541,7 @@ function Editor({ shot, shapes, t, onBack, onNext }) {
1284
1541
  await new Promise((r) => setTimeout(r, 80));
1285
1542
  let out = shot;
1286
1543
  const shooter = viewShot();
1287
- if (shapes.current.length && shooter && content.current) {
1544
+ if ((shapes.current.length || shot.uri.startsWith("data:")) && shooter && content.current) {
1288
1545
  try {
1289
1546
  const uri = await shooter.captureRef(content.current, { format: "jpg", quality: 0.85, result: "tmpfile" });
1290
1547
  out = { uri, width: shot.width, height: shot.height };
@@ -1387,7 +1644,7 @@ function ToolButton({ label, glyph, on, onPress }) {
1387
1644
  /* @__PURE__ */ jsx(Text, { style: [s.toolText, { color: on ? C.white : C.muted }], numberOfLines: 1, children: label })
1388
1645
  ] });
1389
1646
  }
1390
- function Details({ t, lang, shot, flat, shapes, notice, onBack, onDone }) {
1647
+ function Details({ t, lang, shot, flat, shapes, notice, eventId, onBack, onDone }) {
1391
1648
  const [title, setTitle] = useState("");
1392
1649
  const [message, setMessage] = useState("");
1393
1650
  const [email, setEmail] = useState("");
@@ -1403,7 +1660,7 @@ function Details({ t, lang, shot, flat, shapes, notice, onBack, onDone }) {
1403
1660
  setBusy(true);
1404
1661
  setStatus({ text: t("sending"), error: false });
1405
1662
  try {
1406
- const receipt = await config.client.send(feedbackBody({ title, message: message.trim(), email, context: config.device(), shapes, image: shot, screenshots: image ? 1 : 0, locale: lang }));
1663
+ const receipt = await config.client.send(feedbackBody({ title, message: message.trim(), email, context: config.device(), shapes, image: shot, screenshots: image ? 1 : 0, locale: lang, eventId }));
1407
1664
  let uploaded = true;
1408
1665
  if (image) {
1409
1666
  try {
@@ -1462,6 +1719,10 @@ var s = StyleSheet.create({
1462
1719
  tool: { flex: 1, height: 60, alignItems: "center", justifyContent: "center", borderRadius: 12, marginHorizontal: 2 },
1463
1720
  toolGlyph: { fontSize: 20 },
1464
1721
  toolText: { fontSize: 11, marginTop: 2 },
1722
+ thumbs: { flexDirection: "row", flexWrap: "wrap", gap: 12, paddingVertical: 12 },
1723
+ thumb: { width: "47%", backgroundColor: C.card, borderRadius: 14, borderWidth: 1, borderColor: "rgba(255,255,255,0.1)", padding: 8, gap: 8 },
1724
+ thumbImage: { width: "100%", borderRadius: 8, backgroundColor: C.navy },
1725
+ thumbText: { color: C.white, fontSize: 14, fontWeight: "600", textAlign: "center" },
1465
1726
  preview: { height: 150, borderRadius: 12, backgroundColor: C.card },
1466
1727
  input: { backgroundColor: C.card, borderRadius: 12, color: C.white, fontSize: 16, paddingHorizontal: 14, paddingVertical: 12, minHeight: 48 },
1467
1728
  fab: { position: "absolute", right: 16, bottom: 32, height: 48, borderRadius: 24, backgroundColor: C.brand, flexDirection: "row", alignItems: "center", paddingHorizontal: 18, elevation: 6, shadowColor: "#000", shadowOpacity: 0.25, shadowRadius: 10, shadowOffset: { width: 0, height: 4 } },
@@ -1477,7 +1738,7 @@ var core;
1477
1738
  var session;
1478
1739
  var appState;
1479
1740
  function init(options) {
1480
- const { key, publicKey, project, endpoint, waitForReady, ...rest } = options ?? {};
1741
+ const { key, publicKey, project, endpoint, waitForReady, shakeToReport, screenshotToReport, twoFingerReport, reportAfterCrash, screenPicker, ...rest } = options ?? {};
1481
1742
  const k = (key ?? publicKey ?? "").trim();
1482
1743
  if (!k) {
1483
1744
  console.warn(MISSING_KEY);
@@ -1497,26 +1758,42 @@ function init(options) {
1497
1758
  setBoundaryReporter((error) => c.captureException(error, false));
1498
1759
  instrument(() => core);
1499
1760
  const native = rest.enableNative !== false ? bridge() : void 0;
1761
+ if (native && !triggerOff) triggerOff = onNativeTrigger((trigger, crashId) => isTrigger(trigger) && reportTrigger(trigger, typeof crashId === "string" ? crashId : null));
1500
1762
  try {
1501
- native?.start(k, String(project), rest.environment ?? null, release ?? null, c.endpoint);
1763
+ native?.start(k, String(project), rest.environment ?? null, release ?? null, c.endpoint, {
1764
+ shakeToReport: shakeToReport === true,
1765
+ screenshotToReport: screenshotToReport === true,
1766
+ twoFingerReport: twoFingerReport === true,
1767
+ reportAfterCrash: reportAfterCrash === true,
1768
+ screenPicker: false
1769
+ });
1502
1770
  } catch {
1503
1771
  }
1772
+ if (reportAfterCrash === true && c.crashId) {
1773
+ try {
1774
+ native?.promptAfterCrash?.(c.crashId);
1775
+ } catch {
1776
+ }
1777
+ }
1504
1778
  session = release && rest.autoSessionTracking !== false ? new Session(c, release, rest.environment ?? "production") : void 0;
1505
1779
  c.onError = (unhandled) => session?.markError(unhandled);
1506
1780
  if (c.enabled) session?.start();
1507
1781
  appState = AppState?.addEventListener?.("change", (state) => {
1508
1782
  if (state === "active") {
1783
+ screens.foreground(Date.now());
1509
1784
  if (c.enabled) session?.start();
1510
1785
  void c.flush();
1511
1786
  } else if (state === "background") {
1787
+ screens.background(Date.now());
1512
1788
  session?.end();
1513
1789
  void c.flush();
1514
1790
  }
1515
1791
  });
1516
1792
  void c.flush();
1517
1793
  const reports = new ReportClient(base, k);
1518
- configureReporter(reports, () => deviceContext(release));
1794
+ configureReporter(reports, () => deviceContext(release), { picker: screenPicker !== false });
1519
1795
  reportClient = reports;
1796
+ refreshButton(0);
1520
1797
  if (!stuck) {
1521
1798
  stuck = createStuck(
1522
1799
  {
@@ -1538,6 +1815,33 @@ function init(options) {
1538
1815
  }
1539
1816
  var stuck = null;
1540
1817
  var reportClient;
1818
+ var triggerOff;
1819
+ var buttonTimer;
1820
+ var buttonBusy = false;
1821
+ var buttonAgain = false;
1822
+ function refreshButton(delay) {
1823
+ if (buttonTimer) clearTimeout(buttonTimer);
1824
+ buttonTimer = setTimeout(() => {
1825
+ buttonTimer = void 0;
1826
+ void fetchButton();
1827
+ }, delay);
1828
+ }
1829
+ async function fetchButton() {
1830
+ const client = reportClient;
1831
+ if (!client) return;
1832
+ if (buttonBusy) return void (buttonAgain = true);
1833
+ buttonBusy = true;
1834
+ try {
1835
+ setServerButton(parseReportButton(await client.settings(core?.user)));
1836
+ } catch {
1837
+ } finally {
1838
+ buttonBusy = false;
1839
+ if (buttonAgain) {
1840
+ buttonAgain = false;
1841
+ void fetchButton();
1842
+ }
1843
+ }
1844
+ }
1541
1845
  function reportReady() {
1542
1846
  stuck?.end(STARTUP);
1543
1847
  }
@@ -1555,7 +1859,7 @@ function endFlow(name) {
1555
1859
  if (flow) stuck?.end(flow);
1556
1860
  }
1557
1861
  function contexts(model, osVersion) {
1558
- const { width, height } = Dimensions.get("window");
1862
+ const { width, height } = Dimensions2.get("window");
1559
1863
  const engine = globalThis.HermesInternal ? "hermes" : "jsc";
1560
1864
  const rn = Platform2.constants?.reactNativeVersion;
1561
1865
  return {
@@ -1565,7 +1869,7 @@ function contexts(model, osVersion) {
1565
1869
  };
1566
1870
  }
1567
1871
  function deviceContext(release) {
1568
- const { width, height, scale } = Dimensions.get("window");
1872
+ const { width, height, scale } = Dimensions2.get("window");
1569
1873
  let language = "";
1570
1874
  let timezone = "";
1571
1875
  try {
@@ -1603,6 +1907,7 @@ function setUser(user) {
1603
1907
  bridge()?.setUser(u?.id ?? null, u?.email ?? null, u?.username ?? null);
1604
1908
  } catch {
1605
1909
  }
1910
+ refreshButton(1e3);
1606
1911
  }
1607
1912
  function setTag(key, value) {
1608
1913
  core?.setTag(key, value);
@@ -1626,6 +1931,7 @@ async function flush(timeout = 2e3) {
1626
1931
  function setEnabled(on) {
1627
1932
  if (!core) return;
1628
1933
  core.setEnabled(on);
1934
+ if (!on) screens.clear();
1629
1935
  if (on) session?.start();
1630
1936
  else session?.end();
1631
1937
  }
@@ -1644,7 +1950,18 @@ function hasReplayConsent() {
1644
1950
  return false;
1645
1951
  }
1646
1952
  }
1647
- var trackNavigation2 = (ref) => trackNavigation(() => core, ref);
1953
+ function trackNavigation2(ref) {
1954
+ const stop = trackNavigation(() => core, ref);
1955
+ const seen = () => {
1956
+ if (core?.enabled) noteScreen(ref.getCurrentRoute()?.name);
1957
+ };
1958
+ seen();
1959
+ const off = ref.addListener("state", seen);
1960
+ return () => {
1961
+ stop();
1962
+ off();
1963
+ };
1964
+ }
1648
1965
  export {
1649
1966
  BlipitReporter,
1650
1967
  DEFAULT_ENDPOINT,