@squasher-ai/nextjs 0.2.0 → 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.
@@ -0,0 +1,17 @@
1
+ export interface AttemptFailure<TCause = Error> {
2
+ cause: TCause;
3
+ error: Error;
4
+ }
5
+ export interface AttemptOptions<TTry, TCatch = TTry, TCause = Error> {
6
+ try: () => TTry;
7
+ catch: (failure: AttemptFailure<TCause>) => TCatch;
8
+ finally?: () => void;
9
+ }
10
+ export interface AttemptAsyncOptions<TTry, TCatch = TTry, TCause = Error> {
11
+ try: () => Promise<TTry>;
12
+ catch: (failure: AttemptFailure<TCause>) => Promise<TCatch> | TCatch;
13
+ finally?: () => Promise<void> | void;
14
+ }
15
+ export declare function toError<T>(cause: T, fallbackMessage?: string): Error;
16
+ export declare function attempt<TTry, TCatch = TTry, TCause = Error>(options: AttemptOptions<TTry, TCatch, TCause>): TTry | TCatch;
17
+ export declare function attemptAsync<TTry, TCatch = TTry, TCause = Error>(options: AttemptAsyncOptions<TTry, TCatch, TCause>): Promise<TTry | TCatch>;
@@ -0,0 +1,62 @@
1
+ export function toError(cause, fallbackMessage = "Unexpected error") {
2
+ if (cause instanceof Error)
3
+ return cause;
4
+ const nestedError = readProperty(cause, "error");
5
+ if (nestedError instanceof Error)
6
+ return nestedError;
7
+ const messageValue = readProperty(cause, "message");
8
+ if (Object.prototype.toString.call(messageValue) === "[object String]") {
9
+ const message = String(messageValue);
10
+ if (message.length > 0)
11
+ return new Error(message);
12
+ }
13
+ if (Object.prototype.toString.call(cause) === "[object String]") {
14
+ const message = String(cause);
15
+ if (message.length > 0)
16
+ return new Error(message);
17
+ }
18
+ return new Error(fallbackMessage, { cause });
19
+ }
20
+ function readProperty(owner, key) {
21
+ try {
22
+ const target = Object(owner);
23
+ let cursor = target;
24
+ while (cursor) {
25
+ const descriptor = Object.getOwnPropertyDescriptor(cursor, key);
26
+ if (descriptor) {
27
+ return "value" in descriptor ? descriptor.value : descriptor.get?.call(target);
28
+ }
29
+ cursor = Object.getPrototypeOf(cursor);
30
+ }
31
+ return undefined;
32
+ }
33
+ catch {
34
+ return undefined;
35
+ }
36
+ }
37
+ export function attempt(options) {
38
+ try {
39
+ return options.try();
40
+ }
41
+ catch (cause) {
42
+ // SAFETY: `TCause` is the caller-selected type for the catch channel.
43
+ const preservedCause = cause;
44
+ return options.catch({ cause: preservedCause, error: toError(preservedCause) });
45
+ }
46
+ finally {
47
+ options.finally?.();
48
+ }
49
+ }
50
+ export async function attemptAsync(options) {
51
+ try {
52
+ return await options.try();
53
+ }
54
+ catch (cause) {
55
+ // SAFETY: `TCause` is the caller-selected type for the catch channel.
56
+ const preservedCause = cause;
57
+ return await options.catch({ cause: preservedCause, error: toError(preservedCause) });
58
+ }
59
+ finally {
60
+ await options.finally?.();
61
+ }
62
+ }
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Customer-facing telemetry contract shared by the published JavaScript SDKs.
3
+ * This module intentionally contains only the documented ingestion shapes.
4
+ */
5
+ export type JsonPrimitive = boolean | null | number | string;
6
+ export interface JsonObject {
7
+ [key: string]: JsonValue;
8
+ }
9
+ export type JsonValue = JsonPrimitive | JsonValue[] | JsonObject;
10
+ export type Level = "fatal" | "error" | "warning" | "info" | "debug";
11
+ export interface StackFrame {
12
+ filename?: string;
13
+ function?: string;
14
+ lineno?: number;
15
+ colno?: number;
16
+ in_app?: boolean;
17
+ context_line?: string;
18
+ pre_context?: string[];
19
+ post_context?: string[];
20
+ }
21
+ export interface UserContext {
22
+ id?: string;
23
+ email?: string;
24
+ username?: string;
25
+ ip_address?: string;
26
+ }
27
+ export interface RequestContext {
28
+ url?: string;
29
+ method?: string;
30
+ headers?: Record<string, string>;
31
+ }
32
+ export interface Breadcrumb {
33
+ timestamp?: string;
34
+ category?: string;
35
+ message?: string;
36
+ level?: string;
37
+ data?: JsonObject;
38
+ }
39
+ /** Event payload accepted by the documented ingestion endpoint. */
40
+ export interface IngestEvent {
41
+ message: string;
42
+ type?: string;
43
+ stack?: string;
44
+ frames?: StackFrame[];
45
+ level?: Level;
46
+ tags?: Record<string, string>;
47
+ user?: UserContext;
48
+ request?: RequestContext;
49
+ sdk?: {
50
+ name: string;
51
+ version: string;
52
+ };
53
+ timestamp?: string;
54
+ release?: string;
55
+ environment?: string;
56
+ breadcrumbs?: Breadcrumb[];
57
+ extra?: Record<string, JsonValue>;
58
+ session_id?: string;
59
+ kind?: TelemetryKind;
60
+ event_name?: string;
61
+ distinct_id?: string;
62
+ visitor?: VisitorContext;
63
+ analytics?: AnalyticsContext;
64
+ page?: PageContext;
65
+ session?: SessionContext;
66
+ trace?: TraceContext;
67
+ tool_call?: ToolCallContext;
68
+ llm?: LlmContext;
69
+ attributes?: JsonObject;
70
+ measurements?: TelemetryMeasurement[];
71
+ resource_attributes?: Record<string, string>;
72
+ }
73
+ export interface IngestBatchPayload {
74
+ events: IngestEvent[];
75
+ }
76
+ export type IngestEventBatch = [IngestEvent, ...IngestEvent[]];
77
+ export interface IngestBatchEnvelope {
78
+ events: IngestEventBatch;
79
+ }
80
+ export type IngestJsonBatchPayload = IngestEventBatch | IngestBatchEnvelope;
81
+ export type IngestJsonPayload = IngestEvent | IngestJsonBatchPayload;
82
+ /** An encoded newline-delimited JSON request body. */
83
+ export type IngestNdjsonPayload = string;
84
+ export type IngestRequestPayload = IngestJsonPayload | IngestNdjsonPayload;
85
+ export type TelemetryKind = "error" | "log" | "analytics" | "identify" | "page" | "screen" | "visitor" | "agent_session" | "agent_span" | "tool_call" | "llm_generation" | "agent_score";
86
+ export interface VisitorContext {
87
+ visitor_id?: string;
88
+ anonymous_id?: string;
89
+ account_id?: string;
90
+ }
91
+ export interface AnalyticsContext {
92
+ event?: string;
93
+ category?: string;
94
+ funnel?: string;
95
+ step?: string;
96
+ properties?: JsonObject;
97
+ }
98
+ export interface PageContext {
99
+ name?: string;
100
+ path?: string;
101
+ title?: string;
102
+ referrer?: string;
103
+ search?: string;
104
+ screen_class?: string;
105
+ }
106
+ export interface SessionContext {
107
+ session_type?: string;
108
+ agent_id?: string;
109
+ run_id?: string;
110
+ workflow_id?: string;
111
+ step_id?: string;
112
+ status?: string;
113
+ duration_ms?: number;
114
+ }
115
+ export interface TraceContext {
116
+ trace_id?: string;
117
+ span_id?: string;
118
+ parent_span_id?: string;
119
+ span_name?: string;
120
+ span_kind?: string;
121
+ status?: string;
122
+ duration_ms?: number;
123
+ }
124
+ export interface ToolCallContext {
125
+ name?: string;
126
+ input?: JsonObject;
127
+ output?: JsonObject;
128
+ status?: string;
129
+ duration_ms?: number;
130
+ }
131
+ export interface LlmContext {
132
+ provider?: string;
133
+ model?: string;
134
+ prompt_tokens?: number;
135
+ completion_tokens?: number;
136
+ total_tokens?: number;
137
+ cached_input_tokens?: number;
138
+ cost_usd?: number;
139
+ latency_ms?: number;
140
+ status?: string;
141
+ input?: JsonObject;
142
+ output?: JsonObject;
143
+ }
144
+ export interface TelemetryMeasurement {
145
+ name: string;
146
+ value: number;
147
+ unit?: string;
148
+ }
149
+ /** Outcome-aware SDK sampling. Errors and slow operations are kept by default. */
150
+ export interface TelemetrySamplingConfig {
151
+ successRate?: number;
152
+ errorRate?: number;
153
+ slowRate?: number;
154
+ slowThresholdMs?: number;
155
+ alwaysSampleUserIds?: string[];
156
+ alwaysSampleReleases?: string[];
157
+ }
158
+ export interface IngestResponse {
159
+ id: string;
160
+ status: string;
161
+ accepted?: number;
162
+ }
163
+ export interface SdkConfig {
164
+ apiKey: string;
165
+ projectId: string;
166
+ endpoint?: string;
167
+ environment?: string;
168
+ release?: string;
169
+ debug?: boolean;
170
+ sampling?: TelemetrySamplingConfig;
171
+ beforeSend?: (event: IngestEvent) => IngestEvent | null;
172
+ maxBreadcrumbs?: number;
173
+ resourceAttributes?: Record<string, string>;
174
+ autoFlushIntervalMs?: number;
175
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Customer-facing telemetry contract shared by the published JavaScript SDKs.
3
+ * This module intentionally contains only the documented ingestion shapes.
4
+ */
5
+ export {};
@@ -14,4 +14,3 @@ export type SquasherClientResolver = () => Pick<ReturnType<typeof getClient>, "a
14
14
  */
15
15
  export declare function squasherApiHandler(handler: NextApiHandler, resolveClient?: SquasherClientResolver): NextApiHandler;
16
16
  export {};
17
- //# sourceMappingURL=api-handler.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { getClient } from "@squasher-ai/node";
2
- import { attemptAsync } from "@squasher-ai/result-utils";
2
+ import { attemptAsync } from "./_vendor/result-runtime/attempt.js";
3
3
  /**
4
4
  * Wrap a Next.js App Router API route handler to capture errors.
5
5
  *
package/dist/client.d.ts CHANGED
@@ -27,4 +27,3 @@ export declare class SquasherErrorBoundary extends Component<Props, State> {
27
27
  render(): ReactNode;
28
28
  }
29
29
  export {};
30
- //# sourceMappingURL=client.d.ts.map
package/dist/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { Component } from "react";
3
3
  import { getClient } from "@squasher-ai/node";
4
- import { attempt } from "@squasher-ai/result-utils";
4
+ import { attempt } from "./_vendor/result-runtime/attempt.js";
5
5
  /**
6
6
  * Error boundary that captures errors to Squasher.
7
7
  *
package/dist/index.d.ts CHANGED
@@ -2,4 +2,3 @@ export { SquasherClient, captureGeneration, init, getClient, identify, page, cap
2
2
  export type { AnalyticsContext, JsonObject, SquasherConfig, ErrorEvent, UserContext, Breadcrumb, LlmContext, PageContext, SessionContext, TelemetryKind, TelemetryMeasurement, ToolCallContext, TraceContext, VisitorContext, } from "@squasher-ai/node";
3
3
  export { withSquasher } from "./middleware.js";
4
4
  export { squasherApiHandler } from "./api-handler.js";
5
- //# sourceMappingURL=index.d.ts.map
@@ -14,4 +14,3 @@ type MiddlewareHandler = (request: NextRequest) => NextResponse | Response | Pro
14
14
  */
15
15
  export declare function withSquasher(handler: MiddlewareHandler, resolveClient?: SquasherClientResolver): MiddlewareHandler;
16
16
  export {};
17
- //# sourceMappingURL=middleware.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { getClient } from "@squasher-ai/node";
2
- import { attemptAsync } from "@squasher-ai/result-utils";
2
+ import { attemptAsync } from "./_vendor/result-runtime/attempt.js";
3
3
  /**
4
4
  * Wrap a Next.js middleware to capture errors automatically.
5
5
  *
package/package.json CHANGED
@@ -1,17 +1,9 @@
1
1
  {
2
2
  "name": "@squasher-ai/nextjs",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Official @squasher-ai/nextjs package for Squasher.",
5
5
  "homepage": "https://squasher.ai",
6
6
  "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/squasher-ai/squasher.git",
10
- "directory": "packages/public/sdk-nextjs"
11
- },
12
- "bugs": {
13
- "url": "https://github.com/squasher-ai/squasher/issues"
14
- },
15
7
  "publishConfig": {
16
8
  "access": "public"
17
9
  },
@@ -29,8 +21,7 @@
29
21
  }
30
22
  },
31
23
  "dependencies": {
32
- "@squasher-ai/node": "0.3.0",
33
- "@squasher-ai/result-utils": "0.2.0"
24
+ "@squasher-ai/node": "0.4.0"
34
25
  },
35
26
  "peerDependencies": {
36
27
  "next": ">=14.0.0"
@@ -1 +0,0 @@
1
- {"version":3,"file":"api-handler.d.ts","sourceRoot":"","sources":["../src/api-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,KAAK,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACzE,MAAM,MAAM,sBAAsB,GAAG,MAAM,IAAI,CAC7C,UAAU,CAAC,OAAO,SAAS,CAAC,EAC5B,eAAe,GAAG,cAAc,CACjC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,cAAc,EACvB,aAAa,GAAE,sBAAkC,GAChD,cAAc,CAyBhB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5D,UAAU,KAAK;IACb,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,YAAY,CAAC,EAAE,CACb,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,UAAU,KAChB,UAAU,CAAC,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;CAC/D;AAED,UAAU,KAAK;IACb,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,qBAAsB,SAAQ,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;gBACpD,KAAK,EAAE,KAAK;IAKxB,MAAM,CAAC,wBAAwB,IAAI,KAAK;IAI/B,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI;IAe3D,MAAM,IAAI,SAAS;CAM7B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,YAAY,EACZ,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,KAAK,GACN,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,WAAW,EACX,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,cAAc,GACf,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAE5D,KAAK,iBAAiB,GAAG,CACvB,OAAO,EAAE,WAAW,KACjB,YAAY,GAAG,QAAQ,GAAG,OAAO,CAAC,YAAY,GAAG,QAAQ,CAAC,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,iBAAiB,EAC1B,aAAa,GAAE,sBAAkC,GAChD,iBAAiB,CAwBnB"}