@interfere/types 8.1.6 → 9.0.2

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.
Files changed (92) hide show
  1. package/README.md +3 -3
  2. package/dist/data/frame.d.mts +16 -4
  3. package/dist/data/frame.d.mts.map +1 -1
  4. package/dist/data/frame.mjs +1 -16
  5. package/dist/data/frame.mjs.map +1 -1
  6. package/dist/data/session.d.mts +1 -1
  7. package/dist/data/session.d.mts.map +1 -1
  8. package/dist/data/session.mjs +1 -9
  9. package/dist/data/session.mjs.map +1 -1
  10. package/dist/data/source-maps.d.mts +133 -27
  11. package/dist/data/source-maps.d.mts.map +1 -1
  12. package/dist/data/source-maps.mjs +1 -21
  13. package/dist/data/source-maps.mjs.map +1 -1
  14. package/dist/events/error.d.mts +139 -35
  15. package/dist/events/error.d.mts.map +1 -1
  16. package/dist/events/error.mjs +1 -64
  17. package/dist/events/error.mjs.map +1 -1
  18. package/dist/events/pageleave.d.mts +1 -1
  19. package/dist/events/pageleave.mjs +1 -10
  20. package/dist/events/pageleave.mjs.map +1 -1
  21. package/dist/events/pageview.d.mts +1 -1
  22. package/dist/events/pageview.d.mts.map +1 -1
  23. package/dist/events/pageview.mjs +1 -11
  24. package/dist/events/pageview.mjs.map +1 -1
  25. package/dist/integrations/index.mjs +1 -57
  26. package/dist/integrations/index.mjs.map +1 -1
  27. package/dist/integrations/platforms/github.mjs +1 -13
  28. package/dist/integrations/platforms/github.mjs.map +1 -1
  29. package/dist/integrations/platforms/slack.d.mts +32 -0
  30. package/dist/integrations/platforms/slack.d.mts.map +1 -0
  31. package/dist/integrations/platforms/slack.mjs +1 -0
  32. package/dist/integrations/platforms/slack.mjs.map +1 -0
  33. package/dist/integrations/platforms/vercel.mjs +1 -26
  34. package/dist/integrations/platforms/vercel.mjs.map +1 -1
  35. package/dist/releases/definition.d.mts +2 -1
  36. package/dist/releases/definition.d.mts.map +1 -1
  37. package/dist/releases/definition.mjs +1 -63
  38. package/dist/releases/definition.mjs.map +1 -1
  39. package/dist/releases/slug.d.mts +22 -0
  40. package/dist/releases/slug.d.mts.map +1 -0
  41. package/dist/releases/slug.mjs +1 -0
  42. package/dist/releases/slug.mjs.map +1 -0
  43. package/dist/sdk/env.mjs +1 -17
  44. package/dist/sdk/env.mjs.map +1 -1
  45. package/dist/sdk/envelope.d.mts +161 -34
  46. package/dist/sdk/envelope.d.mts.map +1 -1
  47. package/dist/sdk/envelope.mjs +1 -114
  48. package/dist/sdk/envelope.mjs.map +1 -1
  49. package/dist/sdk/errors.d.mts +87 -30
  50. package/dist/sdk/errors.d.mts.map +1 -1
  51. package/dist/sdk/errors.mjs +2 -253
  52. package/dist/sdk/errors.mjs.map +1 -1
  53. package/dist/sdk/geo.mjs +1 -17
  54. package/dist/sdk/geo.mjs.map +1 -1
  55. package/dist/sdk/identify.d.mts +1 -1
  56. package/dist/sdk/identify.d.mts.map +1 -1
  57. package/dist/sdk/identify.mjs +1 -43
  58. package/dist/sdk/identify.mjs.map +1 -1
  59. package/dist/sdk/plugins/context/browser.d.mts +8 -0
  60. package/dist/sdk/plugins/context/browser.d.mts.map +1 -1
  61. package/dist/sdk/plugins/context/browser.mjs +1 -81
  62. package/dist/sdk/plugins/context/browser.mjs.map +1 -1
  63. package/dist/sdk/plugins/context/edge.mjs +1 -9
  64. package/dist/sdk/plugins/context/edge.mjs.map +1 -1
  65. package/dist/sdk/plugins/context/next.mjs +1 -50
  66. package/dist/sdk/plugins/context/next.mjs.map +1 -1
  67. package/dist/sdk/plugins/context/node.d.mts +12 -0
  68. package/dist/sdk/plugins/context/node.d.mts.map +1 -0
  69. package/dist/sdk/plugins/context/node.mjs +1 -0
  70. package/dist/sdk/plugins/context/node.mjs.map +1 -0
  71. package/dist/sdk/plugins/manifest.d.mts +5 -0
  72. package/dist/sdk/plugins/manifest.d.mts.map +1 -1
  73. package/dist/sdk/plugins/manifest.mjs +1 -62
  74. package/dist/sdk/plugins/manifest.mjs.map +1 -1
  75. package/dist/sdk/plugins/payload/errors.d.mts +27 -18
  76. package/dist/sdk/plugins/payload/errors.d.mts.map +1 -1
  77. package/dist/sdk/plugins/payload/errors.mjs +1 -37
  78. package/dist/sdk/plugins/payload/errors.mjs.map +1 -1
  79. package/dist/sdk/plugins/payload/page-events.d.mts +2 -2
  80. package/dist/sdk/plugins/payload/page-events.mjs +1 -25
  81. package/dist/sdk/plugins/payload/page-events.mjs.map +1 -1
  82. package/dist/sdk/plugins/payload/rage-click.mjs +1 -17
  83. package/dist/sdk/plugins/payload/rage-click.mjs.map +1 -1
  84. package/dist/sdk/plugins/payload/replay.mjs +1 -17
  85. package/dist/sdk/plugins/payload/replay.mjs.map +1 -1
  86. package/dist/sdk/remote-config.d.mts +31 -4
  87. package/dist/sdk/remote-config.d.mts.map +1 -1
  88. package/dist/sdk/remote-config.mjs +1 -5
  89. package/dist/sdk/remote-config.mjs.map +1 -1
  90. package/dist/sdk/runtime.mjs +1 -35
  91. package/dist/sdk/runtime.mjs.map +1 -1
  92. package/package.json +12 -18
