@blipit/react-native 0.4.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.js CHANGED
@@ -6,8 +6,505 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  });
7
7
 
8
8
  // src/index.ts
9
- import * as Sentry from "@sentry/react-native";
10
- 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
+ }
93
+
94
+ // src/nuggets.ts
95
+ var VERSION = "0.6.0";
96
+ var SDK_NAME = "@blipit/react-native";
97
+ var DEFAULT_ENDPOINT = "https://in.blipit.io";
98
+ var CATEGORIES = /* @__PURE__ */ new Set(["ui.click", "ui.input", "navigation", "http", "console", "query", "custom"]);
99
+ var CRUMB_LEVELS = /* @__PURE__ */ new Set(["error", "warning", "info", "debug"]);
100
+ var TAG_KEY = /[^a-zA-Z0-9_.-]/g;
101
+ var SENSITIVE = /\b((?:[a-zA-Z0-9_-]*(?:token|key|password|secret|auth|session|passwd|api)[a-zA-Z0-9_-]*)=)[^&\s"']+/gi;
102
+ var QUEUE_MAX = 30;
103
+ var truncate = (v, max) => v.length > max ? v.slice(0, max) : v;
104
+ var scrub = (text2) => text2.replace(SENSITIVE, "$1[redacted]");
105
+ function uuid32() {
106
+ let out = "";
107
+ for (let i = 0; i < 32; i++) out += Math.floor(Math.random() * 16).toString(16);
108
+ return `${out.slice(0, 12)}4${out.slice(13, 16)}${"89ab"[Math.floor(Math.random() * 4)]}${out.slice(17)}`;
109
+ }
110
+ var HERMES = /^\s*at (?:(.+?) \()?(?:address at )?(.+?):(\d+):(\d+)\)?\s*$/;
111
+ var JSC = /^\s*(?:(.*?)@)?(.+?):(\d+):(\d+)\s*$/;
112
+ function parseStack(stack) {
113
+ if (!stack) return [];
114
+ const frames = [];
115
+ for (const line of stack.split("\n")) {
116
+ const m = HERMES.exec(line) ?? (/^\s*at /.test(line) ? null : JSC.exec(line));
117
+ if (!m) continue;
118
+ const file = m[2].replace(/\?.*$/, "");
119
+ const frame = { filename: truncate(file, 1024), lineno: Number(m[3]), colno: Number(m[4]), in_app: !/node_modules|\[native code\]/.test(file) };
120
+ if (m[1]) frame.function = truncate(m[1], 512);
121
+ frames.push(frame);
122
+ }
123
+ return frames.reverse().slice(-128);
124
+ }
125
+ function cleanCrumb(c, at) {
126
+ const ts = typeof c.timestamp === "number" ? new Date(c.timestamp < 1e12 ? c.timestamp * 1e3 : c.timestamp).toISOString() : c.timestamp ?? at;
127
+ const out = { timestamp: ts, category: c.category && CATEGORIES.has(c.category) ? c.category : "custom" };
128
+ if (c.message) out.message = truncate(scrub(String(c.message)), 1024);
129
+ if (c.level && CRUMB_LEVELS.has(c.level)) out.level = c.level;
130
+ if (c.data && typeof c.data === "object") out.data = typeof c.data.url === "string" ? { ...c.data, url: scrub(c.data.url) } : c.data;
131
+ return out;
132
+ }
133
+ var Nuggets = class {
134
+ endpoint;
135
+ key;
136
+ user;
137
+ tags = {};
138
+ lastEventId;
139
+ crashId;
140
+ enabled;
141
+ onError;
142
+ crumbs = [];
143
+ queue = [];
144
+ captured = /* @__PURE__ */ new WeakSet();
145
+ timer;
146
+ sending;
147
+ pausedUntil = 0;
148
+ fetcher;
149
+ now;
150
+ options;
151
+ constructor(options) {
152
+ this.options = options;
153
+ this.endpoint = (options.endpoint ?? DEFAULT_ENDPOINT).replace(/\/api\/v1\/events.*$/, "").replace(/\/+$/, "");
154
+ this.key = options.key;
155
+ this.enabled = options.enabled !== false;
156
+ this.fetcher = guardPlatform(options.fetch ?? ((...a) => fetch(...a)));
157
+ this.now = options.now ?? Date.now;
158
+ try {
159
+ const saved = JSON.parse(options.store?.load() ?? "[]");
160
+ if (Array.isArray(saved)) this.queue = saved.slice(-QUEUE_MAX);
161
+ } catch {
162
+ }
163
+ this.crashId = lastFatal(this.queue);
164
+ }
165
+ get pending() {
166
+ return this.queue.length;
167
+ }
168
+ url(path) {
169
+ return `${this.endpoint}${path}`;
170
+ }
171
+ setEnabled(on) {
172
+ this.enabled = on;
173
+ if (!on) {
174
+ this.queue = [];
175
+ this.crumbs = [];
176
+ this.persist();
177
+ }
178
+ }
179
+ setUser(user) {
180
+ if (!user) return void (this.user = void 0);
181
+ const u = {};
182
+ if (user.id !== void 0 && user.id !== null) u.id = truncate(String(user.id), 128);
183
+ if (user.email) u.email = truncate(user.email, 256);
184
+ if (user.username) u.username = truncate(user.username, 128);
185
+ this.user = Object.keys(u).length ? u : void 0;
186
+ }
187
+ setTag(key, value) {
188
+ const k = truncate(String(key).replace(TAG_KEY, "_"), 64);
189
+ if (k && (k in this.tags || Object.keys(this.tags).length < 32)) this.tags[k] = truncate(String(value), 256);
190
+ }
191
+ addBreadcrumb(crumb) {
192
+ if (!this.enabled) return;
193
+ this.crumbs.push(cleanCrumb(crumb, new Date(this.now()).toISOString()));
194
+ const max = Math.min(this.options.maxBreadcrumbs ?? 50, 100);
195
+ while (this.crumbs.length > max) this.crumbs.shift();
196
+ }
197
+ captureException(error, handled = true, level = "error") {
198
+ if (error && typeof error === "object") {
199
+ if (this.captured.has(error)) return void 0;
200
+ this.captured.add(error);
201
+ }
202
+ const err = error instanceof Error ? error : new Error(typeof error === "string" ? error : safeJson(error));
203
+ const exception = { type: truncate(err.name || "Error", 256), value: truncate(scrub(err.message || String(err)), 4096), handled };
204
+ const frames = parseStack(err.stack);
205
+ if (frames.length) exception.stacktrace = { frames };
206
+ return this.capture({ exception, level });
207
+ }
208
+ captureMessage(message, level = "info") {
209
+ return this.capture({ message: truncate(scrub(String(message)), 8192), level });
210
+ }
211
+ captureSecurity(kind, message, level, security) {
212
+ return this.capture({ message: truncate(message, 8192), level, ...security ? { security } : {}, tags: { "security.kind": truncate(kind, 256) } }, false);
213
+ }
214
+ capture(partial, filter = true) {
215
+ if (!this.enabled) return void 0;
216
+ if (filter && this.options.sampleRate !== void 0 && Math.random() >= this.options.sampleRate) return void 0;
217
+ const text2 = partial.exception?.value ?? partial.message ?? "";
218
+ if (filter && (this.options.ignoreErrors ?? []).some((p) => typeof p === "string" ? text2.includes(p) : p.test(text2))) return void 0;
219
+ let event = {
220
+ event_id: uuid32(),
221
+ timestamp: new Date(this.now()).toISOString(),
222
+ platform: "react-native",
223
+ level: "error",
224
+ environment: this.options.environment ?? "production",
225
+ sdk: { name: SDK_NAME, version: VERSION },
226
+ ...partial
227
+ };
228
+ if (this.options.release) event.release = truncate(this.options.release, 256);
229
+ if (this.user) event.user = { ...this.user };
230
+ const tags = { ...this.tags, ...partial.tags };
231
+ if (Object.keys(tags).length) event.tags = tags;
232
+ if (this.crumbs.length) event.breadcrumbs = [...this.crumbs];
233
+ const contexts2 = this.options.contexts?.();
234
+ if (contexts2 && Object.keys(contexts2).length) event.contexts = contexts2;
235
+ if (this.options.beforeSend) {
236
+ const out = this.options.beforeSend(event);
237
+ if (!out) return void 0;
238
+ event = out;
239
+ }
240
+ this.enqueue(event);
241
+ this.lastEventId = event.event_id;
242
+ if (event.exception) this.onError?.(!event.exception.handled);
243
+ return event.event_id;
244
+ }
245
+ enqueue(event) {
246
+ if (!this.enabled) return false;
247
+ this.queue.push(event);
248
+ while (this.queue.length > QUEUE_MAX) this.queue.shift();
249
+ this.persist();
250
+ this.schedule(1e3);
251
+ return true;
252
+ }
253
+ persist() {
254
+ try {
255
+ this.options.store?.save(JSON.stringify(this.queue));
256
+ } catch {
257
+ }
258
+ }
259
+ schedule(ms) {
260
+ if (this.timer) return;
261
+ this.timer = setTimeout(() => {
262
+ this.timer = void 0;
263
+ void this.flush();
264
+ }, Math.max(ms, this.pausedUntil - this.now()));
265
+ this.timer.unref?.();
266
+ }
267
+ async flush() {
268
+ while (this.sending) await this.sending;
269
+ this.sending = this.drain().finally(() => this.sending = void 0);
270
+ return this.sending;
271
+ }
272
+ async drain() {
273
+ while (this.queue.length && this.enabled && this.now() >= this.pausedUntil) {
274
+ const event = this.queue[0];
275
+ const verdict = await this.send(event);
276
+ if (verdict === "retry") return this.schedule(3e4);
277
+ if (verdict === "wait") return this.schedule(0);
278
+ if (this.queue[0] === event) this.queue.shift();
279
+ this.persist();
280
+ }
281
+ }
282
+ post(path, body) {
283
+ return this.fetcher(this.url(path), { method: "POST", headers: { "Content-Type": "application/json", "X-Blipit-Key": this.key }, body: JSON.stringify(body) });
284
+ }
285
+ async send(event) {
286
+ try {
287
+ const res = await this.post("/api/v1/events", event);
288
+ if (res.status === 429) {
289
+ const header = Number(res.headers?.get?.("retry-after"));
290
+ let seconds = Number.isFinite(header) && header > 0 ? header : 0;
291
+ if (!seconds) {
292
+ try {
293
+ seconds = Number(JSON.parse(await res.text()).retry_after) || 60;
294
+ } catch {
295
+ seconds = 60;
296
+ }
297
+ }
298
+ this.pausedUntil = this.now() + Math.min(seconds, 3600) * 1e3;
299
+ return "wait";
300
+ }
301
+ if (res.status >= 500) return "retry";
302
+ if (res.status >= 400 && this.options.debug) console.warn("[blipit] event rejected", res.status);
303
+ return "done";
304
+ } catch {
305
+ return "retry";
306
+ }
307
+ }
308
+ };
309
+ var RANK = { ok: 0, errored: 1, crashed: 2 };
310
+ var Session = class {
311
+ sid = "";
312
+ started = "";
313
+ status = "ok";
314
+ errors = 0;
315
+ core;
316
+ release;
317
+ environment;
318
+ constructor(core2, release, environment) {
319
+ this.core = core2;
320
+ this.release = release;
321
+ this.environment = environment;
322
+ }
323
+ start() {
324
+ if (this.sid) return;
325
+ this.sid = uuid32();
326
+ this.started = (/* @__PURE__ */ new Date()).toISOString();
327
+ this.status = "ok";
328
+ this.errors = 0;
329
+ this.send(false);
330
+ }
331
+ end() {
332
+ if (!this.sid) return;
333
+ this.send(true);
334
+ this.sid = "";
335
+ }
336
+ markError(unhandled) {
337
+ if (!this.sid) return;
338
+ this.errors += 1;
339
+ const next = unhandled ? "crashed" : "errored";
340
+ if (RANK[next] <= RANK[this.status]) return;
341
+ this.status = next;
342
+ this.send(false);
343
+ }
344
+ send(ending) {
345
+ if (!this.core.enabled) return;
346
+ const did = this.core.user?.id ?? this.core.user?.email;
347
+ const status = this.status === "ok" && ending ? "exited" : this.status;
348
+ this.core.post("/api/v1/sessions", { sid: this.sid, did, status, errors: this.errors, started: this.started, release: this.release, environment: this.environment }).catch(() => void 0);
349
+ }
350
+ };
351
+ function safeJson(v) {
352
+ try {
353
+ return JSON.stringify(v) ?? String(v);
354
+ } catch {
355
+ return String(v);
356
+ }
357
+ }
358
+
359
+ // src/instrument.ts
360
+ var done = /* @__PURE__ */ new WeakSet();
361
+ function instrument(core2, g = globalThis) {
362
+ if (done.has(g)) return;
363
+ done.add(g);
364
+ const eu = g.ErrorUtils;
365
+ if (eu?.setGlobalHandler) {
366
+ const prev = eu.getGlobalHandler?.();
367
+ eu.setGlobalHandler((error, isFatal) => {
368
+ const c = core2();
369
+ c?.captureException(error, false, isFatal ? "fatal" : "error");
370
+ if (isFatal) void c?.flush();
371
+ prev?.(error, isFatal);
372
+ });
373
+ }
374
+ const onUnhandled = (_id, reason) => void core2()?.captureException(reason, false);
375
+ if (g.HermesInternal?.enablePromiseRejectionTracker) {
376
+ g.HermesInternal.enablePromiseRejectionTracker({ allRejections: true, onUnhandled });
377
+ } else {
378
+ try {
379
+ __require("promise/setimmediate/rejection-tracking").enable({ allRejections: true, onUnhandled });
380
+ } catch {
381
+ }
382
+ }
383
+ for (const level of ["warn", "error"]) {
384
+ const original = g.console[level];
385
+ if (typeof original !== "function") continue;
386
+ g.console[level] = (...args) => {
387
+ const message = truncate(args.map((a) => typeof a === "string" ? a : a instanceof Error ? a.message : json(a)).join(" "), 1024);
388
+ if (!message.startsWith("[blipit]")) core2()?.addBreadcrumb({ category: "console", level: level === "warn" ? "warning" : "error", message });
389
+ original.apply(g.console, args);
390
+ };
391
+ }
392
+ const proto = g.XMLHttpRequest?.prototype;
393
+ if (proto?.open && proto.send) {
394
+ const open2 = proto.open;
395
+ const send = proto.send;
396
+ proto.open = function(method, url, ...rest) {
397
+ this._blipit = [String(method).toUpperCase(), String(url)];
398
+ return open2.call(this, method, url, ...rest);
399
+ };
400
+ proto.send = function(...args) {
401
+ const meta = this._blipit;
402
+ const c = core2();
403
+ if (c && meta && !meta[1].startsWith(c.endpoint)) {
404
+ const start = Date.now();
405
+ this.addEventListener?.("loadend", () => {
406
+ const status = this.status;
407
+ const url = meta[1].replace(/[?#].*$/, "");
408
+ c.addBreadcrumb({
409
+ category: "http",
410
+ level: !status || status >= 400 ? "error" : "info",
411
+ message: `${meta[0]} ${url} -> ${status || "network error"}`,
412
+ data: { url, method: meta[0], status_code: status || void 0, duration_ms: Date.now() - start }
413
+ });
414
+ });
415
+ }
416
+ return send.apply(this, args);
417
+ };
418
+ }
419
+ }
420
+ function trackNavigation(core2, ref) {
421
+ let last;
422
+ const seen = () => {
423
+ const name = ref.getCurrentRoute()?.name;
424
+ if (!name || name === last) return;
425
+ core2()?.addBreadcrumb({ category: "navigation", message: `Navigated to ${name}`, data: { from: last, to: name } });
426
+ last = name;
427
+ };
428
+ seen();
429
+ return ref.addListener("state", seen);
430
+ }
431
+ function json(v) {
432
+ try {
433
+ return JSON.stringify(v) ?? String(v);
434
+ } catch {
435
+ return String(v);
436
+ }
437
+ }
438
+
439
+ // src/native.ts
440
+ import { NativeEventEmitter, NativeModules } from "react-native";
441
+ function onNativeTrigger(handle) {
442
+ const b = bridge();
443
+ if (!b) return void 0;
444
+ try {
445
+ const sub = new NativeEventEmitter(b).addListener("BlipitReportTrigger", (e) => handle(e?.trigger, e?.crashId));
446
+ return () => sub.remove();
447
+ } catch {
448
+ return void 0;
449
+ }
450
+ }
451
+ var bridge = () => NativeModules.BlipitNuggets;
452
+ function nativeInfo() {
453
+ const b = bridge();
454
+ try {
455
+ return b?.getConstants?.() ?? b ?? {};
456
+ } catch {
457
+ return {};
458
+ }
459
+ }
460
+ function nativeStore() {
461
+ const b = bridge();
462
+ if (!b?.save || !b.load) return void 0;
463
+ return {
464
+ load: () => {
465
+ try {
466
+ return b.load();
467
+ } catch {
468
+ return null;
469
+ }
470
+ },
471
+ save: (data) => void b.save(data)
472
+ };
473
+ }
474
+ function defaultRelease(info) {
475
+ if (!info.appId || !info.appVersion) return void 0;
476
+ return `${info.appId}@${info.appVersion}${info.appBuild ? `+${info.appBuild}` : ""}`;
477
+ }
478
+
479
+ // src/boundary.ts
480
+ import { Component, createElement } from "react";
481
+ var report = () => void 0;
482
+ function setBoundaryReporter(fn) {
483
+ report = fn;
484
+ }
485
+ var ErrorBoundary = class extends Component {
486
+ state = { error: null };
487
+ static getDerivedStateFromError(error) {
488
+ return { error };
489
+ }
490
+ componentDidCatch(error) {
491
+ const id = report(error);
492
+ this.props.onError?.(error, id);
493
+ }
494
+ resetError = () => this.setState({ error: null });
495
+ render() {
496
+ if (this.state.error === null) return this.props.children ?? null;
497
+ const { fallback } = this.props;
498
+ if (typeof fallback === "function") return fallback({ error: this.state.error, resetError: this.resetError });
499
+ if (fallback === void 0) throw this.state.error;
500
+ return fallback;
501
+ }
502
+ };
503
+ function wrap(Root, options = {}) {
504
+ const Wrapped = (props) => createElement(ErrorBoundary, options, createElement(Root, props));
505
+ Wrapped.displayName = `Blipit(${Root.displayName ?? Root.name ?? "App"})`;
506
+ return Wrapped;
507
+ }
11
508
 
12
509
  // src/report-strings.ts
13
510
  var REPORT_STRINGS = {
@@ -42,7 +539,15 @@ var REPORT_STRINGS = {
42
539
  "recError": "The recording could not be made. You can still send the report.",
43
540
  "uploadingVideo": "Uploading recording\u2026",
44
541
  "close": "Close",
45
- "noShot": "The screenshot could not be taken. You can still send the report."
542
+ "noShot": "The screenshot could not be taken. You can still send the report.",
543
+ "shotAsk": "Report a bug with this screen?",
544
+ "report": "Report",
545
+ "notNow": "Not now",
546
+ "crashAsk": "The app closed unexpectedly. Tell us what you were doing?",
547
+ "tellUs": "Tell us",
548
+ "pickTitle": "Which screen is the bug on?",
549
+ "pickNow": "Current screen",
550
+ "pickBefore": "Earlier screen"
46
551
  },
47
552
  "ar": {
48
553
  "title": "\u0627\u0644\u0625\u0628\u0644\u0627\u063A \u0639\u0646 \u062E\u0637\u0623",
@@ -75,7 +580,15 @@ var REPORT_STRINGS = {
75
580
  "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.",
76
581
  "uploadingVideo": "\u062C\u0627\u0631\u064D \u0631\u0641\u0639 \u0627\u0644\u062A\u0633\u062C\u064A\u0644\u2026",
77
582
  "close": "\u0625\u063A\u0644\u0627\u0642",
78
- "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."
583
+ "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
+ "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",
585
+ "report": "\u0625\u0628\u0644\u0627\u063A",
586
+ "notNow": "\u0644\u064A\u0633 \u0627\u0644\u0622\u0646",
587
+ "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",
588
+ "tellUs": "\u0623\u062E\u0628\u0631\u0646\u0627",
589
+ "pickTitle": "\u0641\u064A \u0623\u064A \u0634\u0627\u0634\u0629 \u064A\u0638\u0647\u0631 \u0627\u0644\u062E\u0637\u0623\u061F",
590
+ "pickNow": "\u0627\u0644\u0634\u0627\u0634\u0629 \u0627\u0644\u062D\u0627\u0644\u064A\u0629",
591
+ "pickBefore": "\u0634\u0627\u0634\u0629 \u0633\u0627\u0628\u0642\u0629"
79
592
  },
80
593
  "de": {
81
594
  "title": "Fehler melden",
@@ -108,7 +621,15 @@ var REPORT_STRINGS = {
108
621
  "recError": "Die Aufnahme konnte nicht erstellt werden. Sie k\xF6nnen den Bericht trotzdem senden.",
109
622
  "uploadingVideo": "Aufnahme wird hochgeladen\u2026",
110
623
  "close": "Schlie\xDFen",
111
- "noShot": "Der Screenshot konnte nicht erstellt werden. Sie k\xF6nnen die Meldung trotzdem senden."
624
+ "noShot": "Der Screenshot konnte nicht erstellt werden. Sie k\xF6nnen die Meldung trotzdem senden.",
625
+ "shotAsk": "Einen Fehler mit diesem Bildschirm melden?",
626
+ "report": "Melden",
627
+ "notNow": "Nicht jetzt",
628
+ "crashAsk": "Die App wurde unerwartet beendet. M\xF6chten Sie uns sagen, was Sie gerade getan haben?",
629
+ "tellUs": "Erz\xE4hlen",
630
+ "pickTitle": "Auf welchem Bildschirm ist der Fehler?",
631
+ "pickNow": "Aktueller Bildschirm",
632
+ "pickBefore": "Fr\xFCherer Bildschirm"
112
633
  },
113
634
  "es": {
114
635
  "title": "Reportar un error",
@@ -141,7 +662,15 @@ var REPORT_STRINGS = {
141
662
  "recError": "No se pudo hacer la grabaci\xF3n. A\xFAn puedes enviar el informe.",
142
663
  "uploadingVideo": "Subiendo grabaci\xF3n\u2026",
143
664
  "close": "Cerrar",
144
- "noShot": "No se pudo tomar la captura. Aun as\xED puedes enviar el reporte."
665
+ "noShot": "No se pudo tomar la captura. Aun as\xED puedes enviar el reporte.",
666
+ "shotAsk": "\xBFInformar de un error con esta pantalla?",
667
+ "report": "Informar",
668
+ "notNow": "Ahora no",
669
+ "crashAsk": "La aplicaci\xF3n se cerr\xF3 inesperadamente. \xBFNos cuenta qu\xE9 estaba haciendo?",
670
+ "tellUs": "Contarlo",
671
+ "pickTitle": "\xBFEn qu\xE9 pantalla est\xE1 el error?",
672
+ "pickNow": "Pantalla actual",
673
+ "pickBefore": "Pantalla anterior"
145
674
  },
146
675
  "fr": {
147
676
  "title": "Signaler un bug",
@@ -174,7 +703,15 @@ var REPORT_STRINGS = {
174
703
  "recError": "L\u2019enregistrement n\u2019a pas pu \xEAtre effectu\xE9. Vous pouvez quand m\xEAme envoyer le rapport.",
175
704
  "uploadingVideo": "Envoi de l\u2019enregistrement\u2026",
176
705
  "close": "Fermer",
177
- "noShot": "La capture d\u2019\xE9cran a \xE9chou\xE9. Vous pouvez quand m\xEAme envoyer le signalement."
706
+ "noShot": "La capture d\u2019\xE9cran a \xE9chou\xE9. Vous pouvez quand m\xEAme envoyer le signalement.",
707
+ "shotAsk": "Signaler un bug avec cet \xE9cran ?",
708
+ "report": "Signaler",
709
+ "notNow": "Plus tard",
710
+ "crashAsk": "L\u2019application s\u2019est ferm\xE9e de fa\xE7on inattendue. Dites-nous ce que vous faisiez ?",
711
+ "tellUs": "Raconter",
712
+ "pickTitle": "Sur quel \xE9cran se trouve le bug ?",
713
+ "pickNow": "\xC9cran actuel",
714
+ "pickBefore": "\xC9cran pr\xE9c\xE9dent"
178
715
  },
179
716
  "it": {
180
717
  "title": "Segnala un bug",
@@ -207,7 +744,15 @@ var REPORT_STRINGS = {
207
744
  "recError": "Non \xE8 stato possibile registrare. Puoi comunque inviare la segnalazione.",
208
745
  "uploadingVideo": "Caricamento della registrazione\u2026",
209
746
  "close": "Chiudi",
210
- "noShot": "Non \xE8 stato possibile acquisire lo screenshot. Puoi comunque inviare la segnalazione."
747
+ "noShot": "Non \xE8 stato possibile acquisire lo screenshot. Puoi comunque inviare la segnalazione.",
748
+ "shotAsk": "Segnalare un bug con questa schermata?",
749
+ "report": "Segnala",
750
+ "notNow": "Non ora",
751
+ "crashAsk": "L\u2019app si \xE8 chiusa in modo imprevisto. Ci dice cosa stava facendo?",
752
+ "tellUs": "Racconta",
753
+ "pickTitle": "In quale schermata si trova il bug?",
754
+ "pickNow": "Schermata attuale",
755
+ "pickBefore": "Schermata precedente"
211
756
  },
212
757
  "ja": {
213
758
  "title": "\u4E0D\u5177\u5408\u3092\u5831\u544A",
@@ -240,7 +785,15 @@ var REPORT_STRINGS = {
240
785
  "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",
241
786
  "uploadingVideo": "\u9332\u753B\u3092\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9\u4E2D\u2026",
242
787
  "close": "\u9589\u3058\u308B",
243
- "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"
788
+ "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
+ "shotAsk": "\u3053\u306E\u753B\u9762\u3067\u4E0D\u5177\u5408\u3092\u5831\u544A\u3057\u307E\u3059\u304B\uFF1F",
790
+ "report": "\u5831\u544A\u3059\u308B",
791
+ "notNow": "\u4ECA\u306F\u3057\u306A\u3044",
792
+ "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",
793
+ "tellUs": "\u4F1D\u3048\u308B",
794
+ "pickTitle": "\u4E0D\u5177\u5408\u304C\u3042\u308B\u306E\u306F\u3069\u306E\u753B\u9762\u3067\u3059\u304B\uFF1F",
795
+ "pickNow": "\u73FE\u5728\u306E\u753B\u9762",
796
+ "pickBefore": "\u524D\u306E\u753B\u9762"
244
797
  },
245
798
  "nl": {
246
799
  "title": "Bug melden",
@@ -273,7 +826,15 @@ var REPORT_STRINGS = {
273
826
  "recError": "De opname kon niet worden gemaakt. Je kunt het rapport nog steeds versturen.",
274
827
  "uploadingVideo": "Opname uploaden\u2026",
275
828
  "close": "Sluiten",
276
- "noShot": "De schermafbeelding kon niet worden gemaakt. Je kunt de melding toch versturen."
829
+ "noShot": "De schermafbeelding kon niet worden gemaakt. Je kunt de melding toch versturen.",
830
+ "shotAsk": "Een bug melden met dit scherm?",
831
+ "report": "Melden",
832
+ "notNow": "Niet nu",
833
+ "crashAsk": "De app is onverwacht gesloten. Vertelt u ons wat u aan het doen was?",
834
+ "tellUs": "Vertellen",
835
+ "pickTitle": "Op welk scherm zit de bug?",
836
+ "pickNow": "Huidig scherm",
837
+ "pickBefore": "Eerder scherm"
277
838
  },
278
839
  "pt": {
279
840
  "title": "Reportar um erro",
@@ -306,7 +867,15 @@ var REPORT_STRINGS = {
306
867
  "recError": "N\xE3o foi poss\xEDvel gravar. Voc\xEA ainda pode enviar o relat\xF3rio.",
307
868
  "uploadingVideo": "Enviando grava\xE7\xE3o\u2026",
308
869
  "close": "Fechar",
309
- "noShot": "N\xE3o foi poss\xEDvel fazer a captura. Voc\xEA ainda pode enviar o relat\xF3rio."
870
+ "noShot": "N\xE3o foi poss\xEDvel fazer a captura. Voc\xEA ainda pode enviar o relat\xF3rio.",
871
+ "shotAsk": "Reportar um erro com esta tela?",
872
+ "report": "Reportar",
873
+ "notNow": "Agora n\xE3o",
874
+ "crashAsk": "O app fechou inesperadamente. Conte o que voc\xEA estava fazendo?",
875
+ "tellUs": "Contar",
876
+ "pickTitle": "Em qual tela est\xE1 o erro?",
877
+ "pickNow": "Tela atual",
878
+ "pickBefore": "Tela anterior"
310
879
  },
311
880
  "tr": {
312
881
  "title": "Hata bildir",
@@ -339,7 +908,15 @@ var REPORT_STRINGS = {
339
908
  "recError": "Kay\u0131t yap\u0131lamad\u0131. Raporu yine de g\xF6nderebilirsiniz.",
340
909
  "uploadingVideo": "Kay\u0131t y\xFCkleniyor\u2026",
341
910
  "close": "Kapat",
342
- "noShot": "Ekran g\xF6r\xFCnt\xFCs\xFC al\u0131namad\u0131. Bildirimi yine de g\xF6nderebilirsiniz."
911
+ "noShot": "Ekran g\xF6r\xFCnt\xFCs\xFC al\u0131namad\u0131. Bildirimi yine de g\xF6nderebilirsiniz.",
912
+ "shotAsk": "Bu ekranla bir hata bildirilsin mi?",
913
+ "report": "Bildir",
914
+ "notNow": "\u015Eimdi de\u011Fil",
915
+ "crashAsk": "Uygulama beklenmedik \u015Fekilde kapand\u0131. Ne yapt\u0131\u011F\u0131n\u0131z\u0131 bize anlat\u0131r m\u0131s\u0131n\u0131z?",
916
+ "tellUs": "Anlat",
917
+ "pickTitle": "Hata hangi ekranda?",
918
+ "pickNow": "Ge\xE7erli ekran",
919
+ "pickBefore": "\xD6nceki ekran"
343
920
  },
344
921
  "zh": {
345
922
  "title": "\u62A5\u544A\u95EE\u9898",
@@ -372,7 +949,15 @@ var REPORT_STRINGS = {
372
949
  "recError": "\u65E0\u6CD5\u5B8C\u6210\u5F55\u5236\u3002\u4F60\u4ECD\u7136\u53EF\u4EE5\u53D1\u9001\u62A5\u544A\u3002",
373
950
  "uploadingVideo": "\u6B63\u5728\u4E0A\u4F20\u5F55\u5236\u5185\u5BB9\u2026",
374
951
  "close": "\u5173\u95ED",
375
- "noShot": "\u65E0\u6CD5\u622A\u53D6\u5C4F\u5E55\u3002\u60A8\u4ECD\u7136\u53EF\u4EE5\u53D1\u9001\u62A5\u544A\u3002"
952
+ "noShot": "\u65E0\u6CD5\u622A\u53D6\u5C4F\u5E55\u3002\u60A8\u4ECD\u7136\u53EF\u4EE5\u53D1\u9001\u62A5\u544A\u3002",
953
+ "shotAsk": "\u8981\u7528\u6B64\u5C4F\u5E55\u62A5\u544A\u95EE\u9898\u5417\uFF1F",
954
+ "report": "\u62A5\u544A",
955
+ "notNow": "\u4EE5\u540E\u518D\u8BF4",
956
+ "crashAsk": "\u5E94\u7528\u610F\u5916\u5173\u95ED\u3002\u80FD\u544A\u8BC9\u6211\u4EEC\u4F60\u5F53\u65F6\u5728\u505A\u4EC0\u4E48\u5417\uFF1F",
957
+ "tellUs": "\u544A\u8BC9\u6211\u4EEC",
958
+ "pickTitle": "\u95EE\u9898\u51FA\u73B0\u5728\u54EA\u4E2A\u5C4F\u5E55\uFF1F",
959
+ "pickNow": "\u5F53\u524D\u5C4F\u5E55",
960
+ "pickBefore": "\u4E4B\u524D\u7684\u5C4F\u5E55"
376
961
  }
377
962
  };
378
963
 
@@ -413,6 +998,7 @@ function feedbackBody(input) {
413
998
  };
414
999
  if (input.title.trim()) body.title = input.title.trim();
415
1000
  if (input.email?.trim()) body.email = input.email.trim();
1001
+ if (input.eventId && /^[0-9a-f]{32}$/.test(input.eventId)) body.event_id = input.eventId;
416
1002
  if (input.image) {
417
1003
  const list = annotations(input.shapes ?? [], input.image.width, input.image.height);
418
1004
  if (list.length) body.annotations = [{ position: 0, shapes: list }];
@@ -426,25 +1012,25 @@ var ReportClient = class {
426
1012
  constructor(endpoint, key, fetcher = (...a) => fetch(...a)) {
427
1013
  this.endpoint = endpoint.replace(/\/+$/, "");
428
1014
  this.key = key;
429
- this.fetcher = fetcher;
1015
+ this.fetcher = guardPlatform(fetcher);
430
1016
  }
431
- async call(path, init3) {
432
- const res = await this.fetcher(`${this.endpoint}${path}`, { ...init3, headers: { "X-Blipit-Key": this.key, ...init3.headers } });
1017
+ async call(path, init2) {
1018
+ const res = await this.fetcher(`${this.endpoint}${path}`, { ...init2, headers: { "X-Blipit-Key": this.key, ...init2.headers } });
433
1019
  const text2 = await res.text();
434
1020
  if (!res.ok) throw new Error(`Blipit returned ${res.status}`);
435
1021
  return text2;
436
1022
  }
437
- async settings() {
438
- return JSON.parse(await this.call("/api/v1/feedback/settings", { method: "GET" }));
1023
+ async settings(user) {
1024
+ return JSON.parse(await this.call("/api/v1/feedback/settings", { method: "GET", headers: userHeaders(user) }));
439
1025
  }
440
1026
  async event(body) {
441
1027
  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
1028
  return res.ok || res.status >= 400 && res.status < 500 && res.status !== 408 && res.status !== 429;
443
1029
  }
444
1030
  async send(body) {
445
- const json = JSON.parse(await this.call("/api/v1/feedback", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }));
446
- if (typeof json.upload_token !== "string") throw new Error("Blipit returned no upload token");
447
- return { id: String(json.id), token: json.upload_token, ref: typeof json.ref === "string" ? json.ref : null };
1031
+ const json2 = JSON.parse(await this.call("/api/v1/feedback", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }));
1032
+ if (typeof json2.upload_token !== "string") throw new Error("Blipit returned no upload token");
1033
+ return { id: String(json2.id), token: json2.upload_token, ref: typeof json2.ref === "string" ? json2.ref : null };
448
1034
  }
449
1035
  async uploadScreenshot(receipt, data, type) {
450
1036
  await this.call(`/api/v1/feedback/${encodeURIComponent(receipt.id)}/screenshot?position=0`, { method: "POST", headers: { "Content-Type": type, "X-Blipit-Upload": receipt.token }, body: data });
@@ -629,6 +1215,7 @@ function createStuck(transport, info, clock = Date.now) {
629
1215
  import { useEffect, useMemo, useRef, useState } from "react";
630
1216
  import {
631
1217
  ActivityIndicator,
1218
+ Dimensions,
632
1219
  I18nManager,
633
1220
  Image,
634
1221
  KeyboardAvoidingView,
@@ -648,13 +1235,46 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
648
1235
  var C = { navy: "#0B1A3A", card: "#1A2135", brand: "#3882F6", muted: "#98A6BE", mark: "#FF3B30", danger: "#FF7A6E", white: "#FFFFFF" };
649
1236
  var opener = null;
650
1237
  var config = null;
651
- function configureReporter(client, device) {
652
- config = { client, device };
1238
+ var open = false;
1239
+ var serverButton = false;
1240
+ var onServerButton = null;
1241
+ var currentScreen;
1242
+ var settle;
1243
+ var debounce = createDebounce();
1244
+ var screens = new ScreenShots();
1245
+ function configureReporter(client, device, o = { picker: true }) {
1246
+ config = { client, device, picker: o.picker };
1247
+ if (!o.picker) screens.clear();
653
1248
  }
654
1249
  function showReport() {
655
1250
  if (!config) console.warn("[blipit] call Blipit.init before showReport");
656
1251
  else if (!opener) console.warn("[blipit] wrap your app in <BlipitReporter> to use showReport");
657
- else opener();
1252
+ else opener({ picker: config.picker, crashId: null });
1253
+ }
1254
+ function reportTrigger(trigger, crashId) {
1255
+ if (!config || !opener || !debounce.allow(open)) return;
1256
+ opener({ picker: false, crashId: trigger === "crash" ? crashId : null });
1257
+ }
1258
+ function setServerButton(on) {
1259
+ serverButton = on;
1260
+ onServerButton?.(on);
1261
+ }
1262
+ function noteScreen(name) {
1263
+ if (!name || !config?.picker) return;
1264
+ currentScreen = name;
1265
+ if (settle) clearTimeout(settle);
1266
+ settle = setTimeout(async () => {
1267
+ settle = void 0;
1268
+ const shooter = viewShot();
1269
+ if (open || !shooter || currentScreen !== name || !config?.picker) return;
1270
+ try {
1271
+ const { width, height } = Dimensions.get("window");
1272
+ const size = pickerSize(width, height);
1273
+ const uri = await shooter.captureScreen({ format: "jpg", quality: 0.6, result: "data-uri", ...size });
1274
+ if (!open && currentScreen === name && config?.picker) screens.add({ name, uri, ...size });
1275
+ } catch {
1276
+ }
1277
+ }, PICKER_SETTLE_MS);
658
1278
  }
659
1279
  function viewShot() {
660
1280
  try {
@@ -677,19 +1297,32 @@ function BlipitReporter({ children, showButton = false }) {
677
1297
  const [shot, setShot] = useState(null);
678
1298
  const [flat, setFlat] = useState(null);
679
1299
  const [notice, setNotice] = useState(null);
1300
+ const [wantPicker, setWantPicker] = useState(false);
1301
+ const [crashId, setCrashId] = useState(null);
1302
+ const [earlier, setEarlier] = useState([]);
1303
+ const [server, setServer] = useState(serverButton);
680
1304
  const shapes = useRef([]);
681
1305
  useEffect(() => {
682
- opener = () => {
1306
+ opener = (o) => {
683
1307
  shapes.current = [];
684
1308
  setShot(null);
685
1309
  setFlat(null);
686
1310
  setNotice(null);
1311
+ setEarlier([]);
1312
+ setWantPicker(o.picker);
1313
+ setCrashId(o.crashId);
687
1314
  setStage("choice");
688
1315
  };
1316
+ onServerButton = setServer;
1317
+ setServer(serverButton);
689
1318
  return () => {
690
1319
  opener = null;
1320
+ onServerButton = null;
691
1321
  };
692
1322
  }, []);
1323
+ useEffect(() => {
1324
+ open = stage !== "closed";
1325
+ }, [stage]);
693
1326
  const capture = async () => {
694
1327
  const shooter = viewShot();
695
1328
  setStage("closed");
@@ -699,7 +1332,9 @@ function BlipitReporter({ children, showButton = false }) {
699
1332
  const uri = await shooter.captureScreen({ format: "jpg", quality: 0.9, result: "tmpfile" });
700
1333
  const size = await new Promise((ok, fail) => Image.getSize(uri, (width, height) => ok({ width, height }), fail));
701
1334
  setShot({ uri, ...size });
702
- setStage("editor");
1335
+ const before = wantPicker ? screens.list(currentScreen) : [];
1336
+ setEarlier(before);
1337
+ setStage(before.length ? "pick" : "editor");
703
1338
  } catch (err) {
704
1339
  if (!shooter) console.warn("[blipit] install react-native-view-shot to attach screenshots to bug reports");
705
1340
  setNotice(t("noShot"));
@@ -708,7 +1343,7 @@ function BlipitReporter({ children, showButton = false }) {
708
1343
  };
709
1344
  return /* @__PURE__ */ jsxs(View, { style: { flex: 1 }, children: [
710
1345
  children,
711
- showButton && stage === "closed" ? /* @__PURE__ */ jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: t("title"), onPress: () => opener?.(), style: ({ pressed }) => [s.fab, pressed && { opacity: 0.85 }], children: [
1346
+ (showButton || server) && stage === "closed" ? /* @__PURE__ */ jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: t("title"), onPress: showReport, style: ({ pressed }) => [s.fab, pressed && { opacity: 0.85 }], children: [
712
1347
  /* @__PURE__ */ jsx(Text, { style: s.fabIcon, children: "!" }),
713
1348
  /* @__PURE__ */ jsx(Text, { style: s.fabText, children: t("title") })
714
1349
  ] }) : null,
@@ -731,6 +1366,28 @@ function BlipitReporter({ children, showButton = false }) {
731
1366
  )
732
1367
  ] })
733
1368
  ] }) : null,
1369
+ stage === "pick" && shot ? /* @__PURE__ */ jsxs(View, { style: s.pad, children: [
1370
+ /* @__PURE__ */ jsx(Bar, { children: /* @__PURE__ */ jsx(BarButton, { label: t("mBack"), glyph: "\u2039", onPress: () => setStage("choice") }) }),
1371
+ /* @__PURE__ */ jsx(Text, { style: s.h1, children: t("pickTitle") }),
1372
+ /* @__PURE__ */ jsx(ScrollView, { contentContainerStyle: s.thumbs, children: [shot, ...earlier].map((item, i) => /* @__PURE__ */ jsxs(
1373
+ Pressable,
1374
+ {
1375
+ accessibilityRole: "button",
1376
+ accessibilityLabel: i === 0 ? t("pickNow") : t("pickBefore"),
1377
+ onPress: () => {
1378
+ setShot(item);
1379
+ setEarlier([]);
1380
+ setStage("editor");
1381
+ },
1382
+ style: ({ pressed }) => [s.thumb, pressed && { opacity: 0.85 }],
1383
+ children: [
1384
+ /* @__PURE__ */ jsx(Image, { source: { uri: item.uri }, style: [s.thumbImage, { aspectRatio: item.width / Math.max(1, item.height) }], resizeMode: "contain", accessibilityIgnoresInvertColors: true }),
1385
+ /* @__PURE__ */ jsx(Text, { style: s.thumbText, numberOfLines: 1, children: i === 0 ? t("pickNow") : t("pickBefore") })
1386
+ ]
1387
+ },
1388
+ i
1389
+ )) })
1390
+ ] }) : null,
734
1391
  stage === "editor" && shot ? /* @__PURE__ */ jsx(
735
1392
  Editor,
736
1393
  {
@@ -753,6 +1410,7 @@ function BlipitReporter({ children, showButton = false }) {
753
1410
  flat,
754
1411
  shapes: shapes.current,
755
1412
  notice,
1413
+ eventId: crashId,
756
1414
  onBack: () => setStage(shot ? "editor" : "choice"),
757
1415
  onDone: () => setStage("closed")
758
1416
  }
@@ -882,7 +1540,7 @@ function Editor({ shot, shapes, t, onBack, onNext }) {
882
1540
  await new Promise((r) => setTimeout(r, 80));
883
1541
  let out = shot;
884
1542
  const shooter = viewShot();
885
- if (shapes.current.length && shooter && content.current) {
1543
+ if ((shapes.current.length || shot.uri.startsWith("data:")) && shooter && content.current) {
886
1544
  try {
887
1545
  const uri = await shooter.captureRef(content.current, { format: "jpg", quality: 0.85, result: "tmpfile" });
888
1546
  out = { uri, width: shot.width, height: shot.height };
@@ -985,7 +1643,7 @@ function ToolButton({ label, glyph, on, onPress }) {
985
1643
  /* @__PURE__ */ jsx(Text, { style: [s.toolText, { color: on ? C.white : C.muted }], numberOfLines: 1, children: label })
986
1644
  ] });
987
1645
  }
988
- function Details({ t, lang, shot, flat, shapes, notice, onBack, onDone }) {
1646
+ function Details({ t, lang, shot, flat, shapes, notice, eventId, onBack, onDone }) {
989
1647
  const [title, setTitle] = useState("");
990
1648
  const [message, setMessage] = useState("");
991
1649
  const [email, setEmail] = useState("");
@@ -1001,7 +1659,7 @@ function Details({ t, lang, shot, flat, shapes, notice, onBack, onDone }) {
1001
1659
  setBusy(true);
1002
1660
  setStatus({ text: t("sending"), error: false });
1003
1661
  try {
1004
- const receipt = await config.client.send(feedbackBody({ title, message: message.trim(), email, context: config.device(), shapes, image: shot, screenshots: image ? 1 : 0, locale: lang }));
1662
+ 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 }));
1005
1663
  let uploaded = true;
1006
1664
  if (image) {
1007
1665
  try {
@@ -1011,8 +1669,8 @@ function Details({ t, lang, shot, flat, shapes, notice, onBack, onDone }) {
1011
1669
  uploaded = false;
1012
1670
  }
1013
1671
  }
1014
- const done = receipt.ref ? t("sentRef").replace("{ref}", receipt.ref) : t("sentTitle");
1015
- setStatus({ text: uploaded ? done : `${done} \xB7 ${t("noShot")}`, error: !uploaded });
1672
+ const done2 = receipt.ref ? t("sentRef").replace("{ref}", receipt.ref) : t("sentTitle");
1673
+ setStatus({ text: uploaded ? done2 : `${done2} \xB7 ${t("noShot")}`, error: !uploaded });
1016
1674
  setTimeout(onDone, 1600);
1017
1675
  } catch {
1018
1676
  setStatus({ text: t("error"), error: true });
@@ -1060,6 +1718,10 @@ var s = StyleSheet.create({
1060
1718
  tool: { flex: 1, height: 60, alignItems: "center", justifyContent: "center", borderRadius: 12, marginHorizontal: 2 },
1061
1719
  toolGlyph: { fontSize: 20 },
1062
1720
  toolText: { fontSize: 11, marginTop: 2 },
1721
+ thumbs: { flexDirection: "row", flexWrap: "wrap", gap: 12, paddingVertical: 12 },
1722
+ thumb: { width: "47%", backgroundColor: C.card, borderRadius: 14, borderWidth: 1, borderColor: "rgba(255,255,255,0.1)", padding: 8, gap: 8 },
1723
+ thumbImage: { width: "100%", borderRadius: 8, backgroundColor: C.navy },
1724
+ thumbText: { color: C.white, fontSize: 14, fontWeight: "600", textAlign: "center" },
1063
1725
  preview: { height: 150, borderRadius: 12, backgroundColor: C.card },
1064
1726
  input: { backgroundColor: C.card, borderRadius: 12, color: C.white, fontSize: 16, paddingHorizontal: 14, paddingVertical: 12, minHeight: 48 },
1065
1727
  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 } },
@@ -1068,30 +1730,14 @@ var s = StyleSheet.create({
1068
1730
  });
1069
1731
 
1070
1732
  // src/index.ts
1071
- import { captureException, captureMessage as captureMessage2, setUser, setTag, addBreadcrumb, flush, wrap } from "@sentry/react-native";
1072
- var DEFAULT_ENDPOINT = "https://in.blipit.io";
1073
- var VERSION = "0.4.0";
1074
- var PACKAGE = { name: "npm:@blipit/react-native", version: VERSION };
1075
- function withIdentity(user) {
1076
- return (event, hint) => {
1077
- try {
1078
- const sdk = event.sdk ??= {};
1079
- const packages = sdk.packages ?? [];
1080
- if (!packages.some((p) => p?.name === PACKAGE.name)) sdk.packages = [...packages, { ...PACKAGE }];
1081
- } catch {
1082
- }
1083
- return user ? user(event, hint) : event;
1084
- };
1085
- }
1086
- function dsn(key, project, endpoint = DEFAULT_ENDPOINT) {
1087
- const host = endpoint.split("://").pop().replace(/\/+$/, "");
1088
- const scheme = endpoint.startsWith("http://") ? "http" : "https";
1089
- return `${scheme}://${key}@${host}/${project}`;
1090
- }
1733
+ var SECURITY_KINDS = ["login_failed", "login_succeeded", "login_blocked", "password_reset_requested", "privilege_granted"];
1091
1734
  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.";
1092
1735
  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.";
1093
- function init2(options) {
1094
- const { key, publicKey, project, endpoint, waitForReady, ...rest } = options ?? {};
1736
+ var core;
1737
+ var session;
1738
+ var appState;
1739
+ function init(options) {
1740
+ const { key, publicKey, project, endpoint, waitForReady, shakeToReport, screenshotToReport, twoFingerReport, reportAfterCrash, screenPicker, ...rest } = options ?? {};
1095
1741
  const k = (key ?? publicKey ?? "").trim();
1096
1742
  if (!k) {
1097
1743
  console.warn(MISSING_KEY);
@@ -1101,17 +1747,60 @@ function init2(options) {
1101
1747
  console.warn(MISSING_PROJECT);
1102
1748
  return false;
1103
1749
  }
1104
- Sentry.init({
1105
- dsn: dsn(k, project, endpoint),
1106
- sendDefaultPii: false,
1107
- tracesSampleRate: 0,
1108
- ...rest,
1109
- beforeSend: withIdentity(rest.beforeSend)
1750
+ const info = nativeInfo();
1751
+ const release = rest.release ?? defaultRelease(info);
1752
+ const base = endpoint ?? DEFAULT_ENDPOINT;
1753
+ session?.end();
1754
+ appState?.remove();
1755
+ core = new Nuggets({ ...rest, key: k, endpoint: base, release, store: nativeStore(), contexts: () => contexts(info.model, info.osVersion) });
1756
+ const c = core;
1757
+ setBoundaryReporter((error) => c.captureException(error, false));
1758
+ instrument(() => core);
1759
+ const native = rest.enableNative !== false ? bridge() : void 0;
1760
+ if (native && !triggerOff) triggerOff = onNativeTrigger((trigger, crashId) => isTrigger(trigger) && reportTrigger(trigger, typeof crashId === "string" ? crashId : null));
1761
+ try {
1762
+ native?.start(k, String(project), rest.environment ?? null, release ?? null, c.endpoint, {
1763
+ shakeToReport: shakeToReport === true,
1764
+ screenshotToReport: screenshotToReport === true,
1765
+ twoFingerReport: twoFingerReport === true,
1766
+ reportAfterCrash: reportAfterCrash === true,
1767
+ screenPicker: false
1768
+ });
1769
+ } catch {
1770
+ }
1771
+ if (reportAfterCrash === true && c.crashId) {
1772
+ try {
1773
+ native?.promptAfterCrash?.(c.crashId);
1774
+ } catch {
1775
+ }
1776
+ }
1777
+ session = release && rest.autoSessionTracking !== false ? new Session(c, release, rest.environment ?? "production") : void 0;
1778
+ c.onError = (unhandled) => session?.markError(unhandled);
1779
+ if (c.enabled) session?.start();
1780
+ appState = AppState?.addEventListener?.("change", (state) => {
1781
+ if (state === "active") {
1782
+ screens.foreground(Date.now());
1783
+ if (c.enabled) session?.start();
1784
+ void c.flush();
1785
+ } else if (state === "background") {
1786
+ screens.background(Date.now());
1787
+ session?.end();
1788
+ void c.flush();
1789
+ }
1110
1790
  });
1111
- const client = new ReportClient(endpoint ?? DEFAULT_ENDPOINT, k);
1112
- configureReporter(client, () => deviceContext(rest.release));
1791
+ void c.flush();
1792
+ const reports = new ReportClient(base, k);
1793
+ configureReporter(reports, () => deviceContext(release), { picker: screenPicker !== false });
1794
+ reportClient = reports;
1795
+ refreshButton(0);
1113
1796
  if (!stuck) {
1114
- stuck = createStuck(client, { release: rest.release, environment: rest.environment, os: Platform2.OS, osVersion: String(Platform2.Version), version: VERSION });
1797
+ stuck = createStuck(
1798
+ {
1799
+ settings: () => reportClient ? reportClient.settings() : Promise.resolve(null),
1800
+ event: async (body) => (core?.enqueue(body), true)
1801
+ },
1802
+ { release, environment: rest.environment, os: Platform2.OS, osVersion: info.osVersion ?? String(Platform2.Version), version: VERSION }
1803
+ );
1115
1804
  try {
1116
1805
  stuck.setForeground(AppState.currentState !== "background");
1117
1806
  AppState.addEventListener("change", (state) => stuck?.setForeground(state !== "background"));
@@ -1120,9 +1809,38 @@ function init2(options) {
1120
1809
  }
1121
1810
  if (waitForReady) stuck.start(STARTUP);
1122
1811
  }
1812
+ if (rest.debug) console.log(`[blipit] ${SDK_NAME}@${VERSION} initialized`);
1123
1813
  return true;
1124
1814
  }
1125
1815
  var stuck = null;
1816
+ var reportClient;
1817
+ var triggerOff;
1818
+ var buttonTimer;
1819
+ var buttonBusy = false;
1820
+ var buttonAgain = false;
1821
+ function refreshButton(delay) {
1822
+ if (buttonTimer) clearTimeout(buttonTimer);
1823
+ buttonTimer = setTimeout(() => {
1824
+ buttonTimer = void 0;
1825
+ void fetchButton();
1826
+ }, delay);
1827
+ }
1828
+ async function fetchButton() {
1829
+ const client = reportClient;
1830
+ if (!client) return;
1831
+ if (buttonBusy) return void (buttonAgain = true);
1832
+ buttonBusy = true;
1833
+ try {
1834
+ setServerButton(parseReportButton(await client.settings(core?.user)));
1835
+ } catch {
1836
+ } finally {
1837
+ buttonBusy = false;
1838
+ if (buttonAgain) {
1839
+ buttonAgain = false;
1840
+ void fetchButton();
1841
+ }
1842
+ }
1843
+ }
1126
1844
  function reportReady() {
1127
1845
  stuck?.end(STARTUP);
1128
1846
  }
@@ -1139,8 +1857,18 @@ function endFlow(name) {
1139
1857
  const flow = cleanName(name, 64);
1140
1858
  if (flow) stuck?.end(flow);
1141
1859
  }
1860
+ function contexts(model, osVersion) {
1861
+ const { width, height } = Dimensions2.get("window");
1862
+ const engine = globalThis.HermesInternal ? "hermes" : "jsc";
1863
+ const rn = Platform2.constants?.reactNativeVersion;
1864
+ return {
1865
+ os: { name: Platform2.OS, version: osVersion ?? String(Platform2.Version) },
1866
+ device: { ...model ? { model } : {}, screen: `${Math.round(width)}x${Math.round(height)}` },
1867
+ runtime: { name: engine, ...rn ? { version: `react-native ${rn.major}.${rn.minor}.${rn.patch}` } : {} }
1868
+ };
1869
+ }
1142
1870
  function deviceContext(release) {
1143
- const { width, height, scale } = Dimensions.get("window");
1871
+ const { width, height, scale } = Dimensions2.get("window");
1144
1872
  let language = "";
1145
1873
  let timezone = "";
1146
1874
  try {
@@ -1151,11 +1879,17 @@ function deviceContext(release) {
1151
1879
  }
1152
1880
  return {
1153
1881
  platform: "react-native",
1154
- sdk: { name: PACKAGE.name, version: VERSION },
1882
+ sdk: { name: `npm:${SDK_NAME}`, version: VERSION },
1155
1883
  ...release ? { app: { release } } : {},
1156
1884
  device: { os: Platform2.OS, os_version: String(Platform2.Version), screen: `${Math.round(width)}x${Math.round(height)}`, dpr: scale, language, timezone, touch: true }
1157
1885
  };
1158
1886
  }
1887
+ function captureException(error) {
1888
+ return core?.captureException(error, true);
1889
+ }
1890
+ function captureMessage(message, level = "info") {
1891
+ return core?.captureMessage(message, level);
1892
+ }
1159
1893
  function captureSecurity(kind, actor, details = {}) {
1160
1894
  const context = { kind, actor };
1161
1895
  const extra = { outcome: details.outcome, actor_id: details.actorId, ip: details.ip, user_agent: details.userAgent, target: details.target };
@@ -1163,30 +1897,93 @@ function captureSecurity(kind, actor, details = {}) {
1163
1897
  if (v !== void 0 && v !== null) context[k] = v;
1164
1898
  }
1165
1899
  const level = kind === "login_failed" || kind === "login_blocked" ? "warning" : "info";
1166
- Sentry.withScope((scope) => {
1167
- scope.setContext("security", context);
1168
- scope.setTag("security.kind", kind);
1169
- Sentry.captureMessage(`${kind} for ${actor}`, level);
1170
- });
1900
+ return core?.captureSecurity(kind, `${kind} for ${actor}`, level, SECURITY_KINDS.includes(kind) && actor ? context : void 0);
1901
+ }
1902
+ function setUser(user) {
1903
+ core?.setUser(user);
1904
+ const u = core?.user;
1905
+ try {
1906
+ bridge()?.setUser(u?.id ?? null, u?.email ?? null, u?.username ?? null);
1907
+ } catch {
1908
+ }
1909
+ refreshButton(1e3);
1910
+ }
1911
+ function setTag(key, value) {
1912
+ core?.setTag(key, value);
1913
+ try {
1914
+ bridge()?.setTag(key, String(value));
1915
+ } catch {
1916
+ }
1917
+ }
1918
+ function addBreadcrumb(crumb) {
1919
+ core?.addBreadcrumb(crumb);
1920
+ }
1921
+ async function flush(timeout = 2e3) {
1922
+ if (!core) return true;
1923
+ const c = core;
1924
+ let timer;
1925
+ const late = new Promise((r) => timer = setTimeout(() => r(false), timeout));
1926
+ const ok = await Promise.race([c.flush().then(() => c.pending === 0), late]);
1927
+ clearTimeout(timer);
1928
+ return ok;
1929
+ }
1930
+ function setEnabled(on) {
1931
+ if (!core) return;
1932
+ core.setEnabled(on);
1933
+ if (!on) screens.clear();
1934
+ if (on) session?.start();
1935
+ else session?.end();
1936
+ }
1937
+ var isEnabled = () => core?.enabled ?? false;
1938
+ var lastEventId = () => core?.lastEventId;
1939
+ function setReplayConsent(granted) {
1940
+ try {
1941
+ bridge()?.setReplayConsent(granted);
1942
+ } catch {
1943
+ }
1944
+ }
1945
+ function hasReplayConsent() {
1946
+ try {
1947
+ return bridge()?.hasReplayConsent() === true;
1948
+ } catch {
1949
+ return false;
1950
+ }
1951
+ }
1952
+ function trackNavigation2(ref) {
1953
+ const stop = trackNavigation(() => core, ref);
1954
+ const seen = () => {
1955
+ if (core?.enabled) noteScreen(ref.getCurrentRoute()?.name);
1956
+ };
1957
+ seen();
1958
+ const off = ref.addListener("state", seen);
1959
+ return () => {
1960
+ stop();
1961
+ off();
1962
+ };
1171
1963
  }
1172
1964
  export {
1173
1965
  BlipitReporter,
1174
1966
  DEFAULT_ENDPOINT,
1967
+ ErrorBoundary,
1175
1968
  VERSION,
1176
1969
  addBreadcrumb,
1177
1970
  captureException,
1178
- captureMessage2 as captureMessage,
1971
+ captureMessage,
1179
1972
  captureSecurity,
1180
- dsn,
1181
1973
  endFlow,
1182
1974
  flowStep,
1183
1975
  flush,
1184
- init2 as init,
1976
+ hasReplayConsent,
1977
+ init,
1978
+ isEnabled,
1979
+ lastEventId,
1185
1980
  reportReady,
1981
+ setEnabled,
1982
+ setReplayConsent,
1186
1983
  setTag,
1187
1984
  setUser,
1188
1985
  showReport,
1189
1986
  startFlow,
1190
- withIdentity,
1987
+ trackNavigation2 as trackNavigation,
1191
1988
  wrap
1192
1989
  };