@honeybadger-io/nextjs 5.11.6 → 6.0.1
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/README.md +5 -42
- package/dist/capture-request-error.d.ts +35 -0
- package/dist/capture-request-error.test.d.ts +2 -0
- package/dist/capture-router-transition-start.d.ts +21 -0
- package/dist/capture-router-transition-start.test.d.ts +2 -0
- package/dist/client.d.ts +2 -0
- package/dist/copy-config-files.js +106 -34
- package/dist/copy-config-files.js.map +1 -1
- package/dist/edge.d.ts +2 -1
- package/dist/flush.d.ts +24 -0
- package/dist/honeybadger-nextjs-client.cjs.js +39 -0
- package/dist/honeybadger-nextjs-client.cjs.js.map +1 -0
- package/dist/honeybadger-nextjs-client.esm.js +31 -0
- package/dist/honeybadger-nextjs-client.esm.js.map +1 -0
- package/dist/honeybadger-nextjs-edge.cjs.js +333 -239
- package/dist/honeybadger-nextjs-edge.cjs.js.map +1 -1
- package/dist/honeybadger-nextjs-edge.esm.js +330 -239
- package/dist/honeybadger-nextjs-edge.esm.js.map +1 -1
- package/dist/honeybadger-nextjs.cjs.js +852 -386
- package/dist/honeybadger-nextjs.cjs.js.map +1 -1
- package/dist/honeybadger-nextjs.esm.js +846 -385
- package/dist/honeybadger-nextjs.esm.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/insights-instrumentation.d.ts +30 -2
- package/dist/insights.d.ts +72 -0
- package/dist/insights.test.d.ts +2 -0
- package/dist/query-filters.test.d.ts +2 -0
- package/dist/setup.d.ts +11 -0
- package/dist/setup.test.d.ts +2 -0
- package/dist/source-maps.d.ts +55 -0
- package/dist/source-maps.test.d.ts +2 -0
- package/dist/types.d.ts +20 -8
- package/package.json +34 -12
- package/src/capture-request-error.test.ts +261 -0
- package/src/capture-request-error.ts +107 -0
- package/src/capture-router-transition-start.test.ts +44 -0
- package/src/capture-router-transition-start.ts +37 -0
- package/src/client.ts +4 -0
- package/src/copy-config-files.test.ts +250 -16
- package/src/copy-config-files.ts +117 -34
- package/src/edge.ts +12 -1
- package/src/flush.ts +58 -0
- package/src/index.ts +7 -2
- package/src/insights-instrumentation.ts +104 -11
- package/src/insights.test.ts +192 -0
- package/src/insights.ts +225 -0
- package/src/query-filters.test.ts +67 -0
- package/src/setup.test.ts +214 -0
- package/src/setup.ts +172 -0
- package/src/source-maps.test.ts +803 -0
- package/src/source-maps.ts +515 -0
- package/src/types.ts +38 -21
- package/templates/_error.js +14 -10
- package/templates/_error_app_router.js +1 -1
- package/templates/_error_app_router.tsx +1 -1
- package/templates/honeybadger.server.config.js +5 -16
- package/templates/instrumentation-client.js +21 -0
- package/templates/instrumentation.js +29 -0
- package/dist/webpack.d.ts +0 -3
- package/dist/with-honeybadger.d.ts +0 -32
- package/dist/with-honeybadger.test.d.ts +0 -2
- package/src/webpack.ts +0 -228
- package/src/with-honeybadger.test.ts +0 -527
- package/src/with-honeybadger.ts +0 -286
- package/templates/honeybadger.browser.config.js +0 -13
- package/templates/honeybadger.edge.config.js +0 -13
package/README.md
CHANGED
|
@@ -11,50 +11,13 @@ For comprehensive documentation and support, [check out our documentation site](
|
|
|
11
11
|
|
|
12
12
|
The documentation includes a detailed [Next.js integration guide](https://docs.honeybadger.io/lib/javascript/integration/nextjs).
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## Example apps
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
This repository contains two example apps using this package. Follow the README in each one
|
|
17
|
+
to run it.
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
This version is considered suitable for preview.
|
|
22
|
-
|
|
23
|
-
## Features
|
|
24
|
-
|
|
25
|
-
- Automatic reporting of uncaught exceptions (see [Limitations](#limitations))
|
|
26
|
-
- Breadcrumbs
|
|
27
|
-
- Source map upload to Honeybadger
|
|
28
|
-
- CLI command to generate Honeybadger configuration files for Next.js runtimes
|
|
29
|
-
|
|
30
|
-
## Limitations
|
|
31
|
-
|
|
32
|
-
The following limitations are known to exist and will be tackled in future releases:
|
|
33
|
-
|
|
34
|
-
- [Issue link](https://github.com/honeybadger-io/honeybadger-js/issues/1055): A custom error component is used to report uncaught exceptions to Honeybadger.
|
|
35
|
-
This is necessary because Next.js does not provide a way to hook into the error handler.
|
|
36
|
-
This is not a catch-all errors solution.
|
|
37
|
-
If you are using the _Pages Router_, there are some caveats to this approach, as reported [here](https://nextjs.org/docs/advanced-features/custom-error-page#caveats).
|
|
38
|
-
This is a limitation of Next.js, not Honeybadger's Next.js integration.
|
|
39
|
-
Errors thrown in middlewares or API routes will not be reported to Honeybadger, since when they reach the error component, the response status code is 404 and no error information is available.
|
|
40
|
-
Additionally, there is an open [issue](https://github.com/vercel/next.js/issues/45535) about 404 being reported with Next.js apps deployed on Vercel, when they should be reported as 500.
|
|
41
|
-
If you are using the _App Router_, these limitations do not apply, because errors thrown in middlewares or API routes do not reach the custom error component
|
|
42
|
-
but are caught by the global `window.onerror` handler. However, some other server errors (i.e. from data fetching methods) will be reported with minimal information,
|
|
43
|
-
since Next.js will send a [generic error message](https://nextjs.org/docs/app/building-your-application/routing/error-handling#handling-server-errors) to this component for better security.
|
|
44
|
-
- [Issue link](https://github.com/honeybadger-io/honeybadger-js/issues/1056): Source maps for the [Edge runtime](https://vercel.com/docs/concepts/functions/edge-functions/edge-runtime) are not supported yet.
|
|
45
|
-
|
|
46
|
-
## API routes and edge runtime
|
|
47
|
-
|
|
48
|
-
API routes (`pages/api/*`, `app/api/*`) and edge middleware are not reached by the
|
|
49
|
-
webpack config-file auto-injection. Pass an explicit config as the second argument
|
|
50
|
-
to `withHoneybadger` there — see the
|
|
51
|
-
[Next.js integration guide](https://docs.honeybadger.io/lib/javascript/integration/nextjs)
|
|
52
|
-
for details.
|
|
53
|
-
|
|
54
|
-
## Example app
|
|
55
|
-
|
|
56
|
-
A separate repository, [nextjs-with-honeybadger](https://github.com/honeybadger-io/nextjs-with-honeybadger) exists with an example app using this package.
|
|
57
|
-
Follow the README instructions to run the example app.
|
|
19
|
+
- [`examples/app-router`](./examples/app-router) — App Router, on Next.js 16 with Turbopack.
|
|
20
|
+
- [`examples/pages-router`](./examples/pages-router) — Pages Router.
|
|
58
21
|
|
|
59
22
|
## Development
|
|
60
23
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { NodeHeaders } from './insights-instrumentation';
|
|
2
|
+
/**
|
|
3
|
+
* The shape Next.js passes to `onRequestError`. Declared locally rather than imported
|
|
4
|
+
* from `next` so this module carries no type-only dependency on the router types, which
|
|
5
|
+
* differ across the supported Next.js range. `headers` is a Node-style bag, which is
|
|
6
|
+
* exactly `NodeHeaders`, so the existing header reader and the `request_id` /
|
|
7
|
+
* `correlation_id` precedence are reused as-is.
|
|
8
|
+
*/
|
|
9
|
+
export type RequestErrorRequest = {
|
|
10
|
+
path: string;
|
|
11
|
+
method: string;
|
|
12
|
+
headers: NodeHeaders;
|
|
13
|
+
};
|
|
14
|
+
export type RequestErrorContext = {
|
|
15
|
+
routerKind: string;
|
|
16
|
+
routePath: string;
|
|
17
|
+
routeType: string;
|
|
18
|
+
renderSource?: string;
|
|
19
|
+
revalidateReason?: string;
|
|
20
|
+
renderType?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Reports errors passed to Next.js's `onRequestError` instrumentation hook.
|
|
24
|
+
*
|
|
25
|
+
* Wire it up in `instrumentation.ts`:
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* export const onRequestError = captureRequestError
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* Reaches Server Components, Route Handlers, Server Actions and middleware, and receives
|
|
32
|
+
* the real error rather than the generic message Next.js hands to an error component.
|
|
33
|
+
*/
|
|
34
|
+
export declare function captureRequestError(error: unknown, request: RequestErrorRequest, context: RequestErrorContext): Promise<void>;
|
|
35
|
+
//# sourceMappingURL=capture-request-error.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigation types Next.js reports for an App Router transition.
|
|
3
|
+
*/
|
|
4
|
+
export type RouterTransitionType = 'push' | 'replace' | 'traverse';
|
|
5
|
+
/**
|
|
6
|
+
* Records App Router navigations as breadcrumbs, so a fault carries the trail of routes
|
|
7
|
+
* the user visited before it.
|
|
8
|
+
*
|
|
9
|
+
* Wire it up in `instrumentation-client.ts`:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* export const onRouterTransitionStart = captureRouterTransitionStart
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Exported as a ready-made handler rather than left as a function for the template to
|
|
16
|
+
* declare, so the generated file works unchanged as both `.js` and `.ts` — an assignment
|
|
17
|
+
* has no parameters to annotate, so there is no implicit `any` for `noImplicitAny` to
|
|
18
|
+
* reject.
|
|
19
|
+
*/
|
|
20
|
+
export declare function captureRouterTransitionStart(url: string, navigationType: RouterTransitionType): void;
|
|
21
|
+
//# sourceMappingURL=capture-router-transition-start.d.ts.map
|
package/dist/client.d.ts
ADDED
|
@@ -8,24 +8,51 @@ const debug = process.env.HONEYBADGER_DEBUG === 'true';
|
|
|
8
8
|
function usesTypescript() {
|
|
9
9
|
return fs.existsSync('tsconfig.json');
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Where a router directory actually lives: `''` for the project root, `'src'`, or `null`
|
|
13
|
+
* when the project does not use that router.
|
|
14
|
+
*
|
|
15
|
+
* A root `app/` (or `pages/`) can sit beside a `src/` folder used for something else, so
|
|
16
|
+
* this locates each directory rather than assuming a layout. Root wins when a directory
|
|
17
|
+
* somehow exists in both places, matching Next.js.
|
|
18
|
+
*/
|
|
19
|
+
function locateRouterDir(router) {
|
|
20
|
+
if (fs.existsSync(router)) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
if (fs.existsSync(path.join('src', router))) {
|
|
24
|
+
return 'src';
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
17
27
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Where Next.js resolves the `instrumentation` files. It derives that directory as the
|
|
30
|
+
* parent of `pagesDir || appDir`:
|
|
31
|
+
*
|
|
32
|
+
* const rootDir = path.join((pagesDir || appDir)!, '..')
|
|
33
|
+
* — packages/next/src/build/index.ts
|
|
34
|
+
*
|
|
35
|
+
* So it is the parent of whichever router directory is found, and the Pages Router wins
|
|
36
|
+
* when a project has both. A project with a root `app/` and a `src/pages/` therefore
|
|
37
|
+
* resolves instrumentation under `src/`, not at the root.
|
|
38
|
+
*
|
|
39
|
+
* Getting this wrong is silent — the file is written somewhere Next.js never reads, so
|
|
40
|
+
* nothing is instrumented and nothing complains.
|
|
41
|
+
*/
|
|
42
|
+
function instrumentationDir() {
|
|
43
|
+
var _a;
|
|
44
|
+
const pagesDir = locateRouterDir('pages');
|
|
45
|
+
if (pagesDir !== null) {
|
|
46
|
+
return pagesDir;
|
|
47
|
+
}
|
|
48
|
+
return (_a = locateRouterDir('app')) !== null && _a !== void 0 ? _a : '';
|
|
21
49
|
}
|
|
22
|
-
function getTargetPath(
|
|
50
|
+
function getTargetPath(routerDir, isAppRouter = false, isGlobalErrorComponent = false) {
|
|
23
51
|
if (!isAppRouter && isGlobalErrorComponent) {
|
|
24
52
|
throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true');
|
|
25
53
|
}
|
|
26
54
|
const extension = usesTypescript() ? 'tsx' : 'js';
|
|
27
|
-
|
|
28
|
-
srcFolder = path.join(srcFolder, isAppRouter ? 'app' : 'pages');
|
|
55
|
+
const srcFolder = path.join(routerDir, isAppRouter ? 'app' : 'pages');
|
|
29
56
|
let fileName = '';
|
|
30
57
|
if (isAppRouter) {
|
|
31
58
|
fileName = isGlobalErrorComponent ? 'global-error' : 'error';
|
|
@@ -39,30 +66,71 @@ function getTemplate(isAppRouter = false, isGlobalErrorComponent = false) {
|
|
|
39
66
|
if (!isAppRouter && isGlobalErrorComponent) {
|
|
40
67
|
throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true');
|
|
41
68
|
}
|
|
42
|
-
const extension = isGlobalErrorComponent ? 'tsx' : 'js';
|
|
43
69
|
const templateName = isAppRouter ? '_error_app_router' : '_error';
|
|
70
|
+
// `_error_app_router` ships as a JS/TS pair that differs only by the prop type
|
|
71
|
+
// annotation, so pick the one matching the target file's extension. `_error` is JS-only,
|
|
72
|
+
// so it has no pair.
|
|
73
|
+
const hasTypedVariant = isAppRouter;
|
|
74
|
+
const extension = hasTypedVariant && usesTypescript() ? 'tsx' : 'js';
|
|
44
75
|
return path.resolve(__dirname, '../templates', templateName + '.' + extension);
|
|
45
76
|
}
|
|
46
|
-
async function copyErrorJs(
|
|
77
|
+
async function copyErrorJs(routerDir, isAppRouter = false) {
|
|
47
78
|
const sourcePath = getTemplate(isAppRouter);
|
|
48
|
-
const targetPath = getTargetPath(
|
|
79
|
+
const targetPath = getTargetPath(routerDir, isAppRouter);
|
|
49
80
|
return copyFileWithBackup(sourcePath, targetPath);
|
|
50
81
|
}
|
|
51
|
-
function copyGlobalErrorJs(
|
|
82
|
+
function copyGlobalErrorJs(routerDir) {
|
|
52
83
|
const sourcePath = getTemplate(true, true);
|
|
53
|
-
const targetPath = getTargetPath(
|
|
84
|
+
const targetPath = getTargetPath(routerDir, true, true);
|
|
54
85
|
return copyFileWithBackup(sourcePath, targetPath);
|
|
55
86
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
87
|
+
/**
|
|
88
|
+
* `instrumentation` and `instrumentation-client` are Next.js file conventions, so unlike
|
|
89
|
+
* the `honeybadger.*.config` files their location is dictated by Next.js — see
|
|
90
|
+
* `instrumentationDir` for the rule.
|
|
91
|
+
*
|
|
92
|
+
* The config files always stay at the project root, so when the instrumentation file
|
|
93
|
+
* lands in `src/` instead its relative import has to climb one level.
|
|
94
|
+
*/
|
|
95
|
+
async function copyInstrumentationFile(name, srcFolder) {
|
|
96
|
+
const sourcePath = path.resolve(__dirname, '../templates', name + '.js');
|
|
97
|
+
const extension = usesTypescript() ? 'ts' : 'js';
|
|
98
|
+
const targetPath = path.join(srcFolder, name + '.' + extension);
|
|
99
|
+
// Unlike the honeybadger.* files, `instrumentation` is a shared Next.js convention:
|
|
100
|
+
// other tools register their own hooks in it. Overwriting it would silently stop them
|
|
101
|
+
// running, and a .bak file is no help if nobody notices, so leave an existing file
|
|
102
|
+
// alone and print what to add instead.
|
|
103
|
+
const existingPath = ['ts', 'js', 'mjs']
|
|
104
|
+
.map((ext) => path.join(srcFolder, name + '.' + ext))
|
|
105
|
+
.find((candidate) => fs.existsSync(candidate));
|
|
106
|
+
if (existingPath) {
|
|
107
|
+
console.log(`\nSkipped ${existingPath} because it already exists — it may register hooks for ` +
|
|
108
|
+
'other tools.\nAdd Honeybadger to it by hand; see ' +
|
|
109
|
+
`${path.relative(process.cwd(), sourcePath)} for the contents to merge in.`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
let contents = await fs.promises.readFile(sourcePath, 'utf8');
|
|
113
|
+
if (srcFolder) {
|
|
114
|
+
contents = contents.replace(/(['"])\.\/honeybadger\./g, '$1../honeybadger.');
|
|
65
115
|
}
|
|
116
|
+
if (debug) {
|
|
117
|
+
console.debug('writing', targetPath);
|
|
118
|
+
}
|
|
119
|
+
return fs.promises.writeFile(targetPath, contents);
|
|
120
|
+
}
|
|
121
|
+
async function backup(targetPath) {
|
|
122
|
+
if (!fs.existsSync(targetPath)) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
// Don't overwrite an existing file without creating a backup first
|
|
126
|
+
const backupPath = targetPath + '.bak';
|
|
127
|
+
if (debug) {
|
|
128
|
+
console.debug('backing up', targetPath, 'to', backupPath);
|
|
129
|
+
}
|
|
130
|
+
return fs.promises.copyFile(targetPath, backupPath);
|
|
131
|
+
}
|
|
132
|
+
async function copyFileWithBackup(sourcePath, targetPath) {
|
|
133
|
+
await backup(targetPath);
|
|
66
134
|
if (debug) {
|
|
67
135
|
console.debug('copying', sourcePath, 'to', targetPath);
|
|
68
136
|
}
|
|
@@ -73,9 +141,9 @@ async function copyConfigFiles() {
|
|
|
73
141
|
console.debug('cwd', process.cwd());
|
|
74
142
|
}
|
|
75
143
|
const templateDir = path.resolve(__dirname, '../templates');
|
|
144
|
+
// The browser config is gone: `instrumentation-client` now configures the browser,
|
|
145
|
+
// and it runs before hydration rather than via a bundler-injected entry point.
|
|
76
146
|
const configFiles = [
|
|
77
|
-
'honeybadger.browser.config.js',
|
|
78
|
-
'honeybadger.edge.config.js',
|
|
79
147
|
'honeybadger.server.config.js',
|
|
80
148
|
];
|
|
81
149
|
const copyPromises = configFiles.map((file) => {
|
|
@@ -84,13 +152,17 @@ async function copyConfigFiles() {
|
|
|
84
152
|
}
|
|
85
153
|
return fs.promises.copyFile(path.join(templateDir, file), file);
|
|
86
154
|
});
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
155
|
+
const instrumentationFolder = instrumentationDir();
|
|
156
|
+
copyPromises.push(copyInstrumentationFile('instrumentation', instrumentationFolder));
|
|
157
|
+
copyPromises.push(copyInstrumentationFile('instrumentation-client', instrumentationFolder));
|
|
158
|
+
const pagesDir = locateRouterDir('pages');
|
|
159
|
+
if (pagesDir !== null) {
|
|
160
|
+
copyPromises.push(copyErrorJs(pagesDir, false));
|
|
90
161
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
copyPromises.push(
|
|
162
|
+
const appDir = locateRouterDir('app');
|
|
163
|
+
if (appDir !== null) {
|
|
164
|
+
copyPromises.push(copyErrorJs(appDir, true));
|
|
165
|
+
copyPromises.push(copyGlobalErrorJs(appDir));
|
|
94
166
|
}
|
|
95
167
|
await Promise.all(copyPromises);
|
|
96
168
|
console.log('Done copying config files.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy-config-files.js","sources":["../../build/copy-config-files.js"],"sourcesContent":["const path = require('path');\nconst fs = require('fs');\nconst debug = process.env.HONEYBADGER_DEBUG === 'true';\nfunction usesTypescript() {\n return fs.existsSync('tsconfig.json');\n}\nfunction usesSrcFolder() {\n return fs.existsSync('src');\n}\nfunction usesPagesRouter(isUnderSrc) {\n const srcFolder = isUnderSrc ? 'src' : '';\n return fs.existsSync(path.join(srcFolder, 'pages'));\n}\nfunction usesAppRouter(isUnderSrc) {\n const srcFolder = isUnderSrc ? 'src' : '';\n return fs.existsSync(path.join(srcFolder, 'app'));\n}\nfunction getTargetPath(isUnderSrc, isAppRouter = false, isGlobalErrorComponent = false) {\n if (!isAppRouter && isGlobalErrorComponent) {\n throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true');\n }\n const extension = usesTypescript() ? 'tsx' : 'js';\n let srcFolder = isUnderSrc ? 'src' : '';\n srcFolder = path.join(srcFolder, isAppRouter ? 'app' : 'pages');\n let fileName = '';\n if (isAppRouter) {\n fileName = isGlobalErrorComponent ? 'global-error' : 'error';\n }\n else {\n fileName = '_error';\n }\n return path.join(srcFolder, fileName + '.' + extension);\n}\nfunction getTemplate(isAppRouter = false, isGlobalErrorComponent = false) {\n if (!isAppRouter && isGlobalErrorComponent) {\n throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true');\n }\n const extension = isGlobalErrorComponent ? 'tsx' : 'js';\n const templateName = isAppRouter ? '_error_app_router' : '_error';\n return path.resolve(__dirname, '../templates', templateName + '.' + extension);\n}\nasync function copyErrorJs(isUnderSrc, isAppRouter = false) {\n const sourcePath = getTemplate(isAppRouter);\n const targetPath = getTargetPath(isUnderSrc, isAppRouter);\n return copyFileWithBackup(sourcePath, targetPath);\n}\nfunction copyGlobalErrorJs(isUnderSrc) {\n const sourcePath = getTemplate(true, true);\n const targetPath = getTargetPath(isUnderSrc, true, true);\n return copyFileWithBackup(sourcePath, targetPath);\n}\nasync function copyFileWithBackup(sourcePath, targetPath) {\n const fileAlreadyExists = fs.existsSync(targetPath);\n if (fileAlreadyExists) {\n // Don't overwrite an existing file without creating a backup first\n const backupPath = targetPath + '.bak';\n if (debug) {\n console.debug('backing up', targetPath, 'to', backupPath);\n }\n await fs.promises.copyFile(targetPath, backupPath);\n }\n if (debug) {\n console.debug('copying', sourcePath, 'to', targetPath);\n }\n return fs.promises.copyFile(sourcePath, targetPath);\n}\nexport async function copyConfigFiles() {\n if (debug) {\n console.debug('cwd', process.cwd());\n }\n const templateDir = path.resolve(__dirname, '../templates');\n const configFiles = [\n 'honeybadger.browser.config.js',\n 'honeybadger.edge.config.js',\n 'honeybadger.server.config.js',\n ];\n const copyPromises = configFiles.map((file) => {\n if (debug) {\n console.debug('copying', file);\n }\n return fs.promises.copyFile(path.join(templateDir, file), file);\n });\n const isUnderSrcFolder = usesSrcFolder();\n if (usesPagesRouter(isUnderSrcFolder)) {\n copyPromises.push(copyErrorJs(isUnderSrcFolder, false));\n }\n if (usesAppRouter(isUnderSrcFolder)) {\n copyPromises.push(copyErrorJs(isUnderSrcFolder, true));\n copyPromises.push(copyGlobalErrorJs(isUnderSrcFolder));\n }\n await Promise.all(copyPromises);\n console.log('Done copying config files.');\n}\n//# sourceMappingURL=copy-config-files.js.map"],"names":[],"mappings":";;;;AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,MAAM,CAAC;AACvD,SAAS,cAAc,GAAG;AAC1B,IAAI,OAAO,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;AAC1C,CAAC;AACD,SAAS,aAAa,GAAG;AACzB,IAAI,OAAO,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AACD,SAA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W,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC,CAAC;AAChE,KAAK;AACL,IAAI,IAAI,aAAa,CAAC,gBAAgB,CAAC,EAAE;AACzC,QAAQ,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC,CAAC;AAC/D,QAAQ,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAC/D,KAAK;AACL,IAAI,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AACpC,IAAI,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAC9C;;;;"}
|
|
1
|
+
{"version":3,"file":"copy-config-files.js","sources":["../../build/copy-config-files.js"],"sourcesContent":["const path = require('path');\nconst fs = require('fs');\nconst debug = process.env.HONEYBADGER_DEBUG === 'true';\nfunction usesTypescript() {\n return fs.existsSync('tsconfig.json');\n}\n/**\n * Where a router directory actually lives: `''` for the project root, `'src'`, or `null`\n * when the project does not use that router.\n *\n * A root `app/` (or `pages/`) can sit beside a `src/` folder used for something else, so\n * this locates each directory rather than assuming a layout. Root wins when a directory\n * somehow exists in both places, matching Next.js.\n */\nfunction locateRouterDir(router) {\n if (fs.existsSync(router)) {\n return '';\n }\n if (fs.existsSync(path.join('src', router))) {\n return 'src';\n }\n return null;\n}\n/**\n * Where Next.js resolves the `instrumentation` files. It derives that directory as the\n * parent of `pagesDir || appDir`:\n *\n * const rootDir = path.join((pagesDir || appDir)!, '..')\n * — packages/next/src/build/index.ts\n *\n * So it is the parent of whichever router directory is found, and the Pages Router wins\n * when a project has both. A project with a root `app/` and a `src/pages/` therefore\n * resolves instrumentation under `src/`, not at the root.\n *\n * Getting this wrong is silent — the file is written somewhere Next.js never reads, so\n * nothing is instrumented and nothing complains.\n */\nfunction instrumentationDir() {\n var _a;\n const pagesDir = locateRouterDir('pages');\n if (pagesDir !== null) {\n return pagesDir;\n }\n return (_a = locateRouterDir('app')) !== null && _a !== void 0 ? _a : '';\n}\nfunction getTargetPath(routerDir, isAppRouter = false, isGlobalErrorComponent = false) {\n if (!isAppRouter && isGlobalErrorComponent) {\n throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true');\n }\n const extension = usesTypescript() ? 'tsx' : 'js';\n const srcFolder = path.join(routerDir, isAppRouter ? 'app' : 'pages');\n let fileName = '';\n if (isAppRouter) {\n fileName = isGlobalErrorComponent ? 'global-error' : 'error';\n }\n else {\n fileName = '_error';\n }\n return path.join(srcFolder, fileName + '.' + extension);\n}\nfunction getTemplate(isAppRouter = false, isGlobalErrorComponent = false) {\n if (!isAppRouter && isGlobalErrorComponent) {\n throw new Error('invalid arguments: isGlobalErrorComponent can only be true when isAppRouter is true');\n }\n const templateName = isAppRouter ? '_error_app_router' : '_error';\n // `_error_app_router` ships as a JS/TS pair that differs only by the prop type\n // annotation, so pick the one matching the target file's extension. `_error` is JS-only,\n // so it has no pair.\n const hasTypedVariant = isAppRouter;\n const extension = hasTypedVariant && usesTypescript() ? 'tsx' : 'js';\n return path.resolve(__dirname, '../templates', templateName + '.' + extension);\n}\nasync function copyErrorJs(routerDir, isAppRouter = false) {\n const sourcePath = getTemplate(isAppRouter);\n const targetPath = getTargetPath(routerDir, isAppRouter);\n return copyFileWithBackup(sourcePath, targetPath);\n}\nfunction copyGlobalErrorJs(routerDir) {\n const sourcePath = getTemplate(true, true);\n const targetPath = getTargetPath(routerDir, true, true);\n return copyFileWithBackup(sourcePath, targetPath);\n}\n/**\n * `instrumentation` and `instrumentation-client` are Next.js file conventions, so unlike\n * the `honeybadger.*.config` files their location is dictated by Next.js — see\n * `instrumentationDir` for the rule.\n *\n * The config files always stay at the project root, so when the instrumentation file\n * lands in `src/` instead its relative import has to climb one level.\n */\nasync function copyInstrumentationFile(name, srcFolder) {\n const sourcePath = path.resolve(__dirname, '../templates', name + '.js');\n const extension = usesTypescript() ? 'ts' : 'js';\n const targetPath = path.join(srcFolder, name + '.' + extension);\n // Unlike the honeybadger.* files, `instrumentation` is a shared Next.js convention:\n // other tools register their own hooks in it. Overwriting it would silently stop them\n // running, and a .bak file is no help if nobody notices, so leave an existing file\n // alone and print what to add instead.\n const existingPath = ['ts', 'js', 'mjs']\n .map((ext) => path.join(srcFolder, name + '.' + ext))\n .find((candidate) => fs.existsSync(candidate));\n if (existingPath) {\n console.log(`\\nSkipped ${existingPath} because it already exists — it may register hooks for ` +\n 'other tools.\\nAdd Honeybadger to it by hand; see ' +\n `${path.relative(process.cwd(), sourcePath)} for the contents to merge in.`);\n return;\n }\n let contents = await fs.promises.readFile(sourcePath, 'utf8');\n if (srcFolder) {\n contents = contents.replace(/(['\"])\\.\\/honeybadger\\./g, '$1../honeybadger.');\n }\n if (debug) {\n console.debug('writing', targetPath);\n }\n return fs.promises.writeFile(targetPath, contents);\n}\nasync function backup(targetPath) {\n if (!fs.existsSync(targetPath)) {\n return;\n }\n // Don't overwrite an existing file without creating a backup first\n const backupPath = targetPath + '.bak';\n if (debug) {\n console.debug('backing up', targetPath, 'to', backupPath);\n }\n return fs.promises.copyFile(targetPath, backupPath);\n}\nasync function copyFileWithBackup(sourcePath, targetPath) {\n await backup(targetPath);\n if (debug) {\n console.debug('copying', sourcePath, 'to', targetPath);\n }\n return fs.promises.copyFile(sourcePath, targetPath);\n}\nexport async function copyConfigFiles() {\n if (debug) {\n console.debug('cwd', process.cwd());\n }\n const templateDir = path.resolve(__dirname, '../templates');\n // The browser config is gone: `instrumentation-client` now configures the browser,\n // and it runs before hydration rather than via a bundler-injected entry point.\n const configFiles = [\n 'honeybadger.server.config.js',\n ];\n const copyPromises = configFiles.map((file) => {\n if (debug) {\n console.debug('copying', file);\n }\n return fs.promises.copyFile(path.join(templateDir, file), file);\n });\n const instrumentationFolder = instrumentationDir();\n copyPromises.push(copyInstrumentationFile('instrumentation', instrumentationFolder));\n copyPromises.push(copyInstrumentationFile('instrumentation-client', instrumentationFolder));\n const pagesDir = locateRouterDir('pages');\n if (pagesDir !== null) {\n copyPromises.push(copyErrorJs(pagesDir, false));\n }\n const appDir = locateRouterDir('app');\n if (appDir !== null) {\n copyPromises.push(copyErrorJs(appDir, true));\n copyPromises.push(copyGlobalErrorJs(appDir));\n }\n await Promise.all(copyPromises);\n console.log('Done copying config files.');\n}\n//# sourceMappingURL=copy-config-files.js.map"],"names":[],"mappings":";;;;AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,MAAM,CAAC;AACvD,SAAS,cAAc,GAAG;AAC1B,IAAI,OAAO,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;AAC1C,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe,CAAC,MAAM,EAAE;AACjC,IAAI,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;AAC/B,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE;AACjD,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,OAAO,IAAI,CAAC;AAChB,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,kBAAkB,GAAG;AAC9B,IAAI,IAAI,EAAE,CAAC;AACX,IAAI,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;AAC9C,IAAI,IAAI,QAAQ,KAAK,IAAI,EAAE;AAC3B,QAAQ,OAAO,QAAQ,CAAC;AACxB,KAAK;AACL,IAAI,OAAO,CAAC,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,EAAE,KAAK,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AAC;AAC9C,IAAI,IAAI,QAAQ,KAAK,IAAI,EAAE;AAC3B,QAAQ,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;AACxD,KAAK;AACL,IAAI,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;AAC1C,IAAI,IAAI,MAAM,KAAK,IAAI,EAAE;AACzB,QAAQ,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AACrD,QAAQ,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;AACrD,KAAK;AACL,IAAI,MAAM,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AACpC,IAAI,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AAC9C;;;;"}
|
package/dist/edge.d.ts
CHANGED
package/dist/flush.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type WaitUntil = (promise: Promise<unknown>) => void;
|
|
2
|
+
/**
|
|
3
|
+
* The `waitUntil` primitive the hosting platform injects per request. Next.js
|
|
4
|
+
* resolves `after()` through this same accessor, and it is the only channel
|
|
5
|
+
* available in Pages Router API routes, which are invoked as `(req, res)` with
|
|
6
|
+
* no context argument to read it from.
|
|
7
|
+
*/
|
|
8
|
+
export declare function requestContextWaitUntil(): WaitUntil | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Ensure events are delivered before a serverless runtime freezes, without
|
|
11
|
+
* delaying the response where the runtime lets us avoid it.
|
|
12
|
+
*
|
|
13
|
+
* In order of preference: Next.js `after()` (App Router only — it needs App Router
|
|
14
|
+
* request context, so Pages Router must not call it), then a `waitUntil` from the
|
|
15
|
+
* platform request context, then a blocking `flushAsync()` when the runtime offers
|
|
16
|
+
* neither.
|
|
17
|
+
*
|
|
18
|
+
* Delivery failures are logged by the events worker and must not break the handler.
|
|
19
|
+
*/
|
|
20
|
+
export declare function scheduleFlush(options?: {
|
|
21
|
+
useAfter?: boolean;
|
|
22
|
+
waitUntil?: WaitUntil;
|
|
23
|
+
}): Promise<void> | void;
|
|
24
|
+
//# sourceMappingURL=flush.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var Honeybadger = require('@honeybadger-io/js');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var Honeybadger__default = /*#__PURE__*/_interopDefaultLegacy(Honeybadger);
|
|
10
|
+
|
|
11
|
+
// Deliberately @honeybadger-io/js, not @honeybadger-io/react. The react package re-exports
|
|
12
|
+
/**
|
|
13
|
+
* Records App Router navigations as breadcrumbs, so a fault carries the trail of routes
|
|
14
|
+
* the user visited before it.
|
|
15
|
+
*
|
|
16
|
+
* Wire it up in `instrumentation-client.ts`:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* export const onRouterTransitionStart = captureRouterTransitionStart
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Exported as a ready-made handler rather than left as a function for the template to
|
|
23
|
+
* declare, so the generated file works unchanged as both `.js` and `.ts` — an assignment
|
|
24
|
+
* has no parameters to annotate, so there is no implicit `any` for `noImplicitAny` to
|
|
25
|
+
* reject.
|
|
26
|
+
*/
|
|
27
|
+
function captureRouterTransitionStart(url, navigationType) {
|
|
28
|
+
// The message carries the path alone and the full URL goes in the metadata, where the
|
|
29
|
+
// configured `filters` are applied to its query string when the payload is built. This is
|
|
30
|
+
// the same split the browser integration already uses for its XHR and fetch breadcrumbs,
|
|
31
|
+
// whose messages are built from `localURLPathname`.
|
|
32
|
+
Honeybadger__default["default"].addBreadcrumb(`Navigated to ${url.split('?')[0]}`, {
|
|
33
|
+
category: 'navigation',
|
|
34
|
+
metadata: { url, navigationType },
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.captureRouterTransitionStart = captureRouterTransitionStart;
|
|
39
|
+
//# sourceMappingURL=honeybadger-nextjs-client.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"honeybadger-nextjs-client.cjs.js","sources":["../../build/capture-router-transition-start.js"],"sourcesContent":["// Deliberately @honeybadger-io/js, not @honeybadger-io/react. The react package re-exports\n// this exact singleton, but reaching it through there also pulls in the error-boundary class\n// component — and this module sits in the main barrel that `instrumentation.ts` imports on\n// the server, where React Server Components reject a class component outright under\n// Turbopack.\nimport Honeybadger from '@honeybadger-io/js';\n/**\n * Records App Router navigations as breadcrumbs, so a fault carries the trail of routes\n * the user visited before it.\n *\n * Wire it up in `instrumentation-client.ts`:\n *\n * ```ts\n * export const onRouterTransitionStart = captureRouterTransitionStart\n * ```\n *\n * Exported as a ready-made handler rather than left as a function for the template to\n * declare, so the generated file works unchanged as both `.js` and `.ts` — an assignment\n * has no parameters to annotate, so there is no implicit `any` for `noImplicitAny` to\n * reject.\n */\nexport function captureRouterTransitionStart(url, navigationType) {\n // The message carries the path alone and the full URL goes in the metadata, where the\n // configured `filters` are applied to its query string when the payload is built. This is\n // the same split the browser integration already uses for its XHR and fetch breadcrumbs,\n // whose messages are built from `localURLPathname`.\n Honeybadger.addBreadcrumb(`Navigated to ${url.split('?')[0]}`, {\n category: 'navigation',\n metadata: { url, navigationType },\n });\n}\n//# sourceMappingURL=capture-router-transition-start.js.map"],"names":["Honeybadger"],"mappings":";;;;;;;;;;AAAA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,4BAA4B,CAAC,GAAG,EAAE,cAAc,EAAE;AAClE;AACA;AACA;AACA;AACA,IAAIA,+BAAW,CAAC,aAAa,CAAC,CAAC,aAAa,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;AACnE,QAAQ,QAAQ,EAAE,YAAY;AAC9B,QAAQ,QAAQ,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE;AACzC,KAAK,CAAC,CAAC;AACP;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Honeybadger from '@honeybadger-io/js';
|
|
2
|
+
|
|
3
|
+
// Deliberately @honeybadger-io/js, not @honeybadger-io/react. The react package re-exports
|
|
4
|
+
/**
|
|
5
|
+
* Records App Router navigations as breadcrumbs, so a fault carries the trail of routes
|
|
6
|
+
* the user visited before it.
|
|
7
|
+
*
|
|
8
|
+
* Wire it up in `instrumentation-client.ts`:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* export const onRouterTransitionStart = captureRouterTransitionStart
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Exported as a ready-made handler rather than left as a function for the template to
|
|
15
|
+
* declare, so the generated file works unchanged as both `.js` and `.ts` — an assignment
|
|
16
|
+
* has no parameters to annotate, so there is no implicit `any` for `noImplicitAny` to
|
|
17
|
+
* reject.
|
|
18
|
+
*/
|
|
19
|
+
function captureRouterTransitionStart(url, navigationType) {
|
|
20
|
+
// The message carries the path alone and the full URL goes in the metadata, where the
|
|
21
|
+
// configured `filters` are applied to its query string when the payload is built. This is
|
|
22
|
+
// the same split the browser integration already uses for its XHR and fetch breadcrumbs,
|
|
23
|
+
// whose messages are built from `localURLPathname`.
|
|
24
|
+
Honeybadger.addBreadcrumb(`Navigated to ${url.split('?')[0]}`, {
|
|
25
|
+
category: 'navigation',
|
|
26
|
+
metadata: { url, navigationType },
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { captureRouterTransitionStart };
|
|
31
|
+
//# sourceMappingURL=honeybadger-nextjs-client.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"honeybadger-nextjs-client.esm.js","sources":["../../build/capture-router-transition-start.js"],"sourcesContent":["// Deliberately @honeybadger-io/js, not @honeybadger-io/react. The react package re-exports\n// this exact singleton, but reaching it through there also pulls in the error-boundary class\n// component — and this module sits in the main barrel that `instrumentation.ts` imports on\n// the server, where React Server Components reject a class component outright under\n// Turbopack.\nimport Honeybadger from '@honeybadger-io/js';\n/**\n * Records App Router navigations as breadcrumbs, so a fault carries the trail of routes\n * the user visited before it.\n *\n * Wire it up in `instrumentation-client.ts`:\n *\n * ```ts\n * export const onRouterTransitionStart = captureRouterTransitionStart\n * ```\n *\n * Exported as a ready-made handler rather than left as a function for the template to\n * declare, so the generated file works unchanged as both `.js` and `.ts` — an assignment\n * has no parameters to annotate, so there is no implicit `any` for `noImplicitAny` to\n * reject.\n */\nexport function captureRouterTransitionStart(url, navigationType) {\n // The message carries the path alone and the full URL goes in the metadata, where the\n // configured `filters` are applied to its query string when the payload is built. This is\n // the same split the browser integration already uses for its XHR and fetch breadcrumbs,\n // whose messages are built from `localURLPathname`.\n Honeybadger.addBreadcrumb(`Navigated to ${url.split('?')[0]}`, {\n category: 'navigation',\n metadata: { url, navigationType },\n });\n}\n//# sourceMappingURL=capture-router-transition-start.js.map"],"names":[],"mappings":";;AAAA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,4BAA4B,CAAC,GAAG,EAAE,cAAc,EAAE;AAClE;AACA;AACA;AACA;AACA,IAAI,WAAW,CAAC,aAAa,CAAC,CAAC,aAAa,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;AACnE,QAAQ,QAAQ,EAAE,YAAY;AAC9B,QAAQ,QAAQ,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE;AACzC,KAAK,CAAC,CAAC;AACP;;;;"}
|