@@ -1,114 +1 @@
1
- import { z } from "zod";
2
- import { sessionIdSchema } from "#data/session";
3
- import { browserContextSchema } from "#sdk/plugins/context/browser";
4
- import { edgeContextSchema } from "#sdk/plugins/context/edge";
5
- import { nextjsContextSchema } from "#sdk/plugins/context/next";
6
- import { errorEnvelopePayloadSchema } from "#sdk/plugins/payload/errors";
7
- import { pageleavePayloadSchema, pageviewPayloadSchema, uiEventPayloadSchema } from "#sdk/plugins/payload/page-events";
8
- import { rageClickPayloadSchema } from "#sdk/plugins/payload/rage-click";
9
- import { replayChunkPayloadSchema } from "#sdk/plugins/payload/replay";
10
- import { envSchema, runtimeSchema } from "#sdk/runtime";
11
- //#region src/sdk/envelope.ts
12
- /**
13
- * Indicates how the sessionId was resolved on the server.
14
- *
15
- * - "header": Extracted from x-interfere-request header (ideal case)
16
- * - "async_context": Retrieved from AsyncLocalStorage context
17
- * - "fallback": Generated as server-side fallback (breaks session continuity)
18
- * - "client": Session ID was set on the client (browser SDK)
19
- */
20
- const sessionSourceSchema = z.enum([
21
- "header",
22
- "async_context",
23
- "fallback",
24
- "client"
25
- ]).optional().meta({
26
- id: "SessionSource",
27
- title: "SessionSource",
28
- description: "How the server resolved the sessionId for this envelope."
29
- });
30
- const envelopeContextSchema = z.discriminatedUnion("runtime", [
31
- browserContextSchema,
32
- nextjsContextSchema,
33
- edgeContextSchema
34
- ]).meta({
35
- id: "EnvelopeContext",
36
- title: "EnvelopeContext",
37
- description: "Runtime-specific request context attached to every envelope."
38
- });
39
- const envelopeHeadersShape = {
40
- buildId: z.string(),
41
- clientTs: z.int(),
42
- context: envelopeContextSchema.optional(),
43
- environment: envSchema,
44
- producerVersion: z.string().optional(),
45
- releaseId: z.string().nullable(),
46
- runtime: runtimeSchema,
47
- sdkStack: z.array(z.string()).optional(),
48
- sessionId: sessionIdSchema.nullable(),
49
- sessionSource: sessionSourceSchema,
50
- uuid: z.uuidv7(),
51
- v: z.literal(0)
52
- };
53
- const errorEnvelopeSchema = z.object({
54
- ...envelopeHeadersShape,
55
- type: z.literal("error"),
56
- payload: errorEnvelopePayloadSchema
57
- }).meta({
58
- id: "ErrorEnvelope",
59
- title: "ErrorEnvelope"
60
- });
61
- const pageviewEnvelopeSchema = z.object({
62
- ...envelopeHeadersShape,
63
- type: z.literal("pageview"),
64
- payload: pageviewPayloadSchema
65
- }).meta({
66
- id: "PageviewEnvelope",
67
- title: "PageviewEnvelope"
68
- });
69
- const pageleaveEnvelopeSchema = z.object({
70
- ...envelopeHeadersShape,
71
- type: z.literal("pageleave"),
72
- payload: pageleavePayloadSchema
73
- }).meta({
74
- id: "PageleaveEnvelope",
75
- title: "PageleaveEnvelope"
76
- });
77
- const uiEventEnvelopeSchema = z.object({
78
- ...envelopeHeadersShape,
79
- type: z.literal("ui_event"),
80
- payload: uiEventPayloadSchema
81
- }).meta({
82
- id: "UiEventEnvelope",
83
- title: "UiEventEnvelope"
84
- });
85
- const replayChunkEnvelopeSchema = z.object({
86
- ...envelopeHeadersShape,
87
- type: z.literal("replay_chunk"),
88
- payload: replayChunkPayloadSchema
89
- }).meta({
90
- id: "ReplayChunkEnvelope",
91
- title: "ReplayChunkEnvelope"
92
- });
93
- const rageClickEnvelopeSchema = z.object({
94
- ...envelopeHeadersShape,
95
- type: z.literal("rage_click"),
96
- payload: rageClickPayloadSchema
97
- }).meta({
98
- id: "RageClickEnvelope",
99
- title: "RageClickEnvelope"
100
- });
101
- const envelopeSchema = z.discriminatedUnion("type", [
102
- errorEnvelopeSchema,
103
- pageviewEnvelopeSchema,
104
- pageleaveEnvelopeSchema,
105
- uiEventEnvelopeSchema,
106
- replayChunkEnvelopeSchema,
107
- rageClickEnvelopeSchema
108
- ]).meta({
109
- id: "Envelope",
110
- title: "Envelope",
111
- description: "A single event envelope accepted by the collector."
112
- });
113
- //#endregion
114
- export { envelopeContextSchema, envelopeSchema, errorEnvelopeSchema, pageleaveEnvelopeSchema, pageviewEnvelopeSchema, rageClickEnvelopeSchema, replayChunkEnvelopeSchema, sessionSourceSchema, uiEventEnvelopeSchema };
1
+ import{z as e}from"zod";import{sessionIdSchema as t}from"#data/session";import{browserContextSchema as n}from"#sdk/plugins/context/browser";import{edgeContextSchema as r}from"#sdk/plugins/context/edge";import{nextjsContextSchema as i}from"#sdk/plugins/context/next";import{nodeContextSchema as a}from"#sdk/plugins/context/node";import{errorEnvelopePayloadSchema as o}from"#sdk/plugins/payload/errors";import{pageleavePayloadSchema as s,pageviewPayloadSchema as c,uiEventPayloadSchema as l}from"#sdk/plugins/payload/page-events";import{rageClickPayloadSchema as u}from"#sdk/plugins/payload/rage-click";import{replayChunkPayloadSchema as d}from"#sdk/plugins/payload/replay";import{envSchema as f,runtimeSchema as p}from"#sdk/runtime";const m=e.enum([`header`,`async_context`,`fallback`,`client`]).optional().meta({id:`SessionSource`,title:`SessionSource`,description:`How the server resolved the sessionId for this envelope.`}),h=e.discriminatedUnion(`runtime`,[n,i,r,a]).meta({id:`EnvelopeContext`,title:`EnvelopeContext`,description:`Runtime-specific request context attached to every envelope.`}),g={buildId:e.string(),clientTs:e.int(),context:h.optional(),environment:f,producerVersion:e.string().optional(),releaseId:e.string().nullable(),runtime:p,sdkStack:e.array(e.string()).optional(),sessionId:t.nullable(),sessionSource:m,uuid:e.uuidv7(),v:e.literal(0)},_=e.object({...g,type:e.literal(`error`),payload:o}).meta({id:`ErrorEnvelope`,title:`ErrorEnvelope`}),v=e.object({...g,type:e.literal(`pageview`),payload:c}).meta({id:`PageviewEnvelope`,title:`PageviewEnvelope`}),y=e.object({...g,type:e.literal(`pageleave`),payload:s}).meta({id:`PageleaveEnvelope`,title:`PageleaveEnvelope`}),b=e.object({...g,type:e.literal(`ui_event`),payload:l}).meta({id:`UiEventEnvelope`,title:`UiEventEnvelope`}),x=e.object({...g,type:e.literal(`replay_chunk`),payload:d}).meta({id:`ReplayChunkEnvelope`,title:`ReplayChunkEnvelope`}),S=e.object({...g,type:e.literal(`rage_click`),payload:u}).meta({id:`RageClickEnvelope`,title:`RageClickEnvelope`}),C=e.discriminatedUnion(`type`,[_,v,y,b,x,S]).meta({id:`Envelope`,title:`Envelope`,description:`A single event envelope accepted by the collector.`});export{h as envelopeContextSchema,C as envelopeSchema,_ as errorEnvelopeSchema,y as pageleaveEnvelopeSchema,v as pageviewEnvelopeSchema,S as rageClickEnvelopeSchema,x as replayChunkEnvelopeSchema,m as sessionSourceSchema,b as uiEventEnvelopeSchema};
@@ -1 +1 @@
1
- {"version":3,"file":"envelope.mjs","names":[],"sources":["../../src/sdk/envelope.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport { sessionIdSchema } from \"#data/session\";\nimport { browserContextSchema } from \"#sdk/plugins/context/browser\";\nimport { edgeContextSchema } from \"#sdk/plugins/context/edge\";\nimport { nextjsContextSchema } from \"#sdk/plugins/context/next\";\nimport { errorEnvelopePayloadSchema } from \"#sdk/plugins/payload/errors\";\nimport {\n pageleavePayloadSchema,\n pageviewPayloadSchema,\n uiEventPayloadSchema,\n} from \"#sdk/plugins/payload/page-events\";\nimport { rageClickPayloadSchema } from \"#sdk/plugins/payload/rage-click\";\nimport { replayChunkPayloadSchema } from \"#sdk/plugins/payload/replay\";\nimport { envSchema, runtimeSchema } from \"#sdk/runtime\";\n\n/**\n * Indicates how the sessionId was resolved on the server.\n *\n * - \"header\": Extracted from x-interfere-request header (ideal case)\n * - \"async_context\": Retrieved from AsyncLocalStorage context\n * - \"fallback\": Generated as server-side fallback (breaks session continuity)\n * - \"client\": Session ID was set on the client (browser SDK)\n */\nexport const sessionSourceSchema = z\n .enum([\"header\", \"async_context\", \"fallback\", \"client\"])\n .optional()\n .meta({\n id: \"SessionSource\",\n title: \"SessionSource\",\n description: \"How the server resolved the sessionId for this envelope.\",\n });\n\nexport type SessionSource = z.infer<typeof sessionSourceSchema>;\n\nexport const envelopeContextSchema = z\n .discriminatedUnion(\"runtime\", [\n browserContextSchema,\n nextjsContextSchema,\n edgeContextSchema,\n ])\n .meta({\n id: \"EnvelopeContext\",\n title: \"EnvelopeContext\",\n description: \"Runtime-specific request context attached to every envelope.\",\n });\n\nexport type EnvelopeContext = z.infer<typeof envelopeContextSchema>;\n\nconst envelopeHeadersShape = {\n buildId: z.string(),\n clientTs: z.int(),\n context: envelopeContextSchema.optional(),\n environment: envSchema,\n producerVersion: z.string().optional(),\n releaseId: z.string().nullable(),\n runtime: runtimeSchema,\n sdkStack: z.array(z.string()).optional(),\n sessionId: sessionIdSchema.nullable(),\n sessionSource: sessionSourceSchema,\n uuid: z.uuidv7(),\n v: z.literal(0),\n} as const;\n\nexport const errorEnvelopeSchema = z\n .object({\n ...envelopeHeadersShape,\n type: z.literal(\"error\"),\n payload: errorEnvelopePayloadSchema,\n })\n .meta({ id: \"ErrorEnvelope\", title: \"ErrorEnvelope\" });\n\nexport const pageviewEnvelopeSchema = z\n .object({\n ...envelopeHeadersShape,\n type: z.literal(\"pageview\"),\n payload: pageviewPayloadSchema,\n })\n .meta({ id: \"PageviewEnvelope\", title: \"PageviewEnvelope\" });\n\nexport const pageleaveEnvelopeSchema = z\n .object({\n ...envelopeHeadersShape,\n type: z.literal(\"pageleave\"),\n payload: pageleavePayloadSchema,\n })\n .meta({ id: \"PageleaveEnvelope\", title: \"PageleaveEnvelope\" });\n\nexport const uiEventEnvelopeSchema = z\n .object({\n ...envelopeHeadersShape,\n type: z.literal(\"ui_event\"),\n payload: uiEventPayloadSchema,\n })\n .meta({ id: \"UiEventEnvelope\", title: \"UiEventEnvelope\" });\n\nexport const replayChunkEnvelopeSchema = z\n .object({\n ...envelopeHeadersShape,\n type: z.literal(\"replay_chunk\"),\n payload: replayChunkPayloadSchema,\n })\n .meta({ id: \"ReplayChunkEnvelope\", title: \"ReplayChunkEnvelope\" });\n\nexport const rageClickEnvelopeSchema = z\n .object({\n ...envelopeHeadersShape,\n type: z.literal(\"rage_click\"),\n payload: rageClickPayloadSchema,\n })\n .meta({ id: \"RageClickEnvelope\", title: \"RageClickEnvelope\" });\n\nexport const envelopeSchema = z\n .discriminatedUnion(\"type\", [\n errorEnvelopeSchema,\n pageviewEnvelopeSchema,\n pageleaveEnvelopeSchema,\n uiEventEnvelopeSchema,\n replayChunkEnvelopeSchema,\n rageClickEnvelopeSchema,\n ])\n .meta({\n id: \"Envelope\",\n title: \"Envelope\",\n description: \"A single event envelope accepted by the collector.\",\n });\n\ntype EnvelopeBase = z.infer<typeof envelopeSchema>;\n\nexport type EventType = EnvelopeBase[\"type\"];\n\nexport type Envelope<T extends EventType | undefined = undefined> =\n T extends EventType ? Extract<EnvelopeBase, { type: T }> : EnvelopeBase;\n\nexport type EnvelopePayload<T extends EventType> = Envelope<T>[\"payload\"];\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwBA,MAAa,sBAAsB,EAChC,KAAK;CAAC;CAAU;CAAiB;CAAY;CAAS,CAAC,CACvD,UAAU,CACV,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACd,CAAC;AAIJ,MAAa,wBAAwB,EAClC,mBAAmB,WAAW;CAC7B;CACA;CACA;CACD,CAAC,CACD,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACd,CAAC;AAIJ,MAAM,uBAAuB;CAC3B,SAAS,EAAE,QAAQ;CACnB,UAAU,EAAE,KAAK;CACjB,SAAS,sBAAsB,UAAU;CACzC,aAAa;CACb,iBAAiB,EAAE,QAAQ,CAAC,UAAU;CACtC,WAAW,EAAE,QAAQ,CAAC,UAAU;CAChC,SAAS;CACT,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CACxC,WAAW,gBAAgB,UAAU;CACrC,eAAe;CACf,MAAM,EAAE,QAAQ;CAChB,GAAG,EAAE,QAAQ,EAAE;CAChB;AAED,MAAa,sBAAsB,EAChC,OAAO;CACN,GAAG;CACH,MAAM,EAAE,QAAQ,QAAQ;CACxB,SAAS;CACV,CAAC,CACD,KAAK;CAAE,IAAI;CAAiB,OAAO;CAAiB,CAAC;AAExD,MAAa,yBAAyB,EACnC,OAAO;CACN,GAAG;CACH,MAAM,EAAE,QAAQ,WAAW;CAC3B,SAAS;CACV,CAAC,CACD,KAAK;CAAE,IAAI;CAAoB,OAAO;CAAoB,CAAC;AAE9D,MAAa,0BAA0B,EACpC,OAAO;CACN,GAAG;CACH,MAAM,EAAE,QAAQ,YAAY;CAC5B,SAAS;CACV,CAAC,CACD,KAAK;CAAE,IAAI;CAAqB,OAAO;CAAqB,CAAC;AAEhE,MAAa,wBAAwB,EAClC,OAAO;CACN,GAAG;CACH,MAAM,EAAE,QAAQ,WAAW;CAC3B,SAAS;CACV,CAAC,CACD,KAAK;CAAE,IAAI;CAAmB,OAAO;CAAmB,CAAC;AAE5D,MAAa,4BAA4B,EACtC,OAAO;CACN,GAAG;CACH,MAAM,EAAE,QAAQ,eAAe;CAC/B,SAAS;CACV,CAAC,CACD,KAAK;CAAE,IAAI;CAAuB,OAAO;CAAuB,CAAC;AAEpE,MAAa,0BAA0B,EACpC,OAAO;CACN,GAAG;CACH,MAAM,EAAE,QAAQ,aAAa;CAC7B,SAAS;CACV,CAAC,CACD,KAAK;CAAE,IAAI;CAAqB,OAAO;CAAqB,CAAC;AAEhE,MAAa,iBAAiB,EAC3B,mBAAmB,QAAQ;CAC1B;CACA;CACA;CACA;CACA;CACA;CACD,CAAC,CACD,KAAK;CACJ,IAAI;CACJ,OAAO;CACP,aAAa;CACd,CAAC"}
1
+ {"version":3,"file":"envelope.mjs","names":[],"sources":["../../src/sdk/envelope.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport { sessionIdSchema } from \"#data/session\";\nimport { browserContextSchema } from \"#sdk/plugins/context/browser\";\nimport { edgeContextSchema } from \"#sdk/plugins/context/edge\";\nimport { nextjsContextSchema } from \"#sdk/plugins/context/next\";\nimport { nodeContextSchema } from \"#sdk/plugins/context/node\";\nimport { errorEnvelopePayloadSchema } from \"#sdk/plugins/payload/errors\";\nimport {\n pageleavePayloadSchema,\n pageviewPayloadSchema,\n uiEventPayloadSchema,\n} from \"#sdk/plugins/payload/page-events\";\nimport { rageClickPayloadSchema } from \"#sdk/plugins/payload/rage-click\";\nimport { replayChunkPayloadSchema } from \"#sdk/plugins/payload/replay\";\nimport { envSchema, runtimeSchema } from \"#sdk/runtime\";\n\n/**\n * Indicates how the sessionId was resolved on the server.\n *\n * - \"header\": Extracted from x-interfere-request header (ideal case)\n * - \"async_context\": Retrieved from AsyncLocalStorage context\n * - \"fallback\": Generated as server-side fallback (breaks session continuity)\n * - \"client\": Session ID was set on the client (browser SDK)\n */\nexport const sessionSourceSchema = z\n .enum([\"header\", \"async_context\", \"fallback\", \"client\"])\n .optional()\n .meta({\n id: \"SessionSource\",\n title: \"SessionSource\",\n description: \"How the server resolved the sessionId for this envelope.\",\n });\n\nexport type SessionSource = z.infer<typeof sessionSourceSchema>;\n\nexport const envelopeContextSchema = z\n .discriminatedUnion(\"runtime\", [\n browserContextSchema,\n nextjsContextSchema,\n edgeContextSchema,\n nodeContextSchema,\n ])\n .meta({\n id: \"EnvelopeContext\",\n title: \"EnvelopeContext\",\n description: \"Runtime-specific request context attached to every envelope.\",\n });\n\nexport type EnvelopeContext = z.infer<typeof envelopeContextSchema>;\n\nconst envelopeHeadersShape = {\n buildId: z.string(),\n clientTs: z.int(),\n context: envelopeContextSchema.optional(),\n environment: envSchema,\n producerVersion: z.string().optional(),\n releaseId: z.string().nullable(),\n runtime: runtimeSchema,\n sdkStack: z.array(z.string()).optional(),\n sessionId: sessionIdSchema.nullable(),\n sessionSource: sessionSourceSchema,\n uuid: z.uuidv7(),\n v: z.literal(0),\n} as const;\n\nexport const errorEnvelopeSchema = z\n .object({\n ...envelopeHeadersShape,\n type: z.literal(\"error\"),\n payload: errorEnvelopePayloadSchema,\n })\n .meta({ id: \"ErrorEnvelope\", title: \"ErrorEnvelope\" });\n\nexport const pageviewEnvelopeSchema = z\n .object({\n ...envelopeHeadersShape,\n type: z.literal(\"pageview\"),\n payload: pageviewPayloadSchema,\n })\n .meta({ id: \"PageviewEnvelope\", title: \"PageviewEnvelope\" });\n\nexport const pageleaveEnvelopeSchema = z\n .object({\n ...envelopeHeadersShape,\n type: z.literal(\"pageleave\"),\n payload: pageleavePayloadSchema,\n })\n .meta({ id: \"PageleaveEnvelope\", title: \"PageleaveEnvelope\" });\n\nexport const uiEventEnvelopeSchema = z\n .object({\n ...envelopeHeadersShape,\n type: z.literal(\"ui_event\"),\n payload: uiEventPayloadSchema,\n })\n .meta({ id: \"UiEventEnvelope\", title: \"UiEventEnvelope\" });\n\nexport const replayChunkEnvelopeSchema = z\n .object({\n ...envelopeHeadersShape,\n type: z.literal(\"replay_chunk\"),\n payload: replayChunkPayloadSchema,\n })\n .meta({ id: \"ReplayChunkEnvelope\", title: \"ReplayChunkEnvelope\" });\n\nexport const rageClickEnvelopeSchema = z\n .object({\n ...envelopeHeadersShape,\n type: z.literal(\"rage_click\"),\n payload: rageClickPayloadSchema,\n })\n .meta({ id: \"RageClickEnvelope\", title: \"RageClickEnvelope\" });\n\nexport const envelopeSchema = z\n .discriminatedUnion(\"type\", [\n errorEnvelopeSchema,\n pageviewEnvelopeSchema,\n pageleaveEnvelopeSchema,\n uiEventEnvelopeSchema,\n replayChunkEnvelopeSchema,\n rageClickEnvelopeSchema,\n ])\n .meta({\n id: \"Envelope\",\n title: \"Envelope\",\n description: \"A single event envelope accepted by the collector.\",\n });\n\ntype EnvelopeBase = z.infer<typeof envelopeSchema>;\n\nexport type EventType = EnvelopeBase[\"type\"];\n\nexport type Envelope<T extends EventType | undefined = undefined> =\n T extends EventType ? Extract<EnvelopeBase, { type: T }> : EnvelopeBase;\n\nexport type EnvelopePayload<T extends EventType> = Envelope<T>[\"payload\"];\n"],"mappings":"4tBAyBA,MAAa,EAAsB,EAChC,KAAK,CAAC,SAAU,gBAAiB,WAAY,SAAS,CAAC,CACvD,UAAU,CACV,KAAK,CACJ,GAAI,gBACJ,MAAO,gBACP,YAAa,2DACd,CAAC,CAIS,EAAwB,EAClC,mBAAmB,UAAW,CAC7B,EACA,EACA,EACA,EACD,CAAC,CACD,KAAK,CACJ,GAAI,kBACJ,MAAO,kBACP,YAAa,+DACd,CAAC,CAIE,EAAuB,CAC3B,QAAS,EAAE,QAAQ,CACnB,SAAU,EAAE,KAAK,CACjB,QAAS,EAAsB,UAAU,CACzC,YAAa,EACb,gBAAiB,EAAE,QAAQ,CAAC,UAAU,CACtC,UAAW,EAAE,QAAQ,CAAC,UAAU,CAChC,QAAS,EACT,SAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU,CACxC,UAAW,EAAgB,UAAU,CACrC,cAAe,EACf,KAAM,EAAE,QAAQ,CAChB,EAAG,EAAE,QAAQ,EAAE,CAChB,CAEY,EAAsB,EAChC,OAAO,CACN,GAAG,EACH,KAAM,EAAE,QAAQ,QAAQ,CACxB,QAAS,EACV,CAAC,CACD,KAAK,CAAE,GAAI,gBAAiB,MAAO,gBAAiB,CAAC,CAE3C,EAAyB,EACnC,OAAO,CACN,GAAG,EACH,KAAM,EAAE,QAAQ,WAAW,CAC3B,QAAS,EACV,CAAC,CACD,KAAK,CAAE,GAAI,mBAAoB,MAAO,mBAAoB,CAAC,CAEjD,EAA0B,EACpC,OAAO,CACN,GAAG,EACH,KAAM,EAAE,QAAQ,YAAY,CAC5B,QAAS,EACV,CAAC,CACD,KAAK,CAAE,GAAI,oBAAqB,MAAO,oBAAqB,CAAC,CAEnD,EAAwB,EAClC,OAAO,CACN,GAAG,EACH,KAAM,EAAE,QAAQ,WAAW,CAC3B,QAAS,EACV,CAAC,CACD,KAAK,CAAE,GAAI,kBAAmB,MAAO,kBAAmB,CAAC,CAE/C,EAA4B,EACtC,OAAO,CACN,GAAG,EACH,KAAM,EAAE,QAAQ,eAAe,CAC/B,QAAS,EACV,CAAC,CACD,KAAK,CAAE,GAAI,sBAAuB,MAAO,sBAAuB,CAAC,CAEvD,EAA0B,EACpC,OAAO,CACN,GAAG,EACH,KAAM,EAAE,QAAQ,aAAa,CAC7B,QAAS,EACV,CAAC,CACD,KAAK,CAAE,GAAI,oBAAqB,MAAO,oBAAqB,CAAC,CAEnD,EAAiB,EAC3B,mBAAmB,OAAQ,CAC1B,EACA,EACA,EACA,EACA,EACA,EACD,CAAC,CACD,KAAK,CACJ,GAAI,WACJ,MAAO,WACP,YAAa,qDACd,CAAC"}
@@ -33,47 +33,47 @@ declare const MECHANISM_TYPE: {
33
33
  readonly onRequestError: "auto.function.nextjs.on_request_error";
34
34
  readonly captureError: "auto.function.nextjs.capture_error";
35
35
  };
36
+ readonly node: {
37
+ readonly captureError: "auto.function.node.capture_error";
38
+ readonly uncaughtException: "auto.node.global_handlers.uncaught_exception";
39
+ readonly unhandledRejection: "auto.node.global_handlers.unhandled_rejection";
40
+ };
41
+ readonly manual: {
42
+ /** Customer called `capture(error)` from `@interfere/react/api`. */readonly capture: "manual.api.capture";
43
+ };
36
44
  };
