@merittdev/horus-lens 0.5.2 → 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/README.md CHANGED
@@ -44,6 +44,22 @@ the reporter picks. Use `enabled={isPreviewEnv}` to force the overlay on (e.g. e
44
44
  preview deployment). Wrap children with `<Lens>` only when a descendant needs the
45
45
  `useLens()` hook for programmatic control.
46
46
 
47
+ ### React Native (initial implementation)
48
+
49
+ ```tsx
50
+ import { Lens } from '@merittdev/horus-lens/react-native';
51
+
52
+ <Lens enabled={isQA} accessId="lai_your_access_id"
53
+ origin="https://www.example.com" route={pathname} />
54
+ ```
55
+
56
+ `enabled` defaults to false. This entry mounts a native issue sheet and captures
57
+ fetch metadata, device/route context and explicitly supplied errors. Console
58
+ capture is opt-in. Supply an origin already allowed by your Lens project.
59
+ Screenshot preview, annotation tools and explicit visual recording are available with native capture support (react-native-view-shot and react-native-svg). Native recording uses image frames; DOM/component inspection and automatic input masking are browser-specific. See
60
+ [the native SDK guide](https://github.com/Meritt-dev/horus-lens/blob/master/packages/react-native/README.md)
61
+ for redaction, hooks and capture controls.
62
+
47
63
  ### Script tag
48
64
 
49
65
  Context can be pushed before the bundle even loads:
package/dist/browser.cjs CHANGED
@@ -31,6 +31,260 @@ __export(browser_exports, {
31
31
  });
32
32
  module.exports = __toCommonJS(browser_exports);
33
33
 
34
+ // ../core/dist/chunk-YBVE6CBL.js
35
+ var SDK_NAME = "@merittdev/horus-lens";
36
+ var SDK_VERSION = true ? "0.6.1" : "0.0.0-dev";
37
+ var DEFAULT_ENDPOINT = "https://api.horus.sh";
38
+ var DEFAULT_REPLAY_WINDOW_MS = 15e3;
39
+ var DEFAULT_MAX_CONSOLE_ENTRIES = 200;
40
+ var DEFAULT_MAX_NETWORK_ENTRIES = 100;
41
+ var MAX_ERROR_ENTRIES = 100;
42
+ var CONSOLE_TAIL_SIZE = 50;
43
+ var NETWORK_TAIL_SIZE = 30;
44
+ var MAX_SERIALIZED_ARG_CHARS = 2e3;
45
+ var MAX_DOM_BYTES = 2 * 1024 * 1024;
46
+ var MAX_TARGET_TEXT_CHARS = 200;
47
+ var SCREENSHOT_TIMEOUT_MS = 2e4;
48
+ var SCREENSHOT_RESOURCE_TIMEOUT_MS = 3500;
49
+ var SCREENSHOT_MAX_SCALE = 2;
50
+ var SCREENSHOT_MAX_PIXELS = 25e5;
51
+ var AUTO_CAPTURE_COOLDOWN_MS = 10 * 60 * 1e3;
52
+ var AUTO_CAPTURE_SESSION_CAP = 5;
53
+ var MAX_MANUAL_RECORDING_MS = 12e4;
54
+ var MAX_MANUAL_RECORDING_EVENTS = 1e4;
55
+ var LENS_OVERLAY_HOST_ID = "__lens_root__";
56
+ var RingBuffer = class {
57
+ constructor(capacity) {
58
+ this.capacity = capacity;
59
+ if (capacity <= 0) throw new Error("RingBuffer capacity must be > 0");
60
+ }
61
+ capacity;
62
+ items = [];
63
+ push(item) {
64
+ this.items.push(item);
65
+ if (this.items.length > this.capacity) {
66
+ this.items.splice(0, this.items.length - this.capacity);
67
+ }
68
+ }
69
+ /** Snapshot of current contents, oldest first. */
70
+ drain() {
71
+ return [...this.items];
72
+ }
73
+ tail(count) {
74
+ return this.items.slice(-count);
75
+ }
76
+ clear() {
77
+ this.items = [];
78
+ }
79
+ get size() {
80
+ return this.items.length;
81
+ }
82
+ };
83
+ var HttpError = class extends Error {
84
+ constructor(status, message) {
85
+ super(message);
86
+ this.status = status;
87
+ this.name = "HttpError";
88
+ }
89
+ status;
90
+ };
91
+ var Transport = class {
92
+ constructor(config2) {
93
+ this.config = config2;
94
+ }
95
+ config;
96
+ async initiate(assets) {
97
+ const body = {
98
+ accessId: this.config.accessId,
99
+ assets
100
+ };
101
+ return this.postJson(
102
+ `${this.config.endpoint}/v1/reports/initiate`,
103
+ body,
104
+ { retries: 0 }
105
+ );
106
+ }
107
+ /** Record a late-uploaded asset (background screenshot) on a finalized report. */
108
+ async attachAsset(reportId, asset) {
109
+ const body = {
110
+ accessId: this.config.accessId,
111
+ ...asset
112
+ };
113
+ await this.postJson(
114
+ `${this.config.endpoint}/v1/reports/${encodeURIComponent(reportId)}/assets`,
115
+ body
116
+ );
117
+ }
118
+ async uploadAsset(upload, blob2, signal) {
119
+ const session = this.config.signal;
120
+ const controller = session ? new AbortController() : void 0;
121
+ const abort = () => controller?.abort();
122
+ if (session?.aborted || signal?.aborted) abort();
123
+ session?.addEventListener("abort", abort);
124
+ if (controller) signal?.addEventListener("abort", abort);
125
+ try {
126
+ const response = await (this.config.fetch ?? fetch)(upload.url, {
127
+ method: upload.method,
128
+ headers: upload.headers,
129
+ body: blob2,
130
+ signal: controller?.signal ?? signal
131
+ });
132
+ if (!response.ok) {
133
+ throw new Error(
134
+ `Asset upload failed (${upload.kind}): ${response.status}`
135
+ );
136
+ }
137
+ } finally {
138
+ session?.removeEventListener("abort", abort);
139
+ if (controller) signal?.removeEventListener("abort", abort);
140
+ }
141
+ }
142
+ async finalize(reportId, metadata, uploadedAssets) {
143
+ const body = {
144
+ accessId: this.config.accessId,
145
+ metadata,
146
+ uploadedAssets
147
+ };
148
+ try {
149
+ return await this.postJson(
150
+ `${this.config.endpoint}/v1/reports/${reportId}/finalize`,
151
+ body
152
+ );
153
+ } catch (err) {
154
+ if (err instanceof HttpError && err.status === 409) {
155
+ return { reportId, status: "submitted" };
156
+ }
157
+ throw err;
158
+ }
159
+ }
160
+ async postJson(url2, body, opts = {}) {
161
+ const retries = opts.retries ?? 1;
162
+ let lastError;
163
+ for (let attempt = 0; attempt <= retries; attempt++) {
164
+ const controller = this.config.requestTimeoutMs || this.config.signal ? new AbortController() : void 0;
165
+ const abort = () => controller?.abort();
166
+ const session = this.config.signal;
167
+ if (session?.aborted) throw new Error("Capture session ended");
168
+ session?.addEventListener("abort", abort);
169
+ const timeout = controller && this.config.requestTimeoutMs ? setTimeout(() => controller.abort(), this.config.requestTimeoutMs) : void 0;
170
+ try {
171
+ const response = await (this.config.fetch ?? fetch)(url2, {
172
+ method: "POST",
173
+ headers: {
174
+ "content-type": "application/json",
175
+ ...this.config.origin ? { Origin: this.config.origin } : {}
176
+ },
177
+ body: JSON.stringify(body),
178
+ ...controller ? { signal: controller.signal } : {}
179
+ });
180
+ if (!response.ok) {
181
+ const text = await response.text().catch(() => "");
182
+ throw new HttpError(
183
+ response.status,
184
+ `Request to ${url2} failed: ${response.status} ${text}`.trim()
185
+ );
186
+ }
187
+ return await response.json();
188
+ } catch (err) {
189
+ lastError = err;
190
+ if (this.config.debug) {
191
+ console.warn(
192
+ `[lens] request failed (attempt ${attempt + 1}/${retries + 1})`,
193
+ err
194
+ );
195
+ }
196
+ } finally {
197
+ if (timeout !== void 0) clearTimeout(timeout);
198
+ session?.removeEventListener("abort", abort);
199
+ }
200
+ }
201
+ throw lastError;
202
+ }
203
+ };
204
+ var LEVELS = ["log", "info", "warn", "error", "debug"];
205
+ function cap(value) {
206
+ return value.length > MAX_SERIALIZED_ARG_CHARS ? `${value.slice(0, MAX_SERIALIZED_ARG_CHARS)}\u2026[truncated]` : value;
207
+ }
208
+ function serializeArg(value) {
209
+ if (value === null) return "null";
210
+ if (value === void 0) return "undefined";
211
+ const type = typeof value;
212
+ if (type === "string") return cap(value);
213
+ if (type === "number" || type === "boolean" || type === "bigint" || type === "symbol") {
214
+ return String(value);
215
+ }
216
+ if (type === "function") {
217
+ return `[Function: ${value.name || "anonymous"}]`;
218
+ }
219
+ if (value instanceof Error) {
220
+ return cap(value.stack ? `${value.name}: ${value.message}
221
+ ${value.stack}` : `${value.name}: ${value.message}`);
222
+ }
223
+ try {
224
+ const seen = /* @__PURE__ */ new WeakSet();
225
+ const json2 = JSON.stringify(value, (_key, val) => {
226
+ if (typeof val === "bigint") return String(val);
227
+ if (typeof val === "function") return "[Function]";
228
+ if (typeof val === "object" && val !== null) {
229
+ if (seen.has(val)) return "[Circular]";
230
+ seen.add(val);
231
+ }
232
+ return val;
233
+ });
234
+ return cap(json2 ?? String(value));
235
+ } catch {
236
+ return cap(String(value));
237
+ }
238
+ }
239
+ function firstErrorStack(args) {
240
+ for (const arg of args) {
241
+ if (arg instanceof Error && arg.stack) return arg.stack;
242
+ }
243
+ return void 0;
244
+ }
245
+ function installConsole(consoleBuffer, errorBuffer) {
246
+ if (typeof console === "undefined") return () => {
247
+ };
248
+ const target = console;
249
+ const restores = [];
250
+ let active = true;
251
+ for (const level of LEVELS) {
252
+ const original = target[level];
253
+ if (typeof original !== "function") continue;
254
+ const wrapped = (...args) => {
255
+ if (!active) {
256
+ original.apply(console, args);
257
+ return;
258
+ }
259
+ try {
260
+ const serialized = args.map(serializeArg);
261
+ const timestamp = Date.now();
262
+ consoleBuffer.push({ level, args: serialized, timestamp });
263
+ if (level === "error") {
264
+ const stack = firstErrorStack(args);
265
+ const entry = {
266
+ message: serialized.join(" ") || "console.error",
267
+ source: "console.error",
268
+ timestamp
269
+ };
270
+ if (stack) entry.stack = stack;
271
+ errorBuffer.push(entry);
272
+ }
273
+ } catch {
274
+ }
275
+ original.apply(console, args);
276
+ };
277
+ target[level] = wrapped;
278
+ restores.push(() => {
279
+ if (target[level] === wrapped) target[level] = original;
280
+ });
281
+ }
282
+ return () => {
283
+ active = false;
284
+ for (const restore of restores) restore();
285
+ };
286
+ }
287
+
34
288
  // ../../node_modules/.pnpm/rrweb@2.1.0/node_modules/rrweb/dist/rrweb.js
35
289
  var __defProp2 = Object.defineProperty;
36
290
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -11680,9 +11934,9 @@ var saveWebGLVar = (value, win, ctx) => {
11680
11934
  }
11681
11935
  return index2;
11682
11936
  };
