@squasher-ai/nextjs 0.1.0 → 0.2.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/dist/api-handler.d.ts +3 -1
- package/dist/api-handler.d.ts.map +1 -1
- package/dist/api-handler.js +20 -19
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +15 -9
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/middleware.d.ts +2 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +19 -18
- package/package.json +4 -3
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/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,6 @@ 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
17
|
//# sourceMappingURL=api-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-handler.d.ts","sourceRoot":"","sources":["../src/api-handler.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/api-handler.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getClient } from "@squasher-ai/node";
|
|
2
|
+
import { attemptAsync } from "@squasher-ai/result-utils";
|
|
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;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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"}
|
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 "@squasher-ai/result-utils";
|
|
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,5 @@
|
|
|
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";
|
|
3
|
+
export { withSquasher } from "./middleware.js";
|
|
4
|
+
export { squasherApiHandler } from "./api-handler.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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"}
|
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,6 @@ 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
17
|
//# sourceMappingURL=middleware.d.ts.map
|
package/dist/middleware.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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"}
|
package/dist/middleware.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getClient } from "@squasher-ai/node";
|
|
2
|
+
import { attemptAsync } from "@squasher-ai/result-utils";
|
|
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,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@squasher-ai/nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Official @squasher-ai/nextjs package for Squasher.",
|
|
5
5
|
"homepage": "https://squasher.ai",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/squasher-ai/squasher.git",
|
|
10
|
-
"directory": "packages/sdk-nextjs"
|
|
10
|
+
"directory": "packages/public/sdk-nextjs"
|
|
11
11
|
},
|
|
12
12
|
"bugs": {
|
|
13
13
|
"url": "https://github.com/squasher-ai/squasher/issues"
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@squasher-ai/node": "0.
|
|
32
|
+
"@squasher-ai/node": "0.3.0",
|
|
33
|
+
"@squasher-ai/result-utils": "0.2.0"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
36
|
"next": ">=14.0.0"
|