37
45
  /**
38
- * True when any exception in the cause chain has at least one stack frame
39
- * whose `fileName` is a browser-extension script URL. Covers extension-only
40
- * stacks, extension interceptors (extension frames above app), app errors
41
- * whose stack still includes extension code (e.g. hydration), and errors
42
- * whose outer throw is app code but whose inner `.cause` originated in an
43
- * extension. Stacks with no filenames are unchanged (returns false).
44
- */
45
- declare function shouldDropBrowserExtensionNoise(exceptions: readonly ExceptionValue[]): boolean;
46
- /**
47
- * True when no frame across the full cause chain carries any `fileName`.
46
+ * True when the raw stack mentions any browser-extension URL scheme
47
+ * anywhere. Catches extension-only stacks, extension interceptors
48
+ * (extension frames above app), and app errors whose stack still
49
+ * includes extension code (e.g. extension hydration). Cause-chain
50
+ * variants are caught by passing the chain entries' stacks to this
51
+ * check separately.
48
52
  *
49
- * Such stacks are structurally uninvestigatable: they come from inline
50
- * `<script>` blocks (`at <anonymous>:N:M`), `eval()` / `new Function()`,
51
- * CORS-masked cross-origin scripts (`"Script error."`), or browser-internal
52
- * code with no URL. No source map can resolve them, no repo lookup can find
53
- * them, and the agent has nothing to reason over. Dropping at capture time
54
- * prevents them from dominating ingest volume.
53
+ * Server-side parsing has full structured fidelity, but the noise
54
+ * filter runs at capture time before a parsed stack exists — regex
55
+ * over the raw string is sufficient and avoids pulling a parser into
56
+ * the customer bundle.
55
57
  */
