@squasher-ai/nextjs 0.1.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.
- package/LICENSE +21 -21
- package/README.md +1 -1
- package/dist/_vendor/result-runtime/attempt.d.ts +17 -0
- package/dist/_vendor/result-runtime/attempt.js +62 -0
- package/dist/_vendor/telemetry-contract/sdk/public-contract.d.ts +175 -0
- package/dist/_vendor/telemetry-contract/sdk/public-contract.js +5 -0
- package/dist/api-handler.d.ts +3 -2
- package/dist/api-handler.js +20 -19
- package/dist/client.d.ts +2 -1
- package/dist/client.js +15 -9
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -2
- package/dist/middleware.d.ts +2 -2
- package/dist/middleware.js +19 -18
- package/package.json +3 -3
- package/dist/api-handler.d.ts.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/middleware.d.ts.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Squasher
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Squasher
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -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
|
+
}
|
package/dist/api-handler.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { getClient } from "@squasher-ai/node";
|
|
1
2
|
type NextApiHandler = (request: Request) => Response | Promise<Response>;
|
|
3
|
+
export type SquasherClientResolver = () => Pick<ReturnType<typeof getClient>, "addBreadcrumb" | "captureError">;
|
|
2
4
|
/**
|
|
3
5
|
* Wrap a Next.js App Router API route handler to capture errors.
|
|
4
6
|
*
|
|
@@ -10,6 +12,5 @@ type NextApiHandler = (request: Request) => Response | Promise<Response>;
|
|
|
10
12
|
* });
|
|
11
13
|
* ```
|
|
12
14
|
*/
|
|
13
|
-
export declare function squasherApiHandler(handler: NextApiHandler): NextApiHandler;
|
|
15
|
+
export declare function squasherApiHandler(handler: NextApiHandler, resolveClient?: SquasherClientResolver): NextApiHandler;
|
|
14
16
|
export {};
|
|
15
|
-
//# sourceMappingURL=api-handler.d.ts.map
|
package/dist/api-handler.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getClient } from "@squasher-ai/node";
|
|
2
|
+
import { attemptAsync } from "./_vendor/result-runtime/attempt.js";
|
|
2
3
|
/**
|
|
3
4
|
* Wrap a Next.js App Router API route handler to capture errors.
|
|
4
5
|
*
|
|
@@ -10,30 +11,30 @@ import { getClient } from "@squasher-ai/node";
|
|
|
10
11
|
* });
|
|
11
12
|
* ```
|
|
12
13
|
*/
|
|
13
|
-
export function squasherApiHandler(handler) {
|
|
14
|
+
export function squasherApiHandler(handler, resolveClient = getClient) {
|
|
14
15
|
return async (request) => {
|
|
15
16
|
try {
|
|
16
17
|
return await handler(request);
|
|
17
18
|
}
|
|
18
|
-
catch (
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
19
|
+
catch (cause) {
|
|
20
|
+
if (cause instanceof Error) {
|
|
21
|
+
await attemptAsync({
|
|
22
|
+
try: async () => {
|
|
23
|
+
const client = resolveClient();
|
|
24
|
+
const url = new URL(request.url);
|
|
25
|
+
client.addBreadcrumb({
|
|
26
|
+
category: "api",
|
|
27
|
+
message: `${request.method} ${url.pathname}`,
|
|
28
|
+
});
|
|
29
|
+
await client.captureError(cause, {
|
|
30
|
+
url: request.url,
|
|
31
|
+
method: request.method,
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
catch: () => undefined,
|
|
35
|
+
});
|
|
35
36
|
}
|
|
36
|
-
throw
|
|
37
|
+
throw cause;
|
|
37
38
|
}
|
|
38
39
|
};
|
|
39
40
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Component, type ErrorInfo, type ReactNode } from "react";
|
|
2
|
+
import { getClient, type JsonObject } from "@squasher-ai/node";
|
|
2
3
|
interface Props {
|
|
3
4
|
children: ReactNode;
|
|
4
5
|
fallback?: ReactNode;
|
|
6
|
+
captureError?: (error: Error, context: JsonObject) => ReturnType<ReturnType<typeof getClient>["captureError"]>;
|
|
5
7
|
}
|
|
6
8
|
interface State {
|
|
7
9
|
hasError: boolean;
|
|
@@ -25,4 +27,3 @@ export declare class SquasherErrorBoundary extends Component<Props, State> {
|
|
|
25
27
|
render(): ReactNode;
|
|
26
28
|
}
|
|
27
29
|
export {};
|
|
28
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Component } from "react";
|
|
3
3
|
import { getClient } from "@squasher-ai/node";
|
|
4
|
+
import { attempt } from "./_vendor/result-runtime/attempt.js";
|
|
4
5
|
/**
|
|
5
6
|
* Error boundary that captures errors to Squasher.
|
|
6
7
|
*
|
|
@@ -22,15 +23,20 @@ export class SquasherErrorBoundary extends Component {
|
|
|
22
23
|
return { hasError: true };
|
|
23
24
|
}
|
|
24
25
|
componentDidCatch(error, errorInfo) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
attempt({
|
|
27
|
+
try: () => {
|
|
28
|
+
const context = {};
|
|
29
|
+
if (errorInfo.componentStack)
|
|
30
|
+
context.componentStack = errorInfo.componentStack;
|
|
31
|
+
if (this.props.captureError) {
|
|
32
|
+
this.props.captureError(error, context);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
getClient().captureError(error, context);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
catch: () => undefined,
|
|
39
|
+
});
|
|
34
40
|
}
|
|
35
41
|
render() {
|
|
36
42
|
if (this.state.hasError) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { SquasherClient, captureGeneration, init, getClient, identify, page, captureError, captureMessage, captureSpan, captureTelemetry, captureToolCall, screen, track, } from "@squasher-ai/node";
|
|
2
2
|
export type { AnalyticsContext, JsonObject, SquasherConfig, ErrorEvent, UserContext, Breadcrumb, LlmContext, PageContext, SessionContext, TelemetryKind, TelemetryMeasurement, ToolCallContext, TraceContext, VisitorContext, } from "@squasher-ai/node";
|
|
3
|
-
export { withSquasher } from "./middleware";
|
|
4
|
-
export { squasherApiHandler } from "./api-handler";
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
3
|
+
export { withSquasher } from "./middleware.js";
|
|
4
|
+
export { squasherApiHandler } from "./api-handler.js";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { SquasherClient, captureGeneration, init, getClient, identify, page, captureError, captureMessage, captureSpan, captureTelemetry, captureToolCall, screen, track, } from "@squasher-ai/node";
|
|
2
|
-
export { withSquasher } from "./middleware";
|
|
3
|
-
export { squasherApiHandler } from "./api-handler";
|
|
2
|
+
export { withSquasher } from "./middleware.js";
|
|
3
|
+
export { squasherApiHandler } from "./api-handler.js";
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
import type { SquasherClientResolver } from "./api-handler";
|
|
2
3
|
type MiddlewareHandler = (request: NextRequest) => NextResponse | Response | Promise<NextResponse | Response>;
|
|
3
4
|
/**
|
|
4
5
|
* Wrap a Next.js middleware to capture errors automatically.
|
|
@@ -11,6 +12,5 @@ type MiddlewareHandler = (request: NextRequest) => NextResponse | Response | Pro
|
|
|
11
12
|
* });
|
|
12
13
|
* ```
|
|
13
14
|
*/
|
|
14
|
-
export declare function withSquasher(handler: MiddlewareHandler): MiddlewareHandler;
|
|
15
|
+
export declare function withSquasher(handler: MiddlewareHandler, resolveClient?: SquasherClientResolver): MiddlewareHandler;
|
|
15
16
|
export {};
|
|
16
|
-
//# sourceMappingURL=middleware.d.ts.map
|
package/dist/middleware.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getClient } from "@squasher-ai/node";
|
|
2
|
+
import { attemptAsync } from "./_vendor/result-runtime/attempt.js";
|
|
2
3
|
/**
|
|
3
4
|
* Wrap a Next.js middleware to capture errors automatically.
|
|
4
5
|
*
|
|
@@ -10,29 +11,29 @@ import { getClient } from "@squasher-ai/node";
|
|
|
10
11
|
* });
|
|
11
12
|
* ```
|
|
12
13
|
*/
|
|
13
|
-
export function withSquasher(handler) {
|
|
14
|
+
export function withSquasher(handler, resolveClient = getClient) {
|
|
14
15
|
return async (request) => {
|
|
15
16
|
try {
|
|
16
17
|
return await handler(request);
|
|
17
18
|
}
|
|
18
|
-
catch (
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
19
|
+
catch (cause) {
|
|
20
|
+
if (cause instanceof Error) {
|
|
21
|
+
await attemptAsync({
|
|
22
|
+
try: async () => {
|
|
23
|
+
const client = resolveClient();
|
|
24
|
+
client.addBreadcrumb({
|
|
25
|
+
category: "middleware",
|
|
26
|
+
message: `${request.method} ${request.nextUrl.pathname}`,
|
|
27
|
+
});
|
|
28
|
+
await client.captureError(cause, {
|
|
29
|
+
url: request.nextUrl.toString(),
|
|
30
|
+
method: request.method,
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
catch: () => undefined,
|
|
34
|
+
});
|
|
34
35
|
}
|
|
35
|
-
throw
|
|
36
|
+
throw cause;
|
|
36
37
|
}
|
|
37
38
|
};
|
|
38
39
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squasher-ai/nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Official @squasher-ai/nextjs package for Squasher.",
|
|
5
|
-
"homepage": "https://
|
|
5
|
+
"homepage": "https://squasher.ai",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@squasher-ai/node": "0.
|
|
24
|
+
"@squasher-ai/node": "0.4.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"next": ">=14.0.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api-handler.d.ts","sourceRoot":"","sources":["../src/api-handler.ts"],"names":[],"mappings":"AAEA,KAAK,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,CAwB1E"}
|
package/dist/client.d.ts.map
DELETED
|
@@ -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;AAGlE,UAAU,KAAK;IACb,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;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;IAW3D,MAAM,IAAI,SAAS;CAM7B"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -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,cAAc,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/middleware.d.ts.map
DELETED
|
@@ -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,KAAK,iBAAiB,GAAG,CACvB,OAAO,EAAE,WAAW,KACjB,YAAY,GAAG,QAAQ,GAAG,OAAO,CAAC,YAAY,GAAG,QAAQ,CAAC,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,iBAAiB,CAuB1E"}
|