11683
- function serializeArg(value, win, ctx) {
11937
+ function serializeArg2(value, win, ctx) {
11684
11938
  if (value instanceof Array) {
11685
- return value.map((arg) => serializeArg(arg, win, ctx));
11939
+ return value.map((arg) => serializeArg2(arg, win, ctx));
11686
11940
  } else if (value === null) {
11687
11941
  return value;
11688
11942
  } else if (value instanceof Float32Array || value instanceof Float64Array || value instanceof Int32Array || value instanceof Uint32Array || value instanceof Uint8Array || value instanceof Uint16Array || value instanceof Int16Array || value instanceof Int8Array || value instanceof Uint8ClampedArray) {
@@ -11708,7 +11962,7 @@ function serializeArg(value, win, ctx) {
11708
11962
  return {
11709
11963
  rr_type: name,
11710
11964
  args: [
11711
- serializeArg(value.buffer, win, ctx),
11965
+ serializeArg2(value.buffer, win, ctx),
11712
11966
  value.byteOffset,
11713
11967
  value.byteLength
11714
11968
  ]
@@ -11731,7 +11985,7 @@ function serializeArg(value, win, ctx) {
11731
11985
  const name = value.constructor.name;
11732
11986
  return {
11733
11987
  rr_type: name,
11734
- args: [serializeArg(value.data, win, ctx), value.width, value.height]
11988
+ args: [serializeArg2(value.data, win, ctx), value.width, value.height]
11735
11989
  };
11736
11990
  } else if (isInstanceOfWebGLObject(value, win) || typeof value === "object") {
11737
11991
  const name = value.constructor.name;
@@ -11744,7 +11998,7 @@ function serializeArg(value, win, ctx) {
11744
11998
  return value;
11745
11999
  }
11746
12000
  var serializeArgs = (args, win, ctx) => {
11747
- return args.map((arg) => serializeArg(arg, win, ctx));
12001
+ return args.map((arg) => serializeArg2(arg, win, ctx));
11748
12002
  };
11749
12003
  var isInstanceOfWebGLObject = (value, win) => {
11750
12004
  const webGLConstructorNames = [
@@ -29081,27 +29335,6 @@ var ApiErrorSchema = external_exports.object({
29081
29335
  });
29082
29336
 
29083
29337
  // ../core/dist/index.js
29084
- var SDK_NAME = "@merittdev/horus-lens";
29085
- var SDK_VERSION = true ? "0.5.2" : "0.0.0-dev";
29086
- var DEFAULT_ENDPOINT = "https://api.horus.sh";
29087
- var DEFAULT_REPLAY_WINDOW_MS = 15e3;
29088
- var DEFAULT_MAX_CONSOLE_ENTRIES = 200;
29089
- var DEFAULT_MAX_NETWORK_ENTRIES = 100;
29090
- var MAX_ERROR_ENTRIES = 100;
29091
- var CONSOLE_TAIL_SIZE = 50;
29092
- var NETWORK_TAIL_SIZE = 30;
29093
- var MAX_SERIALIZED_ARG_CHARS = 2e3;
29094
- var MAX_DOM_BYTES = 2 * 1024 * 1024;
29095
- var MAX_TARGET_TEXT_CHARS = 200;
29096
- var SCREENSHOT_TIMEOUT_MS = 2e4;
29097
- var SCREENSHOT_RESOURCE_TIMEOUT_MS = 3500;
29098
- var SCREENSHOT_MAX_SCALE = 2;
29099
- var SCREENSHOT_MAX_PIXELS = 25e5;
29100
- var AUTO_CAPTURE_COOLDOWN_MS = 10 * 60 * 1e3;
29101
- var AUTO_CAPTURE_SESSION_CAP = 5;
29102
- var MAX_MANUAL_RECORDING_MS = 12e4;
29103
- var MAX_MANUAL_RECORDING_EVENTS = 1e4;
29104
- var LENS_OVERLAY_HOST_ID = "__lens_root__";
29105
29338
  function autoCaptureSignature(message) {
29106
29339
  return message.toLowerCase().replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/g, "<uuid>").replace(/\d+/g, "<n>").replace(/\s+/g, " ").trim();
29107
29340
  }
@@ -29180,189 +29413,6 @@ function startAutoCapture(client, options = {}) {
29180
29413
  window.removeEventListener("unhandledrejection", onRejection);
29181
29414
  };
29182
29415
  }
29183
- var RingBuffer = class {
29184
- constructor(capacity) {
29185
- this.capacity = capacity;
29186
- if (capacity <= 0) throw new Error("RingBuffer capacity must be > 0");
29187
- }
29188
- capacity;
29189
- items = [];
29190
- push(item) {
29191
- this.items.push(item);
29192
- if (this.items.length > this.capacity) {
29193
- this.items.splice(0, this.items.length - this.capacity);
29194
- }
29195
- }
29196
- /** Snapshot of current contents, oldest first. */
29197
- drain() {
29198
- return [...this.items];
29199
- }
29200
- tail(count) {
29201
- return this.items.slice(-count);
29202
- }
29203
- clear() {
29204
- this.items = [];
29205
- }
29206
- get size() {
29207
- return this.items.length;
29208
- }
29209
- };
29210
- var HttpError = class extends Error {
29211
- constructor(status, message) {
29212
- super(message);
29213
- this.status = status;
29214
- this.name = "HttpError";
29215
- }
29216
- status;
29217
- };
29218
- var Transport = class {
29219
- constructor(config2) {
29220
- this.config = config2;
29221
- }
29222
- config;
29223
- async initiate(assets) {
29224
- const body = { accessId: this.config.accessId, assets };
29225
- return this.postJson(
29226
- `${this.config.endpoint}/v1/reports/initiate`,
29227
- body,
29228
- { retries: 0 }
29229
- );
29230
- }
29231
- /** Record a late-uploaded asset (background screenshot) on a finalized report. */
29232
- async attachAsset(reportId, asset) {
29233
- const body = { accessId: this.config.accessId, ...asset };
29234
- await this.postJson(`${this.config.endpoint}/v1/reports/${encodeURIComponent(reportId)}/assets`, body);
29235
- }
29236
- async uploadAsset(upload, blob2, signal) {
29237
- const response = await fetch(upload.url, {
29238
- method: upload.method,
29239
- headers: upload.headers,
29240
- body: blob2,
29241
- signal
29242
- });
29243
- if (!response.ok) {
29244
- throw new Error(`Asset upload failed (${upload.kind}): ${response.status}`);
29245
- }
29246
- }
29247
- async finalize(reportId, metadata, uploadedAssets) {
29248
- const body = { accessId: this.config.accessId, metadata, uploadedAssets };
29249
- try {
29250
- return await this.postJson(
29251
- `${this.config.endpoint}/v1/reports/${reportId}/finalize`,
29252
- body
29253
- );
29254
- } catch (err) {
29255
- if (err instanceof HttpError && err.status === 409) {
29256
- return { reportId, status: "submitted" };
29257
- }
29258
- throw err;
29259
- }
29260
- }
29261
- async postJson(url2, body, opts = {}) {
29262
- const retries = opts.retries ?? 1;
29263
- let lastError;
29264
- for (let attempt = 0; attempt <= retries; attempt++) {
29265
- try {
29266
- const response = await fetch(url2, {
29267
- method: "POST",
29268
- headers: { "content-type": "application/json" },
29269
- body: JSON.stringify(body)
29270
- });
29271
- if (!response.ok) {
29272
- const text = await response.text().catch(() => "");
29273
- throw new HttpError(
29274
- response.status,
29275
- `Request to ${url2} failed: ${response.status} ${text}`.trim()
29276
- );
29277
- }
29278
- return await response.json();
29279
- } catch (err) {
29280
- lastError = err;
29281
- if (this.config.debug) {
29282
- console.warn(`[lens] request failed (attempt ${attempt + 1}/${retries + 1})`, err);
29283
- }
29284
- }
29285
- }
29286
- throw lastError;
29287
- }
29288
- };
29289
- var LEVELS = ["log", "info", "warn", "error", "debug"];
29290
- function cap(value) {
29291
- return value.length > MAX_SERIALIZED_ARG_CHARS ? `${value.slice(0, MAX_SERIALIZED_ARG_CHARS)}\u2026[truncated]` : value;
29292
- }
29293
- function serializeArg2(value) {
29294
- if (value === null) return "null";
29295
- if (value === void 0) return "undefined";
29296
- const type = typeof value;
29297
- if (type === "string") return cap(value);
29298
- if (type === "number" || type === "boolean" || type === "bigint" || type === "symbol") {
29299
- return String(value);
29300
- }
29301
- if (type === "function") {
29302
- return `[Function: ${value.name || "anonymous"}]`;
29303
- }
29304
- if (value instanceof Error) {
29305
- return cap(value.stack ? `${value.name}: ${value.message}
29306
- ${value.stack}` : `${value.name}: ${value.message}`);
29307
- }
29308
- try {
29309
- const seen = /* @__PURE__ */ new WeakSet();
29310
- const json2 = JSON.stringify(value, (_key, val) => {
29311
- if (typeof val === "bigint") return String(val);
29312
- if (typeof val === "function") return "[Function]";
29313
- if (typeof val === "object" && val !== null) {
29314
- if (seen.has(val)) return "[Circular]";
29315
- seen.add(val);
29316
- }
29317
- return val;
29318
- });
29319
- return cap(json2 ?? String(value));
29320
- } catch {
29321
- return cap(String(value));
29322
- }
29323
- }
29324
- function firstErrorStack(args) {
29325
- for (const arg of args) {
29326
- if (arg instanceof Error && arg.stack) return arg.stack;
29327
- }
29328
- return void 0;
29329
- }
29330
- function installConsole(consoleBuffer, errorBuffer) {
29331
- if (typeof console === "undefined") return () => {
29332
- };
29333
- const target = console;
29334
- const restores = [];
29335
- for (const level of LEVELS) {
29336
- const original = target[level];
29337
- if (typeof original !== "function") continue;
29338
- const wrapped = (...args) => {
29339
- try {
29340
- const serialized = args.map(serializeArg2);
29341
- const timestamp = Date.now();
29342
- consoleBuffer.push({ level, args: serialized, timestamp });
29343
- if (level === "error") {
29344
- const stack = firstErrorStack(args);
29345
- const entry = {
29346
- message: serialized.join(" ") || "console.error",
29347
- source: "console.error",
29348
- timestamp
29349
- };
29350
- if (stack) entry.stack = stack;
29351
- errorBuffer.push(entry);
29352
- }
29353
- } catch {
29354
- }
29355
- original.apply(console, args);
29356
- };
29357
- target[level] = wrapped;
29358
- restores.push(() => {
29359
- target[level] = original;
29360
- });
29361
- }
29362
- return () => {
29363
- for (const restore of restores) restore();
29364
- };
29365
- }
29366
29416
  function nowMs() {
29367
29417
  return typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
29368
29418
  }