56
- declare function shouldDropUnresolvableStack(exceptions: readonly ExceptionValue[]): boolean;
58
+ declare function shouldDropBrowserExtensionNoise(stacks: readonly string[]): boolean;
57
59
  /**
58
- * Normalizes an `Error.stack` string before feeding it to the stack parser.
59
- *
60
- * - Truncates each line to {@link MAX_STACK_LINE_LENGTH} to prevent ReDoS on
61
- * pathological inputs (a single frame with a 100 KiB URL can stall the
62
- * main thread for seconds in a regex-based parser).
63
- * - Strips the trailing `(error: *)` suffix some webpack builds emit.
60
+ * True when **none** of the supplied stacks (head + cause chain entries)
61
+ * carries any source-location anchor. Non-Error rejections (no stack at
62
+ * all) are exempt at the call site they ship structured payloads the
63
+ * agent can reason over without frames.
64
64
  */
65
- declare function preprocessStack(stack: string): string;
65
+ declare function shouldDropUnresolvableStack(stacks: readonly string[]): boolean;
66
66
  /**
67
67
  * Parses a React `errorInfo.componentStack` string into synthetic frames.
68
+ * Server-side stack parsing handles JS frames; component-stack frames are
69
+ * supplementary context React emits separately and have a different shape,
70
+ * so they're parsed at capture time and shipped via `appendFrames`.
68
71
  *
69
72
  * React produces different formats across versions:
70
73
  * - React 16–18 legacy: ` in ComponentName`
71
74
  * ` in ComponentName (created by Parent)`
72
75
  * - React 19 owner stacks: ` at ComponentName`
73
76
  * ` at ComponentName (file.tsx:10:5)`
74
- *
75
- * Each line becomes one frame with the component as `functionName`. When file
76
- * positions are present (React 19), they're preserved.
77
77
  */
