@merittdev/horus-lens 0.2.1 → 0.3.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.
@@ -1,6 +1,6 @@
1
- import { L as LensConfig, a as LensClient } from './index.d-QzZn4EMM.cjs';
1
+ import { L as LensConfig, a as LensClient } from './index.d-BYG_Mjs-.cjs';
2
2
  import { z } from 'zod';
3
- import './index.d-Cyvb07sp.cjs';
3
+ import './index.d-DTx4C384.cjs';
4
4
 
5
5
  declare const AppContextSchema: z.ZodObject<{
6
6
  release: z.ZodOptional<z.ZodString>;
package/dist/browser.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { L as LensConfig, a as LensClient } from './index.d-BtnbCqUx.js';
1
+ import { L as LensConfig, a as LensClient } from './index.d-Dyzc1E9T.js';
2
2
  import { z } from 'zod';
3
- import './index.d-Cyvb07sp.js';
3
+ import './index.d-DTx4C384.js';
4
4
 
5
5
  declare const AppContextSchema: z.ZodObject<{
6
6
  release: z.ZodOptional<z.ZodString>;
package/dist/browser.js CHANGED
@@ -7,8 +7,8 @@ import {
7
7
  isGateActive,
8
8
  loaderSnippet,
9
9
  processQueue
10
- } from "./chunk-SDMTZ5Y6.js";
11
- import "./chunk-U6GBOUCE.js";
10
+ } from "./chunk-PNY6BL4C.js";
11
+ import "./chunk-LIYEDZV7.js";
12
12
  export {
13
13
  DEFAULT_CDN_URL,
14
14
  LOADER_SNIPPET,
@@ -14674,6 +14674,7 @@ var AssetRefSchema = external_exports.object({
14674
14674
  byteSize: external_exports.number().optional()
14675
14675
  });
14676
14676
  var ReportStatusSchema = external_exports.enum(["initiated", "submitted", "triaged", "linked", "resolved"]);
14677
+ var ReportTriggerSchema = external_exports.enum(["user", "api", "error"]);
14677
14678
  var ReportMetadataSchema = external_exports.object({
14678
14679
  comment: external_exports.string().optional(),
14679
14680
  annotations: external_exports.array(AnnotationSchema).default([]),
@@ -14684,6 +14685,13 @@ var ReportMetadataSchema = external_exports.object({
14684
14685
  /** Small inline tails so the report list can render without fetching assets. */
14685
14686
  consoleTail: external_exports.array(ConsoleEntrySchema).default([]),
14686
14687
  networkTail: external_exports.array(NetworkEntrySchema).default([]),
14688
+ /**
14689
+ * How the report was triggered. Optional + non-breaking: this schema is a
14690
+ * plain `z.object` (NOT `.strict()`), so a cloud running an older shared
14691
+ * schema silently strips this unknown key on parse rather than rejecting.
14692
+ * Absent → treat as `user`.
14693
+ */
14694
+ trigger: ReportTriggerSchema.optional(),
14687
14695
  sdk: external_exports.object({ name: external_exports.string(), version: external_exports.string() })
14688
14696
  });
14689
14697
  var ReportSchema = external_exports.object({
@@ -29055,7 +29063,7 @@ async function domToBlob(node2, options) {
29055
29063
 
29056
29064
  // ../core/dist/index.js
29057
29065
  var SDK_NAME = "@merittdev/horus-lens";
29058
- var SDK_VERSION = true ? "0.2.1" : "0.0.0-dev";
29066
+ var SDK_VERSION = true ? "0.3.0" : "0.0.0-dev";
29059
29067
  var DEFAULT_ENDPOINT = "https://api.horus.sh";
29060
29068
  var DEFAULT_REPLAY_WINDOW_MS = 15e3;
29061
29069
  var DEFAULT_MAX_CONSOLE_ENTRIES = 200;
@@ -29069,9 +29077,85 @@ var MAX_TARGET_TEXT_CHARS = 200;
29069
29077
  var SCREENSHOT_TIMEOUT_MS = 2e4;
29070
29078
  var SCREENSHOT_MAX_SCALE = 2;
29071
29079
  var SCREENSHOT_MAX_PIXELS = 25e5;
29080
+ var AUTO_CAPTURE_COOLDOWN_MS = 10 * 60 * 1e3;
29081
+ var AUTO_CAPTURE_SESSION_CAP = 5;
29072
29082
  var MAX_MANUAL_RECORDING_MS = 12e4;
29073
29083
  var MAX_MANUAL_RECORDING_EVENTS = 1e4;
29074
29084
  var LENS_OVERLAY_HOST_ID = "__lens_root__";
29085
+ function autoCaptureSignature(message) {
29086
+ 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();
29087
+ }
29088
+ function reasonToMessage(reason) {
29089
+ if (reason instanceof Error) return reason.message || String(reason);
29090
+ if (typeof reason === "string") return reason;
29091
+ try {
29092
+ const json2 = JSON.stringify(reason);
29093
+ if (json2 && json2 !== "{}") return json2;
29094
+ } catch {
29095
+ }
29096
+ return String(reason);
29097
+ }
29098
+ function isIgnored2(message, ignore) {
29099
+ for (const entry of ignore) {
29100
+ if (typeof entry === "string") {
29101
+ if (message.includes(entry)) return true;
29102
+ } else if (entry.test(message)) {
29103
+ return true;
29104
+ }
29105
+ }
29106
+ return false;
29107
+ }
29108
+ function startAutoCapture(client, options = {}) {
29109
+ if (typeof window === "undefined") return () => {
29110
+ };
29111
+ const sampleRate = options.sampleRate ?? 1;
29112
+ const ignore = options.ignore ?? [];
29113
+ const lastSeen = /* @__PURE__ */ new Map();
29114
+ let sessionCount = 0;
29115
+ let submitting = false;
29116
+ const consider = (rawMessage) => {
29117
+ if (submitting) return;
29118
+ if (!rawMessage) return;
29119
+ if (isIgnored2(rawMessage, ignore)) return;
29120
+ if (sampleRate <= 0) return;
29121
+ if (sampleRate < 1 && Math.random() >= sampleRate) return;
29122
+ const signature = autoCaptureSignature(rawMessage);
29123
+ const now = Date.now();
29124
+ const last = lastSeen.get(signature);
29125
+ if (last !== void 0 && now - last < AUTO_CAPTURE_COOLDOWN_MS) return;
29126
+ if (sessionCount >= AUTO_CAPTURE_SESSION_CAP) return;
29127
+ lastSeen.set(signature, now);
29128
+ sessionCount += 1;
29129
+ submitting = true;
29130
+ options.onCapture?.(signature);
29131
+ void Promise.resolve().then(() => client.submitReport({ trigger: "error", include: { screenshot: false } })).catch(() => {
29132
+ }).finally(() => {
29133
+ submitting = false;
29134
+ });
29135
+ };
29136
+ const onError = (event) => {
29137
+ try {
29138
+ const e = event;
29139
+ const error51 = e.error;
29140
+ const message = e.message || (error51 instanceof Error ? error51.message : error51 != null ? String(error51) : "");
29141
+ consider(message);
29142
+ } catch {
29143
+ }
29144
+ };
29145
+ const onRejection = (event) => {
29146
+ try {
29147
+ const e = event;
29148
+ consider(reasonToMessage(e.reason));
29149
+ } catch {
29150
+ }
29151
+ };
29152
+ window.addEventListener("error", onError);
29153
+ window.addEventListener("unhandledrejection", onRejection);
29154
+ return () => {
29155
+ window.removeEventListener("error", onError);
29156
+ window.removeEventListener("unhandledrejection", onRejection);
29157
+ };
29158
+ }
29075
29159
  var RingBuffer = class {
29076
29160
  constructor(capacity) {
29077
29161
  this.capacity = capacity;
@@ -29917,6 +30001,7 @@ var LensClient = class {
29917
30001
  replayWindowMs;
29918
30002
  debug;
29919
30003
  screenshotEnabled;
30004
+ autoCapture;
29920
30005
  beforeSend;
29921
30006
  app;
29922
30007
  consoleBuffer;
@@ -29931,6 +30016,7 @@ var LensClient = class {
29931
30016
  this.endpoint = (config2.endpoint ?? DEFAULT_ENDPOINT).replace(/\/+$/, "");
29932
30017
  this.debug = config2.debug ?? false;
29933
30018
  this.screenshotEnabled = config2.screenshot ?? true;
30019
+ this.autoCapture = config2.autoCapture;
29934
30020
  this.beforeSend = config2.beforeSend;
29935
30021
  this.app = config2.app ?? {};
29936
30022
  this.replayWindowMs = config2.replay === false ? null : config2.replay?.windowMs ?? DEFAULT_REPLAY_WINDOW_MS;
@@ -29959,6 +30045,15 @@ var LensClient = class {
29959
30045
  this.teardowns.push(installNetwork(this.networkBuffer, this.endpoint));
29960
30046
  this.teardowns.push(installErrors(this.errorBuffer));
29961
30047
  this.replay?.start();
30048
+ if (this.autoCapture?.errors) {
30049
+ this.teardowns.push(
30050
+ startAutoCapture(this, {
30051
+ sampleRate: this.autoCapture.sampleRate,
30052
+ ignore: this.autoCapture.ignore,
30053
+ onCapture: (signature) => this.warn(`auto-capture: submitting report for "${signature}"`)
30054
+ })
30055
+ );
30056
+ }
29962
30057
  }
29963
30058
  stop() {
29964
30059
  if (!this.started) return;
@@ -30019,6 +30114,7 @@ var LensClient = class {
30019
30114
  errors: wantErrors ? errorEntries : [],
30020
30115
  consoleTail: wantConsole ? consoleTail : [],
30021
30116
  networkTail: wantNetwork ? networkTail : [],
30117
+ trigger: input2.trigger ?? "user",
30022
30118
  sdk: { name: SDK_NAME, version: SDK_VERSION }
30023
30119
  };
30024
30120
  if (input2.comment !== void 0) metadata.comment = input2.comment;
@@ -30111,6 +30207,7 @@ export {
30111
30207
  AssetKindSchema,
30112
30208
  AssetRefSchema,
30113
30209
  ReportStatusSchema,
30210
+ ReportTriggerSchema,
30114
30211
  ReportMetadataSchema,
30115
30212
  ReportSchema,
30116
30213
  ReportSummarySchema,
@@ -30144,4 +30241,4 @@ rrweb/dist/rrweb.js:
30144
30241
  PERFORMANCE OF THIS SOFTWARE.
30145
30242
  ***************************************************************************** *)
30146
30243
  */
30147
- //# sourceMappingURL=chunk-U6GBOUCE.js.map
30244
+ //# sourceMappingURL=chunk-LIYEDZV7.js.map