@blipit/react-native 0.5.0 → 0.6.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/dist/index.cjs CHANGED
@@ -48,8 +48,91 @@ __export(index_exports, {
48
48
  module.exports = __toCommonJS(index_exports);
49
49
  var import_react_native3 = require("react-native");
50
50
 
51
+ // src/mismatch.ts
52
+ var blocked = false;
53
+ async function checkPlatformMismatch(res) {
54
+ if (res.status !== 409) return false;
55
+ let body = null;
56
+ try {
57
+ body = JSON.parse(await (typeof res.clone === "function" ? res.clone() : res).text());
58
+ } catch {
59
+ }
60
+ if (body?.reason !== "platform_mismatch") return false;
61
+ if (!blocked) {
62
+ blocked = true;
63
+ const message = typeof body.error === "string" ? body.error : "This key belongs to a Blipit project for another platform.";
64
+ console.error(`[blipit] BLIPIT IS NOT SENDING: ${message} Nothing more is sent with this key until the app restarts.`);
65
+ }
66
+ return true;
67
+ }
68
+ function guardPlatform(fetcher) {
69
+ return (async (...args) => {
70
+ if (blocked) return new Response(null, { status: 409 });
71
+ const res = await fetcher(...args);
72
+ await checkPlatformMismatch(res);
73
+ return res;
74
+ });
75
+ }
76
+
77
+ // src/triggers.ts
78
+ var TRIGGERS = ["shake", "screenshot", "two_finger", "crash"];
79
+ var PICKER_MAX = 3;
80
+ var PICKER_SIDE = 480;
81
+ var PICKER_SETTLE_MS = 700;
82
+ var PICKER_IDLE_MS = 18e4;
83
+ var isTrigger = (v) => typeof v === "string" && TRIGGERS.includes(v);
84
+ function createDebounce(gapMs = 1500, now = Date.now) {
85
+ let last = -Infinity;
86
+ return {
87
+ allow(open2) {
88
+ const t = now();
89
+ if (open2 || t - last < gapMs) return false;
90
+ last = t;
91
+ return true;
92
+ }
93
+ };
94
+ }
95
+ var parseReportButton = (json2) => !!json2 && typeof json2 === "object" && json2.report_button === true;
96
+ function userHeaders(user) {
97
+ const out = {};
98
+ if (user?.id) out["X-Blipit-User-Id"] = user.id;
99
+ if (user?.email) out["X-Blipit-User-Email"] = user.email;
100
+ return out;
101
+ }
102
+ function pickerSize(width, height, side = PICKER_SIDE) {
103
+ const scale = Math.min(1, side / Math.max(width, height, 1));
104
+ return { width: Math.max(1, Math.round(width * scale)), height: Math.max(1, Math.round(height * scale)) };
105
+ }
106
+ var ScreenShots = class {
107
+ items = [];
108
+ hiddenAt = 0;
109
+ add(shot) {
110
+ this.items = [shot, ...this.items.filter((s2) => s2.name !== shot.name)].slice(0, PICKER_MAX);
111
+ }
112
+ list(except) {
113
+ return this.items.filter((s2) => s2.name !== except);
114
+ }
115
+ clear() {
116
+ this.items = [];
117
+ }
118
+ background(at) {
119
+ this.hiddenAt = at;
120
+ }
121
+ foreground(at) {
122
+ if (this.hiddenAt && at - this.hiddenAt >= PICKER_IDLE_MS) this.clear();
123
+ this.hiddenAt = 0;
124
+ }
125
+ };
126
+ function lastFatal(queue) {
127
+ for (let i = queue.length - 1; i >= 0; i--) {
128
+ const e = queue[i];
129
+ 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;
130
+ }
131
+ return void 0;
132
+ }
133
+
51
134
  // src/nuggets.ts
52
- var VERSION = "0.5.0";
135
+ var VERSION = "0.6.0";
53
136
  var SDK_NAME = "@blipit/react-native";
54
137
  var DEFAULT_ENDPOINT = "https://in.blipit.io";
55
138
  var CATEGORIES = /* @__PURE__ */ new Set(["ui.click", "ui.input", "navigation", "http", "console", "query", "custom"]);
@@ -93,6 +176,7 @@ var Nuggets = class {
93
176
  user;
94
177
  tags = {};
95
178
  lastEventId;
179
+ crashId;
96
180
  enabled;
97
181
  onError;
98
182
  crumbs = [];
@@ -109,13 +193,14 @@ var Nuggets = class {
109
193
  this.endpoint = (options.endpoint ?? DEFAULT_ENDPOINT).replace(/\/api\/v1\/events.*$/, "").replace(/\/+$/, "");
110
194
  this.key = options.key;
111
195
  this.enabled = options.enabled !== false;
112
- this.fetcher = options.fetch ?? ((...a) => fetch(...a));
196
+ this.fetcher = guardPlatform(options.fetch ?? ((...a) => fetch(...a)));
113
197
  this.now = options.now ?? Date.now;
114
198
  try {
115
199
  const saved = JSON.parse(options.store?.load() ?? "[]");
116
200
  if (Array.isArray(saved)) this.queue = saved.slice(-QUEUE_MAX);
117
201
  } catch {
118
202
  }
203
+ this.crashId = lastFatal(this.queue);
119
204
  }
120
205
  get pending() {
121
206
  return this.queue.length;
@@ -346,11 +431,11 @@ function instrument(core2, g = globalThis) {
346
431
  }
347
432
  const proto = g.XMLHttpRequest?.prototype;
348
433
  if (proto?.open && proto.send) {
349
- const open = proto.open;
434
+ const open2 = proto.open;
350
435
  const send = proto.send;
351
436
  proto.open = function(method, url, ...rest) {
352
437
  this._blipit = [String(method).toUpperCase(), String(url)];
353
- return open.call(this, method, url, ...rest);
438
+ return open2.call(this, method, url, ...rest);
354
439
  };
355
440
  proto.send = function(...args) {
356
441
  const meta = this._blipit;
@@ -393,6 +478,16 @@ function json(v) {
393
478
 
394
479
  // src/native.ts
395
480
  var import_react_native = require("react-native");
481
+ function onNativeTrigger(handle) {
482
+ const b = bridge();
483
+ if (!b) return void 0;
484
+ try {
485
+ const sub = new import_react_native.NativeEventEmitter(b).addListener("BlipitReportTrigger", (e) => handle(e?.trigger, e?.crashId));
486
+ return () => sub.remove();
487
+ } catch {
488
+ return void 0;
489
+ }
490
+ }
396
491
  var bridge = () => import_react_native.NativeModules.BlipitNuggets;
397
492
  function nativeInfo() {
398
493
  const b = bridge();
@@ -484,7 +579,15 @@ var REPORT_STRINGS = {
484
579
  "recError": "The recording could not be made. You can still send the report.",
485
580
  "uploadingVideo": "Uploading recording\u2026",
486
581
  "close": "Close",
487
- "noShot": "The screenshot could not be taken. You can still send the report."
582
+ "noShot": "The screenshot could not be taken. You can still send the report.",
583
+ "shotAsk": "Report a bug with this screen?",
584
+ "report": "Report",
585
+ "notNow": "Not now",
586
+ "crashAsk": "The app closed unexpectedly. Tell us what you were doing?",
587
+ "tellUs": "Tell us",
588
+ "pickTitle": "Which screen is the bug on?",
589
+ "pickNow": "Current screen",
590
+ "pickBefore": "Earlier screen"
488
591
  },
489
592
  "ar": {
490
593
  "title": "\u0627\u0644\u0625\u0628\u0644\u0627\u063A \u0639\u0646 \u062E\u0637\u0623",
@@ -517,7 +620,15 @@ var REPORT_STRINGS = {
517
620
  "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.",
518
621
  "uploadingVideo": "\u062C\u0627\u0631\u064D \u0631\u0641\u0639 \u0627\u0644\u062A\u0633\u062C\u064A\u0644\u2026",
519
622
  "close": "\u0625\u063A\u0644\u0627\u0642",
520
- "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."
623
+ "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.",
624
+ "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",
625
+ "report": "\u0625\u0628\u0644\u0627\u063A",
626
+ "notNow": "\u0644\u064A\u0633 \u0627\u0644\u0622\u0646",
627
+ "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",
628
+ "tellUs": "\u0623\u062E\u0628\u0631\u0646\u0627",
629
+ "pickTitle": "\u0641\u064A \u0623\u064A \u0634\u0627\u0634\u0629 \u064A\u0638\u0647\u0631 \u0627\u0644\u062E\u0637\u0623\u061F",
630
+ "pickNow": "\u0627\u0644\u0634\u0627\u0634\u0629 \u0627\u0644\u062D\u0627\u0644\u064A\u0629",
631
+ "pickBefore": "\u0634\u0627\u0634\u0629 \u0633\u0627\u0628\u0642\u0629"
521
632
  },
522
633
  "de": {
523
634
  "title": "Fehler melden",
@@ -550,7 +661,15 @@ var REPORT_STRINGS = {
550
661
  "recError": "Die Aufnahme konnte nicht erstellt werden. Sie k\xF6nnen den Bericht trotzdem senden.",
551
662
  "uploadingVideo": "Aufnahme wird hochgeladen\u2026",
552
663
  "close": "Schlie\xDFen",
553
- "noShot": "Der Screenshot konnte nicht erstellt werden. Sie k\xF6nnen die Meldung trotzdem senden."
664
+ "noShot": "Der Screenshot konnte nicht erstellt werden. Sie k\xF6nnen die Meldung trotzdem senden.",
665
+ "shotAsk": "Einen Fehler mit diesem Bildschirm melden?",
666
+ "report": "Melden",
667
+ "notNow": "Nicht jetzt",
668
+ "crashAsk": "Die App wurde unerwartet beendet. M\xF6chten Sie uns sagen, was Sie gerade getan haben?",
669
+ "tellUs": "Erz\xE4hlen",
670
+ "pickTitle": "Auf welchem Bildschirm ist der Fehler?",
671
+ "pickNow": "Aktueller Bildschirm",
672
+ "pickBefore": "Fr\xFCherer Bildschirm"
554
673
  },
555
674
  "es": {
556
675
  "title": "Reportar un error",
@@ -583,7 +702,15 @@ var REPORT_STRINGS = {
583
702
  "recError": "No se pudo hacer la grabaci\xF3n. A\xFAn puedes enviar el informe.",
584
703
  "uploadingVideo": "Subiendo grabaci\xF3n\u2026",
585
704
  "close": "Cerrar",
586
- "noShot": "No se pudo tomar la captura. Aun as\xED puedes enviar el reporte."
705
+ "noShot": "No se pudo tomar la captura. Aun as\xED puedes enviar el reporte.",
706
+ "shotAsk": "\xBFInformar de un error con esta pantalla?",
707
+ "report": "Informar",
708
+ "notNow": "Ahora no",
709
+ "crashAsk": "La aplicaci\xF3n se cerr\xF3 inesperadamente. \xBFNos cuenta qu\xE9 estaba haciendo?",
710
+ "tellUs": "Contarlo",
711
+ "pickTitle": "\xBFEn qu\xE9 pantalla est\xE1 el error?",
712
+ "pickNow": "Pantalla actual",
713
+ "pickBefore": "Pantalla anterior"
587
714
  },
588
715
  "fr": {
589
716
  "title": "Signaler un bug",
@@ -616,7 +743,15 @@ var REPORT_STRINGS = {
616
743
  "recError": "L\u2019enregistrement n\u2019a pas pu \xEAtre effectu\xE9. Vous pouvez quand m\xEAme envoyer le rapport.",
617
744
  "uploadingVideo": "Envoi de l\u2019enregistrement\u2026",
618
745
  "close": "Fermer",
619
- "noShot": "La capture d\u2019\xE9cran a \xE9chou\xE9. Vous pouvez quand m\xEAme envoyer le signalement."
746
+ "noShot": "La capture d\u2019\xE9cran a \xE9chou\xE9. Vous pouvez quand m\xEAme envoyer le signalement.",
747
+ "shotAsk": "Signaler un bug avec cet \xE9cran ?",
748
+ "report": "Signaler",
749
+ "notNow": "Plus tard",
750
+ "crashAsk": "L\u2019application s\u2019est ferm\xE9e de fa\xE7on inattendue. Dites-nous ce que vous faisiez ?",
751
+ "tellUs": "Raconter",
752
+ "pickTitle": "Sur quel \xE9cran se trouve le bug ?",
753
+ "pickNow": "\xC9cran actuel",
754
+ "pickBefore": "\xC9cran pr\xE9c\xE9dent"
620
755
  },
621
756
  "it": {
622
757
  "title": "Segnala un bug",
@@ -649,7 +784,15 @@ var REPORT_STRINGS = {
649
784
  "recError": "Non \xE8 stato possibile registrare. Puoi comunque inviare la segnalazione.",
650
785
  "uploadingVideo": "Caricamento della registrazione\u2026",
651
786
  "close": "Chiudi",
652
- "noShot": "Non \xE8 stato possibile acquisire lo screenshot. Puoi comunque inviare la segnalazione."
787
+ "noShot": "Non \xE8 stato possibile acquisire lo screenshot. Puoi comunque inviare la segnalazione.",
788
+ "shotAsk": "Segnalare un bug con questa schermata?",
789
+ "report": "Segnala",
790
+ "notNow": "Non ora",
791
+ "crashAsk": "L\u2019app si \xE8 chiusa in modo imprevisto. Ci dice cosa stava facendo?",
792
+ "tellUs": "Racconta",
793
+ "pickTitle": "In quale schermata si trova il bug?",
794
+ "pickNow": "Schermata attuale",
795
+ "pickBefore": "Schermata precedente"
653
796
  },
654
797
  "ja": {
655
798
  "title": "\u4E0D\u5177\u5408\u3092\u5831\u544A",
@@ -682,7 +825,15 @@ var REPORT_STRINGS = {
682
825
  "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",
683
826
  "uploadingVideo": "\u9332\u753B\u3092\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u4E2D\u2026",
684
827
  "close": "\u9589\u3058\u308B",
685
- "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"
828
+ "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",
829
+ "shotAsk": "\u3053\u306E\u753B\u9762\u3067\u4E0D\u5177\u5408\u3092\u5831\u544A\u3057\u307E\u3059\u304B\uFF1F",
830
+ "report": "\u5831\u544A\u3059\u308B",
831
+ "notNow": "\u4ECA\u306F\u3057\u306A\u3044",
832
+ "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",
833
+ "tellUs": "\u4F1D\u3048\u308B",
834
+ "pickTitle": "\u4E0D\u5177\u5408\u304C\u3042\u308B\u306E\u306F\u3069\u306E\u753B\u9762\u3067\u3059\u304B\uFF1F",
835
+ "pickNow": "\u73FE\u5728\u306E\u753B\u9762",
836
+ "pickBefore": "\u524D\u306E\u753B\u9762"
686
837
  },
687
838
  "nl": {
688
839
  "title": "Bug melden",
@@ -715,7 +866,15 @@ var REPORT_STRINGS = {
715
866
  "recError": "De opname kon niet worden gemaakt. Je kunt het rapport nog steeds versturen.",
716
867
  "uploadingVideo": "Opname uploaden\u2026",
717
868
  "close": "Sluiten",
718
- "noShot": "De schermafbeelding kon niet worden gemaakt. Je kunt de melding toch versturen."
869
+ "noShot": "De schermafbeelding kon niet worden gemaakt. Je kunt de melding toch versturen.",
870
+ "shotAsk": "Een bug melden met dit scherm?",
871
+ "report": "Melden",
872
+ "notNow": "Niet nu",
873
+ "crashAsk": "De app is onverwacht gesloten. Vertelt u ons wat u aan het doen was?",
874
+ "tellUs": "Vertellen",
875
+ "pickTitle": "Op welk scherm zit de bug?",
876
+ "pickNow": "Huidig scherm",
877
+ "pickBefore": "Eerder scherm"
719
878
  },
720
879
  "pt": {
721
880
  "title": "Reportar um erro",
@@ -748,7 +907,15 @@ var REPORT_STRINGS = {
748
907
  "recError": "N\xE3o foi poss\xEDvel gravar. Voc\xEA ainda pode enviar o relat\xF3rio.",
749
908
  "uploadingVideo": "Enviando grava\xE7\xE3o\u2026",
750
909
  "close": "Fechar",
751
- "noShot": "N\xE3o foi poss\xEDvel fazer a captura. Voc\xEA ainda pode enviar o relat\xF3rio."
910
+ "noShot": "N\xE3o foi poss\xEDvel fazer a captura. Voc\xEA ainda pode enviar o relat\xF3rio.",
911
+ "shotAsk": "Reportar um erro com esta tela?",
912
+ "report": "Reportar",
913
+ "notNow": "Agora n\xE3o",
914
+ "crashAsk": "O app fechou inesperadamente. Conte o que voc\xEA estava fazendo?",
915
+ "tellUs": "Contar",
916
+ "pickTitle": "Em qual tela est\xE1 o erro?",
917
+ "pickNow": "Tela atual",
918
+ "pickBefore": "Tela anterior"
752
919
  },
753
920
  "tr": {
754
921
  "title": "Hata bildir",
@@ -781,7 +948,15 @@ var REPORT_STRINGS = {
781
948
  "recError": "Kay\u0131t yap\u0131lamad\u0131. Raporu yine de g\xF6nderebilirsiniz.",
782
949
  "uploadingVideo": "Kay\u0131t y\xFCkleniyor\u2026",
783
950
  "close": "Kapat",
784
- "noShot": "Ekran g\xF6r\xFCnt\xFCs\xFC al\u0131namad\u0131. Bildirimi yine de g\xF6nderebilirsiniz."
951
+ "noShot": "Ekran g\xF6r\xFCnt\xFCs\xFC al\u0131namad\u0131. Bildirimi yine de g\xF6nderebilirsiniz.",
952
+ "shotAsk": "Bu ekranla bir hata bildirilsin mi?",
953
+ "report": "Bildir",
954
+ "notNow": "\u015Eimdi de\u011Fil",
955
+ "crashAsk": "Uygulama beklenmedik \u015Fekilde kapand\u0131. Ne yapt\u0131\u011F\u0131n\u0131z\u0131 bize anlat\u0131r m\u0131s\u0131n\u0131z?",
956
+ "tellUs": "Anlat",
957
+ "pickTitle": "Hata hangi ekranda?",
958
+ "pickNow": "Ge\xE7erli ekran",
959
+ "pickBefore": "\xD6nceki ekran"
785
960
  },
786
961
  "zh": {
787
962
  "title": "\u62A5\u544A\u95EE\u9898",
@@ -814,7 +989,15 @@ var REPORT_STRINGS = {
814
989
  "recError": "\u65E0\u6CD5\u5B8C\u6210\u5F55\u5236\u3002\u4F60\u4ECD\u7136\u53EF\u4EE5\u53D1\u9001\u62A5\u544A\u3002",
815
990
  "uploadingVideo": "\u6B63\u5728\u4E0A\u4F20\u5F55\u5236\u5185\u5BB9\u2026",
816
991
  "close": "\u5173\u95ED",
817
- "noShot": "\u65E0\u6CD5\u622A\u53D6\u5C4F\u5E55\u3002\u60A8\u4ECD\u7136\u53EF\u4EE5\u53D1\u9001\u62A5\u544A\u3002"
992
+ "noShot": "\u65E0\u6CD5\u622A\u53D6\u5C4F\u5E55\u3002\u60A8\u4ECD\u7136\u53EF\u4EE5\u53D1\u9001\u62A5\u544A\u3002",
993
+ "shotAsk": "\u8981\u7528\u6B64\u5C4F\u5E55\u62A5\u544A\u95EE\u9898\u5417\uFF1F",
994
+ "report": "\u62A5\u544A",
995
+ "notNow": "\u4EE5\u540E\u518D\u8BF4",
996
+ "crashAsk": "\u5E94\u7528\u610F\u5916\u5173\u95ED\u3002\u80FD\u544A\u8BC9\u6211\u4EEC\u4F60\u5F53\u65F6\u5728\u505A\u4EC0\u4E48\u5417\uFF1F",
997
+ "tellUs": "\u544A\u8BC9\u6211\u4EEC",
998
+ "pickTitle": "\u95EE\u9898\u51FA\u73B0\u5728\u54EA\u4E2A\u5C4F\u5E55\uFF1F",
999
+ "pickNow": "\u5F53\u524D\u5C4F\u5E55",
1000
+ "pickBefore": "\u4E4B\u524D\u7684\u5C4F\u5E55"
818
1001
  }
819
1002
  };
820
1003
 
@@ -855,6 +1038,7 @@ function feedbackBody(input) {
855
1038
  };
856
1039
  if (input.title.trim()) body.title = input.title.trim();
857
1040
  if (input.email?.trim()) body.email = input.email.trim();
1041
+ if (input.eventId && /^[0-9a-f]{32}$/.test(input.eventId)) body.event_id = input.eventId;
858
1042
  if (input.image) {
859
1043
  const list = annotations(input.shapes ?? [], input.image.width, input.image.height);
860
1044
  if (list.length) body.annotations = [{ position: 0, shapes: list }];
@@ -868,7 +1052,7 @@ var ReportClient = class {
868
1052
  constructor(endpoint, key, fetcher = (...a) => fetch(...a)) {
869
1053
  this.endpoint = endpoint.replace(/\/+$/, "");
870
1054
  this.key = key;
871
- this.fetcher = fetcher;
1055
+ this.fetcher = guardPlatform(fetcher);
872
1056
  }
873
1057
  async call(path, init2) {
874
1058
  const res = await this.fetcher(`${this.endpoint}${path}`, { ...init2, headers: { "X-Blipit-Key": this.key, ...init2.headers } });
@@ -876,8 +1060,8 @@ var ReportClient = class {
876
1060
  if (!res.ok) throw new Error(`Blipit returned ${res.status}`);
877
1061
  return text2;
878
1062
  }
879
- async settings() {
880
- return JSON.parse(await this.call("/api/v1/feedback/settings", { method: "GET" }));
1063
+ async settings(user) {
1064
+ return JSON.parse(await this.call("/api/v1/feedback/settings", { method: "GET", headers: userHeaders(user) }));
881
1065
  }
882
1066
  async event(body) {
883
1067
  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) });
@@ -1074,13 +1258,46 @@ var import_jsx_runtime = require("react/jsx-runtime");
1074
1258
  var C = { navy: "#0B1A3A", card: "#1A2135", brand: "#3882F6", muted: "#98A6BE", mark: "#FF3B30", danger: "#FF7A6E", white: "#FFFFFF" };
1075
1259
  var opener = null;
1076
1260
  var config = null;
1077
- function configureReporter(client, device) {
1078
- config = { client, device };
1261
+ var open = false;
1262
+ var serverButton = false;
1263
+ var onServerButton = null;
1264
+ var currentScreen;
1265
+ var settle;
1266
+ var debounce = createDebounce();
1267
+ var screens = new ScreenShots();
1268
+ function configureReporter(client, device, o = { picker: true }) {
1269
+ config = { client, device, picker: o.picker };
1270
+ if (!o.picker) screens.clear();
1079
1271
  }
1080
1272
  function showReport() {
1081
1273
  if (!config) console.warn("[blipit] call Blipit.init before showReport");
1082
1274
  else if (!opener) console.warn("[blipit] wrap your app in <BlipitReporter> to use showReport");
1083
- else opener();
1275
+ else opener({ picker: config.picker, crashId: null });
1276
+ }
1277
+ function reportTrigger(trigger, crashId) {
1278
+ if (!config || !opener || !debounce.allow(open)) return;
1279
+ opener({ picker: false, crashId: trigger === "crash" ? crashId : null });
1280
+ }
1281
+ function setServerButton(on) {
1282
+ serverButton = on;
1283
+ onServerButton?.(on);
1284
+ }
1285
+ function noteScreen(name) {
1286
+ if (!name || !config?.picker) return;
1287
+ currentScreen = name;
1288
+ if (settle) clearTimeout(settle);
1289
+ settle = setTimeout(async () => {
1290
+ settle = void 0;
1291
+ const shooter = viewShot();
1292
+ if (open || !shooter || currentScreen !== name || !config?.picker) return;
1293
+ try {
1294
+ const { width, height } = import_react_native2.Dimensions.get("window");
1295
+ const size = pickerSize(width, height);
1296
+ const uri = await shooter.captureScreen({ format: "jpg", quality: 0.6, result: "data-uri", ...size });
1297
+ if (!open && currentScreen === name && config?.picker) screens.add({ name, uri, ...size });
1298
+ } catch {
1299
+ }
1300
+ }, PICKER_SETTLE_MS);
1084
1301
  }
1085
1302
  function viewShot() {
1086
1303
  try {
@@ -1103,19 +1320,32 @@ function BlipitReporter({ children, showButton = false }) {
1103
1320
  const [shot, setShot] = (0, import_react2.useState)(null);
1104
1321
  const [flat, setFlat] = (0, import_react2.useState)(null);
1105
1322
  const [notice, setNotice] = (0, import_react2.useState)(null);
1323
+ const [wantPicker, setWantPicker] = (0, import_react2.useState)(false);
1324
+ const [crashId, setCrashId] = (0, import_react2.useState)(null);
1325
+ const [earlier, setEarlier] = (0, import_react2.useState)([]);
1326
+ const [server, setServer] = (0, import_react2.useState)(serverButton);
1106
1327
  const shapes = (0, import_react2.useRef)([]);
1107
1328
  (0, import_react2.useEffect)(() => {
1108
- opener = () => {
1329
+ opener = (o) => {
1109
1330
  shapes.current = [];
1110
1331
  setShot(null);
1111
1332
  setFlat(null);
1112
1333
  setNotice(null);
1334
+ setEarlier([]);
1335
+ setWantPicker(o.picker);
1336
+ setCrashId(o.crashId);
1113
1337
  setStage("choice");
1114
1338
  };
1339
+ onServerButton = setServer;
1340
+ setServer(serverButton);
1115
1341
  return () => {
1116
1342
  opener = null;
1343
+ onServerButton = null;
1117
1344
  };
1118
1345
  }, []);
1346
+ (0, import_react2.useEffect)(() => {
1347
+ open = stage !== "closed";
1348
+ }, [stage]);
1119
1349
  const capture = async () => {
1120
1350
  const shooter = viewShot();
1121
1351
  setStage("closed");
@@ -1125,7 +1355,9 @@ function BlipitReporter({ children, showButton = false }) {
1125
1355
  const uri = await shooter.captureScreen({ format: "jpg", quality: 0.9, result: "tmpfile" });
1126
1356
  const size = await new Promise((ok, fail) => import_react_native2.Image.getSize(uri, (width, height) => ok({ width, height }), fail));
1127
1357
  setShot({ uri, ...size });
1128
- setStage("editor");
1358
+ const before = wantPicker ? screens.list(currentScreen) : [];
1359
+ setEarlier(before);
1360
+ setStage(before.length ? "pick" : "editor");
1129
1361
  } catch (err) {
1130
1362
  if (!shooter) console.warn("[blipit] install react-native-view-shot to attach screenshots to bug reports");
1131
1363
  setNotice(t("noShot"));
@@ -1134,7 +1366,7 @@ function BlipitReporter({ children, showButton = false }) {
1134
1366
  };
1135
1367
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: { flex: 1 }, children: [
1136
1368
  children,
1137
- showButton && stage === "closed" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.Pressable, { accessibilityRole: "button", accessibilityLabel: t("title"), onPress: () => opener?.(), style: ({ pressed }) => [s.fab, pressed && { opacity: 0.85 }], children: [
1369
+ (showButton || server) && stage === "closed" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.Pressable, { accessibilityRole: "button", accessibilityLabel: t("title"), onPress: showReport, style: ({ pressed }) => [s.fab, pressed && { opacity: 0.85 }], children: [
1138
1370
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.fabIcon, children: "!" }),
1139
1371
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.fabText, children: t("title") })
1140
1372
  ] }) : null,
@@ -1157,6 +1389,28 @@ function BlipitReporter({ children, showButton = false }) {
1157
1389
  )
1158
1390
  ] })
1159
1391
  ] }) : null,
1392
+ stage === "pick" && shot ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native2.View, { style: s.pad, children: [
1393
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Bar, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BarButton, { label: t("mBack"), glyph: "\u2039", onPress: () => setStage("choice") }) }),
1394
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.h1, children: t("pickTitle") }),
1395
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.ScrollView, { contentContainerStyle: s.thumbs, children: [shot, ...earlier].map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1396
+ import_react_native2.Pressable,
1397
+ {
1398
+ accessibilityRole: "button",
1399
+ accessibilityLabel: i === 0 ? t("pickNow") : t("pickBefore"),
1400
+ onPress: () => {
1401
+ setShot(item);
1402
+ setEarlier([]);
1403
+ setStage("editor");
1404
+ },
1405
+ style: ({ pressed }) => [s.thumb, pressed && { opacity: 0.85 }],
1406
+ children: [
1407
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Image, { source: { uri: item.uri }, style: [s.thumbImage, { aspectRatio: item.width / Math.max(1, item.height) }], resizeMode: "contain", accessibilityIgnoresInvertColors: true }),
1408
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: s.thumbText, numberOfLines: 1, children: i === 0 ? t("pickNow") : t("pickBefore") })
1409
+ ]
1410
+ },
1411
+ i
1412
+ )) })
1413
+ ] }) : null,
1160
1414
  stage === "editor" && shot ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1161
1415
  Editor,
1162
1416
  {
@@ -1179,6 +1433,7 @@ function BlipitReporter({ children, showButton = false }) {
1179
1433
  flat,
1180
1434
  shapes: shapes.current,
1181
1435
  notice,
1436
+ eventId: crashId,
1182
1437
  onBack: () => setStage(shot ? "editor" : "choice"),
1183
1438
  onDone: () => setStage("closed")
1184
1439
  }
@@ -1308,7 +1563,7 @@ function Editor({ shot, shapes, t, onBack, onNext }) {
1308
1563
  await new Promise((r) => setTimeout(r, 80));
1309
1564
  let out = shot;
1310
1565
  const shooter = viewShot();
1311
- if (shapes.current.length && shooter && content.current) {
1566
+ if ((shapes.current.length || shot.uri.startsWith("data:")) && shooter && content.current) {
1312
1567
  try {
1313
1568
  const uri = await shooter.captureRef(content.current, { format: "jpg", quality: 0.85, result: "tmpfile" });
1314
1569
  out = { uri, width: shot.width, height: shot.height };
@@ -1411,7 +1666,7 @@ function ToolButton({ label, glyph, on, onPress }) {
1411
1666
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native2.Text, { style: [s.toolText, { color: on ? C.white : C.muted }], numberOfLines: 1, children: label })
1412
1667
  ] });
1413
1668
  }
1414
- function Details({ t, lang, shot, flat, shapes, notice, onBack, onDone }) {
1669
+ function Details({ t, lang, shot, flat, shapes, notice, eventId, onBack, onDone }) {
1415
1670
  const [title, setTitle] = (0, import_react2.useState)("");
1416
1671
  const [message, setMessage] = (0, import_react2.useState)("");
1417
1672
  const [email, setEmail] = (0, import_react2.useState)("");
@@ -1427,7 +1682,7 @@ function Details({ t, lang, shot, flat, shapes, notice, onBack, onDone }) {
1427
1682
  setBusy(true);
1428
1683
  setStatus({ text: t("sending"), error: false });
1429
1684
  try {
1430
- const receipt = await config.client.send(feedbackBody({ title, message: message.trim(), email, context: config.device(), shapes, image: shot, screenshots: image ? 1 : 0, locale: lang }));
1685
+ 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 }));
1431
1686
  let uploaded = true;
1432
1687
  if (image) {
1433
1688
  try {
@@ -1486,6 +1741,10 @@ var s = import_react_native2.StyleSheet.create({
1486
1741
  tool: { flex: 1, height: 60, alignItems: "center", justifyContent: "center", borderRadius: 12, marginHorizontal: 2 },
1487
1742
  toolGlyph: { fontSize: 20 },
1488
1743
  toolText: { fontSize: 11, marginTop: 2 },
1744
+ thumbs: { flexDirection: "row", flexWrap: "wrap", gap: 12, paddingVertical: 12 },
1745
+ thumb: { width: "47%", backgroundColor: C.card, borderRadius: 14, borderWidth: 1, borderColor: "rgba(255,255,255,0.1)", padding: 8, gap: 8 },
1746
+ thumbImage: { width: "100%", borderRadius: 8, backgroundColor: C.navy },
1747
+ thumbText: { color: C.white, fontSize: 14, fontWeight: "600", textAlign: "center" },
1489
1748
  preview: { height: 150, borderRadius: 12, backgroundColor: C.card },
1490
1749
  input: { backgroundColor: C.card, borderRadius: 12, color: C.white, fontSize: 16, paddingHorizontal: 14, paddingVertical: 12, minHeight: 48 },
1491
1750
  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 } },
@@ -1501,7 +1760,7 @@ var core;
1501
1760
  var session;
1502
1761
  var appState;
1503
1762
  function init(options) {
1504
- const { key, publicKey, project, endpoint, waitForReady, ...rest } = options ?? {};
1763
+ const { key, publicKey, project, endpoint, waitForReady, shakeToReport, screenshotToReport, twoFingerReport, reportAfterCrash, screenPicker, ...rest } = options ?? {};
1505
1764
  const k = (key ?? publicKey ?? "").trim();
1506
1765
  if (!k) {
1507
1766
  console.warn(MISSING_KEY);
@@ -1521,26 +1780,42 @@ function init(options) {
1521
1780
  setBoundaryReporter((error) => c.captureException(error, false));
1522
1781
  instrument(() => core);
1523
1782
  const native = rest.enableNative !== false ? bridge() : void 0;
1783
+ if (native && !triggerOff) triggerOff = onNativeTrigger((trigger, crashId) => isTrigger(trigger) && reportTrigger(trigger, typeof crashId === "string" ? crashId : null));
1524
1784
  try {
1525
- native?.start(k, String(project), rest.environment ?? null, release ?? null, c.endpoint);
1785
+ native?.start(k, String(project), rest.environment ?? null, release ?? null, c.endpoint, {
1786
+ shakeToReport: shakeToReport === true,
1787
+ screenshotToReport: screenshotToReport === true,
1788
+ twoFingerReport: twoFingerReport === true,
1789
+ reportAfterCrash: reportAfterCrash === true,
1790
+ screenPicker: false
1791
+ });
1526
1792
  } catch {
1527
1793
  }
1794
+ if (reportAfterCrash === true && c.crashId) {
1795
+ try {
1796
+ native?.promptAfterCrash?.(c.crashId);
1797
+ } catch {
1798
+ }
1799
+ }
1528
1800
  session = release && rest.autoSessionTracking !== false ? new Session(c, release, rest.environment ?? "production") : void 0;
1529
1801
  c.onError = (unhandled) => session?.markError(unhandled);
1530
1802
  if (c.enabled) session?.start();
1531
1803
  appState = import_react_native3.AppState?.addEventListener?.("change", (state) => {
1532
1804
  if (state === "active") {
1805
+ screens.foreground(Date.now());
1533
1806
  if (c.enabled) session?.start();
1534
1807
  void c.flush();
1535
1808
  } else if (state === "background") {
1809
+ screens.background(Date.now());
1536
1810
  session?.end();
1537
1811
  void c.flush();
1538
1812
  }
1539
1813
  });
1540
1814
  void c.flush();
1541
1815
  const reports = new ReportClient(base, k);
1542
- configureReporter(reports, () => deviceContext(release));
1816
+ configureReporter(reports, () => deviceContext(release), { picker: screenPicker !== false });
1543
1817
  reportClient = reports;
1818
+ refreshButton(0);
1544
1819
  if (!stuck) {
1545
1820
  stuck = createStuck(
1546
1821
  {
@@ -1562,6 +1837,33 @@ function init(options) {
1562
1837
  }
1563
1838
  var stuck = null;
1564
1839
  var reportClient;
1840
+ var triggerOff;
1841
+ var buttonTimer;
1842
+ var buttonBusy = false;
1843
+ var buttonAgain = false;
1844
+ function refreshButton(delay) {
1845
+ if (buttonTimer) clearTimeout(buttonTimer);
1846
+ buttonTimer = setTimeout(() => {
1847
+ buttonTimer = void 0;
1848
+ void fetchButton();
1849
+ }, delay);
1850
+ }
1851
+ async function fetchButton() {
1852
+ const client = reportClient;
1853
+ if (!client) return;
1854
+ if (buttonBusy) return void (buttonAgain = true);
1855
+ buttonBusy = true;
1856
+ try {
1857
+ setServerButton(parseReportButton(await client.settings(core?.user)));
1858
+ } catch {
1859
+ } finally {
1860
+ buttonBusy = false;
1861
+ if (buttonAgain) {
1862
+ buttonAgain = false;
1863
+ void fetchButton();
1864
+ }
1865
+ }
1866
+ }
1565
1867
  function reportReady() {
1566
1868
  stuck?.end(STARTUP);
1567
1869
  }
@@ -1627,6 +1929,7 @@ function setUser(user) {
1627
1929
  bridge()?.setUser(u?.id ?? null, u?.email ?? null, u?.username ?? null);
1628
1930
  } catch {
1629
1931
  }
1932
+ refreshButton(1e3);
1630
1933
  }
1631
1934
  function setTag(key, value) {
1632
1935
  core?.setTag(key, value);
@@ -1650,6 +1953,7 @@ async function flush(timeout = 2e3) {
1650
1953
  function setEnabled(on) {
1651
1954
  if (!core) return;
1652
1955
  core.setEnabled(on);
1956
+ if (!on) screens.clear();
1653
1957
  if (on) session?.start();
1654
1958
  else session?.end();
1655
1959
  }
@@ -1668,7 +1972,18 @@ function hasReplayConsent() {
1668
1972
  return false;
1669
1973
  }
1670
1974
  }
1671
- var trackNavigation2 = (ref) => trackNavigation(() => core, ref);
1975
+ function trackNavigation2(ref) {
1976
+ const stop = trackNavigation(() => core, ref);
1977
+ const seen = () => {
1978
+ if (core?.enabled) noteScreen(ref.getCurrentRoute()?.name);
1979
+ };
1980
+ seen();
1981
+ const off = ref.addListener("state", seen);
1982
+ return () => {
1983
+ stop();
1984
+ off();
1985
+ };
1986
+ }
1672
1987
  // Annotate the CommonJS export names for ESM import in node:
1673
1988
  0 && (module.exports = {
1674
1989
  BlipitReporter,