78
78
  declare function parseReactComponentStack(componentStack: string): IngestedFrame[];
79
79
  /**
@@ -90,7 +90,64 @@ declare function parseReactComponentStack(componentStack: string): IngestedFrame
90
90
  * it's the documented ES2022 convention.
91
91
  */
92
92
  declare function toError(error: unknown): Error;
93
- declare function toExceptions(error: Error, mechanism: ErrorMechanism): ExceptionValue[];
94
- declare function extractFilenameFromStack(stack: string): string | null;
93
+ /**
94
+ * Capture-side variant for thrown values that aren't Errors and don't
95
+ * carry a nested Error (e.g. `Promise.reject({ code: 401, body: "..." })`,
96
+ * `Promise.reject(42)`). The structured payload rides on `serialized`
97
+ * so downstream consumers can render the original shape instead of
98
+ * parsing JSON back out of an Error's message string.
99
+ *
100
+ * Strings are *not* represented here — `Promise.reject("boom")` maps
101
+ * cleanly to `new Error("boom")` without lying about the shape, so it
102
+ * goes through `toException`'s Error branch.
103
+ */
104
+ interface NonErrorException {
105
+ readonly kind: "non-error";
106
+ /**
107
+ * Original payload, depth-bounded and circular-safe. Anything beyond
108
+ * `MAX_NON_ERROR_DEPTH` is collapsed to `"[depth-limit]"`; circular
109
+ * back-edges become `"[circular]"`. Primitives pass through unchanged.
110
+ */
111
+ readonly serialized: unknown;
112
+ /**
113
+ * Stable label for grouping. `"PlainObject"` / `"Array"` / `"number"`
114
+ * etc. — derived from the value's structural class, not its content,
115
+ * so two `Promise.reject({ code: 401 })` calls land in the same group
116
+ * regardless of which keys the object carries.
117
+ */
118
+ readonly type: string;
119
+ /**
120
+ * Best-effort one-liner. For objects: a sorted list of keys. For
121
+ * primitives: `String(value)`. The dashboard shows this; the
122
+ * `serialized` field carries the actual payload.
123
+ */
124
+ readonly value: string;
125
+ }
126
+ /**
127
+ * Coerces any thrown value into either an `Error` (when one is
128
+ * recoverable — direct Error, or nested Error inside an object via
129
+ * `cause` / first-Error-valued property — or a string, which maps
130
+ * cleanly to `new Error(str)`) or a structured `NonErrorException`
131
+ * carrying the original payload.
132
+ *
133
+ * Replaces `toError` for capture sites that handle both branches
134
+ * (today: `unhandledrejection`). `toError` is kept for callers that
135
+ * specifically need an `Error` (`<ErrorBoundary>` interop, browser
136
+ * APIs that take Error-typed args).
137
+ */
138
+ declare function toException(value: unknown): Error | NonErrorException;
139
+ declare function isNonErrorException(value: unknown): value is NonErrorException;
140
+ /**
141
+ * Walks `Error.cause` to flatten the chain into the wire shape the
142
+ * collector expects. Each entry carries `type` / `value` / `mechanism?`
143
+ * plus the raw `stack` string — the SDK ships **no parsed frames**.
144
+ * Server-side ingest parses `stack` into structured `IngestedFrame[]`
145
+ * via the collector's stack parser (see
146
+ * `src/services/collector/src/lib/stack-parser.ts`).
147
+ *
148
+ * Non-Error rejections short-circuit to a single `kind: "non-error"`
149
+ * entry with the structured payload on `serialized`.
150
+ */
151
+ declare function toExceptions(value: Error | NonErrorException, mechanism: ErrorMechanism): ExceptionValue[];
95
152
  //#endregion
