@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 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.
@@ -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":"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"}
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,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 (error) {
19
- if (error instanceof Error) {
20
- try {
21
- const client = getClient();
22
- const url = new URL(request.url);
23
- client.addBreadcrumb({
24
- category: "api",
25
- message: `${request.method} ${url.pathname}`,
26
- });
27
- await client.captureError(error, {
28
- url: request.url,
29
- method: request.method,
30
- });
31
- }
32
- catch {
33
- // SDK not initialized — silently ignore
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 error;
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;
@@ -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;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"}
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
- try {
26
- const client = getClient();
27
- client.captureError(error, {
28
- componentStack: errorInfo.componentStack ?? undefined,
29
- });
30
- }
31
- catch {
32
- // SDK not initialized — silently ignore
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
@@ -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,cAAc,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
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";
@@ -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
@@ -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,CAAC,OAAO,EAAE,iBAAiB,GAAG,iBAAiB,CAuB1E"}
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"}
@@ -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 (error) {
19
- if (error instanceof Error) {
20
- try {
21
- const client = getClient();
22
- client.addBreadcrumb({
23
- category: "middleware",
24
- message: `${request.method} ${request.nextUrl.pathname}`,
25
- });
26
- await client.captureError(error, {
27
- url: request.nextUrl.toString(),
28
- method: request.method,
29
- });
30
- }
31
- catch {
32
- // SDK not initialized — silently ignore
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 error;
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.1.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.1.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"