96
- export { MECHANISM_TYPE, extractFilenameFromStack, parseReactComponentStack, preprocessStack, shouldDropBrowserExtensionNoise, shouldDropUnresolvableStack, toError, toExceptions };
153
+ export { MECHANISM_TYPE, NonErrorException, isNonErrorException, parseReactComponentStack, shouldDropBrowserExtensionNoise, shouldDropUnresolvableStack, toError, toException, toExceptions };
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/sdk/errors.ts"],"mappings":";;;;;;AAsBA;;;;;;;;;;;;cAAa,cAAA;EAAA;;;;;;;;;;;;;;;;;;;;;AAuJb;;;;iBAtGgB,+BAAA,CACd,UAAA,WAAqB,cAAA;AAkJvB;;;;;AA0BA;;;;;AA1BA,iBAjIgB,2BAAA,CACd,UAAA,WAAqB,cAAA;;;;;;;;;iBA4CP,eAAA,CAAgB,KAAA;AA8MhC;;;;;;;;;;;;AAAA,iBAvKgB,wBAAA,CACd,cAAA,WACC,aAAA;;;;;;;;;;;;;;iBA2Ca,OAAA,CAAQ,KAAA,YAAiB,KAAA;AAAA,iBA0BzB,YAAA,CACd,KAAA,EAAO,KAAA,EACP,SAAA,EAAW,cAAA,GACV,cAAA;AAAA,iBA6Fa,wBAAA,CAAyB,KAAA"}
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../../src/sdk/errors.ts"],"mappings":";;;;;;AAoBA;;;;;;;;;;;;cAAa,cAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;IAiHG;;;;AAgDhB;;;;;AAmEA;;;;;;;iBAlLgB,+BAAA,CACd,MAAA;;;AAmTF;;;;iBA5RgB,2BAAA,CACd,MAAA;;;;;AAgTF;;;;;;;;iBA1QgB,wBAAA,CACd,cAAA,WACC,aAAA;AA6RH;;;;;;;;;;;;;AAAA,iBA/OgB,OAAA,CAAQ,KAAA,YAAiB,KAAA;;;;;;;;;;;;UAmExB,iBAAA;EAAA,SACN,IAAA;;;;;;WAMA,UAAA;;;;;;;WAOA,IAAA;;;;;;WAMA,KAAA;AAAA;;;;;;;;;;;;;iBA8GK,WAAA,CAAY,KAAA,YAAiB,KAAA,GAAQ,iBAAA;AAAA,iBAqBrC,mBAAA,CACd,KAAA,YACC,KAAA,IAAS,iBAAA;;;;;;;;;;;;iBAmBI,YAAA,CACd,KAAA,EAAO,KAAA,GAAQ,iBAAA,EACf,SAAA,EAAW,cAAA,GACV,cAAA"}
@@ -1,253 +1,2 @@
1
- import { parse } from "error-stack-parser-es";
2
- //#region src/sdk/errors.ts
3
- /**
4
- * Structured taxonomy of capture sources, tagged onto each
5
- * `ErrorMechanism.type`. Follows the `auto.<surface>.<library>.<method>`
6
- * convention Sentry also uses, so downstream analytics / classification can
7
- * group on common prefixes:
8
- *
9
- * `auto.browser.*` — captured by SDK global handlers in the browser
10
- * `auto.function.*` — captured by SDK functions (boundaries, callbacks,
11
- * server wrappers)
12
- *
13
- * Leaves (`.onerror`, `.error_boundary`, `.on_request_error`, …) identify
14
- * the specific capture site, which lets the agent's skill classifier reason
15
- * about what "kind" of event this is without string-matching loose names.
16
- */
17
- const MECHANISM_TYPE = {
18
- browser: {
19
- onerror: "auto.browser.global_handlers.onerror",
20
- onunhandledrejection: "auto.browser.global_handlers.onunhandledrejection",
21
- consoleError: "auto.browser.console.error"
22
- },
23
- react: {
24
- errorBoundary: "auto.function.react.error_boundary",
25
- captureBoundary: "auto.function.react.capture_boundary",
26
- caughtError: "auto.function.react.caught_error",
27
- uncaughtError: "auto.function.react.uncaught_error",
28
- recoverableError: "auto.function.react.recoverable_error"
29
- },
30
- nextjs: {
31
- onRequestError: "auto.function.nextjs.on_request_error",
32
- captureError: "auto.function.nextjs.capture_error"
33
- }
34
- };
35
- /**
36
- * URL schemes used by browser extensions in stack frame `fileName` values.
37
- *
38
- * `webkit-masked-url://` is Safari's opaque scheme introduced to mask the
39
- * origin of content scripts under ITP — it serves the same purpose as the
40
- * `*-extension://` schemes from a noise-filtering perspective.
41
- */
42
- const BROWSER_EXTENSION_SCRIPT_URL_PREFIXES = [
43
- "chrome-extension://",
44
- "moz-extension://",
45
- "safari-web-extension://",
46
- "safari-extension://",
47
- "ms-browser-extension://",
48
- "webkit-masked-url://"
49
- ];
50
- function isExtensionOriginated({ fileName }) {
51
- return BROWSER_EXTENSION_SCRIPT_URL_PREFIXES.some((prefix) => fileName?.startsWith(prefix) ?? false);
52
- }
53
- /**
54
- * True when any exception in the cause chain has at least one stack frame
55
- * whose `fileName` is a browser-extension script URL. Covers extension-only
56
- * stacks, extension interceptors (extension frames above app), app errors
57
- * whose stack still includes extension code (e.g. hydration), and errors
58
- * whose outer throw is app code but whose inner `.cause` originated in an
59
- * extension. Stacks with no filenames are unchanged (returns false).
60
- */
61
- function shouldDropBrowserExtensionNoise(exceptions) {
62
- return exceptions.some((exception) => exception.frames?.some(isExtensionOriginated) ?? false);
63
- }
64
- /**
65
- * True when no frame across the full cause chain carries any `fileName`.
66
- *
67
- * Such stacks are structurally uninvestigatable: they come from inline
68
- * `<script>` blocks (`at <anonymous>:N:M`), `eval()` / `new Function()`,
69
- * CORS-masked cross-origin scripts (`"Script error."`), or browser-internal
70
- * code with no URL. No source map can resolve them, no repo lookup can find
71
- * them, and the agent has nothing to reason over. Dropping at capture time
72
- * prevents them from dominating ingest volume.
73
- */
74
- function shouldDropUnresolvableStack(exceptions) {
75
- for (const exception of exceptions) {
76
- const frames = exception.frames;
77
- if (!frames?.length) continue;
78
- if (frames.some((frame) => typeof frame.fileName === "string")) return false;
79
- }
80
- return true;
81
- }
82
- const MAX_CAUSE_DEPTH = 5;
83
- /**
84
- * Upper bound for any single stack-trace line. Pathologically long lines can
85
- * trigger catastrophic backtracking in regex-based stack parsers (the
86
- * `error-stack-parser-es` library we depend on is regex-driven). Sentry uses
87
- * the same 1 KiB ceiling for the same reason.
88
- */
89
- const MAX_STACK_LINE_LENGTH = 1024;
90
- /**
91
- * Webpack emits `(error: *)` wrappers around stack frames under certain
92
- * devtool configurations. The pattern is always a trailing suffix; trimming
93
- * it lets the downstream parser see a clean `at fn (file:L:C)`.
94
- */
95
- const WEBPACK_ERROR_WRAPPER_RE = /\s*\(error:\s+\*\)$/;
96
- const PAREN_FILE_RE = /\((.+?)(?::\d+){1,2}\)/;
97
- const AT_FILE_RE = /at\s+(.+?)(?::\d+){1,2}$/;
98
- const SPIDERMONKEY_RE = /(?:^|@)((?:https?:\/\/|\/).+?)(?::\d+){1,2}$/;
99
- const BARE_FILE_RE = /(?:^|@)(.+?)(?::\d+){1,2}$/;
100
- /**
101
- * Normalizes an `Error.stack` string before feeding it to the stack parser.
102
- *
103
- * - Truncates each line to {@link MAX_STACK_LINE_LENGTH} to prevent ReDoS on
104
- * pathological inputs (a single frame with a 100 KiB URL can stall the
105
- * main thread for seconds in a regex-based parser).
106
- * - Strips the trailing `(error: *)` suffix some webpack builds emit.
107
- */
108
- function preprocessStack(stack) {
109
- if (!stack) return stack;
110
- const out = [];
111
- for (const rawLine of stack.split("\n")) {
112
- const line = rawLine.length > MAX_STACK_LINE_LENGTH ? rawLine.slice(0, MAX_STACK_LINE_LENGTH) : rawLine;
113
- out.push(line.replace(WEBPACK_ERROR_WRAPPER_RE, ""));
114
- }
115
- return out.join("\n");
116
- }
117
- /**
118
- * Matches one React component-stack line. Captures:
119
- * 1. component name
120
- * 2. optional file name (required to have a line number, to avoid matching
121
- * "(created by Parent)" annotations emitted by React 16-18)
122
- * 3. optional line number
123
- * 4. optional column number
124
- */
125
- const COMPONENT_STACK_RE = /^(?:in|at)\s+([^\s(]+)(?:\s+\(([^\s:)]+):(\d+)(?::(\d+))?\))?/;
126
- /**
127
- * Parses a React `errorInfo.componentStack` string into synthetic frames.
128
- *
129
- * React produces different formats across versions:
130
- * - React 16–18 legacy: ` in ComponentName`
131
- * ` in ComponentName (created by Parent)`
132
- * - React 19 owner stacks: ` at ComponentName`
133
- * ` at ComponentName (file.tsx:10:5)`
134
- *
135
- * Each line becomes one frame with the component as `functionName`. When file
136
- * positions are present (React 19), they're preserved.
137
- */
138
- function parseReactComponentStack(componentStack) {
139
- const frames = [];
140
- for (const rawLine of componentStack.split("\n")) {
141
- const line = rawLine.trim();
142
- if (!line) continue;
143
- const match = COMPONENT_STACK_RE.exec(line);
144
- if (!match) continue;
145
- const [, name, fileName, lineStr, colStr] = match;
146
- if (!name) continue;
147
- const frame = { functionName: name };
148
- if (fileName) frame.fileName = fileName;
149
- if (lineStr) frame.lineNumber = Number(lineStr);
150
- if (colStr) frame.columnNumber = Number(colStr);
151
- frames.push(frame);
152
- }
153
- return frames;
154
- }
155
- /**
156
- * Coerces any thrown value into an `Error` instance, preferring a nested
157
- * `Error` inside a plain-object rejection over a stringified fallback.
158
- *
159
- * Motivated by the common `Promise.reject({ error: realErr })` pattern
160
- * (tRPC, GraphQL clients, some fetch wrappers). Without this, the captured
161
- * exception would be `new Error("[object Object]")` and the nested Error's
162
- * stack/message would be lost entirely.
163
- *
164
- * When multiple candidate Error values exist on the object, the first one
165
- * found (in declaration order) wins. `cause` is preferred if present, since
166
- * it's the documented ES2022 convention.
167
- */
168
- function toError(error) {
169
- if (error instanceof Error) return error;
170
- if (typeof error === "string") return new Error(error);
171
- if (error !== null && typeof error === "object") {
172
- const record = error;
173
- if (record["cause"] instanceof Error) return record["cause"];
174
- for (const value of Object.values(record)) if (value instanceof Error) return value;
175
- }
176
- return new Error(String(error));
177
- }
178
- function toExceptions(error, mechanism) {
179
- const debugIdMap = getDebugIdMap();
180
- const exceptions = [];
181
- let current = error;
182
- for (let depth = 0; current && depth < MAX_CAUSE_DEPTH; depth += 1) {
183
- exceptions.push({
184
- type: current.name,
185
- value: current.message,
186
- mechanism: depth === 0 ? mechanism : void 0,
187
- frames: framesFromError(current, debugIdMap)
188
- });
189
- current = current.cause instanceof Error ? current.cause : void 0;
190
- }
191
- return exceptions;
192
- }
193
- /**
194
- * Extracts and normalizes frames from an Error, applying:
195
- * 1. `preprocessStack` — line truncation and webpack-wrapper stripping.
196
- * 2. `error-stack-parser-es` — engine-specific stack parsing.
197
- * 3. `framesToPop` — honoring the documented Node convention where an
198
- * Error constructor sets this field to instruct callers to drop N top
199
- * frames (used by invariant libraries, assertion wrappers, etc.).
200
- */
201
- function framesFromError(error, debugIdMap) {
202
- const rawStack = error.stack ?? "";
203
- const cleaned = preprocessStack(rawStack);
204
- let frames = parse(cleaned === rawStack ? error : {
205
- name: error.name,
206
- message: error.message,
207
- stack: cleaned
208
- }, { allowEmpty: true }).map((frame) => normalizeFrame(frame, debugIdMap));
209
- const framesToPop = error.framesToPop;
210
- if (typeof framesToPop === "number" && framesToPop > 0) frames = frames.slice(Math.floor(framesToPop));
211
- return frames;
212
- }
213
- let cachedDebugIdMap;
214
- let cachedDebugIdCount = 0;
215
- function getDebugIdMap() {
216
- const registry = globalThis["_debugIds"];
217
- if (!registry) return /* @__PURE__ */ new Map();
218
- const entries = Object.keys(registry);
219
- if (cachedDebugIdMap && entries.length === cachedDebugIdCount) return cachedDebugIdMap;
220
- const map = /* @__PURE__ */ new Map();
221
- for (const stackKey of entries) {
222
- const debugId = registry[stackKey];
223
- if (!debugId) continue;
224
- const filename = extractFilenameFromStack(stackKey);
225
- if (filename) map.set(filename, debugId);
226
- }
227
- cachedDebugIdMap = map;
228
- cachedDebugIdCount = entries.length;
229
- return map;
230
- }
231
- function extractFilenameFromStack(stack) {
232
- const lines = stack.split("\n");
233
- for (let i = lines.length - 1; i >= 0; i--) {
234
- const line = lines[i];
235
- if (!line) continue;
236
- const match = line.match(PAREN_FILE_RE) ?? line.match(AT_FILE_RE) ?? line.match(SPIDERMONKEY_RE) ?? line.match(BARE_FILE_RE);
237
- if (match?.[1]) return match[1].trim();
238
- }
239
- return null;
240
- }
241
- function normalizeFrame(frame, debugIdMap) {
242
- const fileName = typeof frame.fileName === "string" ? frame.fileName : void 0;
243
- return {
244
- fileName,
245
- functionName: typeof frame.functionName === "string" ? frame.functionName : void 0,
246
- lineNumber: typeof frame.lineNumber === "number" ? frame.lineNumber : void 0,
247
- columnNumber: typeof frame.columnNumber === "number" ? frame.columnNumber : void 0,
248
- source: typeof frame.source === "string" ? frame.source : void 0,
249
- debugId: fileName ? debugIdMap.get(fileName) : void 0
250
- };
251
- }
252
- //#endregion
253
- export { MECHANISM_TYPE, extractFilenameFromStack, parseReactComponentStack, preprocessStack, shouldDropBrowserExtensionNoise, shouldDropUnresolvableStack, toError, toExceptions };
1
+ const e={browser:{onerror:`auto.browser.global_handlers.onerror`,onunhandledrejection:`auto.browser.global_handlers.onunhandledrejection`,consoleError:`auto.browser.console.error`},react:{errorBoundary:`auto.function.react.error_boundary`,captureBoundary:`auto.function.react.capture_boundary`,caughtError:`auto.function.react.caught_error`,uncaughtError:`auto.function.react.uncaught_error`,recoverableError:`auto.function.react.recoverable_error`},nextjs:{onRequestError:`auto.function.nextjs.on_request_error`,captureError:`auto.function.nextjs.capture_error`},node:{captureError:`auto.function.node.capture_error`,uncaughtException:`auto.node.global_handlers.uncaught_exception`,unhandledRejection:`auto.node.global_handlers.unhandled_rejection`},manual:{capture:`manual.api.capture`}},t=/\b(?:chrome|moz|safari-web|safari|ms-browser|webkit-masked)-(?:extension|url):\/\//;function n(e){return e.some(e=>t.test(e))}const r=/(?:https?|file|blob|webpack-internal):\/\/|\sat\s+[\w$.<>]+\s+\([^)]+:\d/;function i(e){if(e.length===0)return!1;for(let t of e)if(r.test(t))return!1;return!0}const a=/^(?:in|at)\s+([^\s(]+)(?:\s+\(([^\s:)]+):(\d+)(?::(\d+))?\))?/;function o(e){let t=[];for(let n of e.split(`
2
+ `)){let e=n.trim();if(!e)continue;let r=a.exec(e);if(!r)continue;let[,i,o,s,c]=r;if(!i)continue;let l={id:`react-${t.length}`,fn:i};o&&(l.file=o),s&&(l.line=Number(s)),c&&(l.column=Number(c)),t.push(l)}return t}function s(e){return e instanceof Error?e:typeof e==`string`?Error(e):typeof e==`object`&&e?c(e)||l(u(e)??String(e)):l(String(e))}function c(e){if(e.cause instanceof Error)return e.cause;for(let t of Object.values(e))if(t instanceof Error)return t}function l(e){let t=Error(e);return t.name=`NonError`,t}function u(e){try{return JSON.stringify(e)}catch{return null}}function d(e){if(e===null)return`null`;let t=typeof e;if(t!==`object`)return t;let n=Object.prototype.toString.call(e).slice(8,-1);return n===`Object`?`PlainObject`:n}function f(e){if(e==null)return`Non-Error captured: ${String(e)}`;if(typeof e==`object`){let t=Object.keys(e).sort();return t.length===0?`Non-Error captured: empty object`:`Non-Error captured with keys: ${t.join(`, `)}`}return`Non-Error captured: ${String(e)}`}function p(e,t){let n=new WeakSet,r=(e,i)=>{if(e===null)return null;let a=typeof e;if(a===`string`||a===`number`||a===`boolean`)return e;if(a===`undefined`)return;if(a===`function`||a===`symbol`||a===`bigint`)return String(e);if(i>t)return`[depth-limit]`;if(n.has(e))return`[circular]`;if(n.add(e),Array.isArray(e))return e.map(e=>r(e,i+1));let o={};for(let[t,n]of Object.entries(e))o[t]=r(n,i+1);return o};return r(e,0)}function m(e){if(e instanceof Error)return e;if(typeof e==`string`)return Error(e);if(typeof e==`object`&&e){let t=c(e);if(t)return t}return{kind:`non-error`,type:d(e),value:f(e),serialized:p(e,4)}}function h(e){return typeof e==`object`&&!!e&&e.kind===`non-error`}function g(e,t){if(h(e))return[{kind:`non-error`,type:e.type,value:e.value,mechanism:t,serialized:e.serialized}];let n=[],r=e;for(let e=0;r&&e<5;e+=1)n.push({kind:`error`,type:r.name,value:r.message,mechanism:e===0?t:void 0,stack:r.stack??``}),r=r.cause instanceof Error?r.cause:void 0;return n}export{e as MECHANISM_TYPE,h as isNonErrorException,o as parseReactComponentStack,n as shouldDropBrowserExtensionNoise,i as shouldDropUnresolvableStack,s as toError,m as toException,g as toExceptions};