@seliseblocks/genesis-os 4.2.8 → 4.2.9
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.
|
@@ -32,10 +32,11 @@ var DEFAULT_IGNORED_MESSAGES = [
|
|
|
32
32
|
"ResizeObserver loop completed with undelivered notifications",
|
|
33
33
|
"Script error."
|
|
34
34
|
];
|
|
35
|
+
var UNCONFIGURED_ACCESS_TOKEN = "rollbar-reporting-disabled";
|
|
35
36
|
var createRollbarConfig = (options) => {
|
|
36
37
|
const accessToken = chunkX4YCRWXO_cjs.getRuntimeEnv("BLOCKS_ROLLBAR_CLIENT_TOKEN");
|
|
37
38
|
return {
|
|
38
|
-
accessToken,
|
|
39
|
+
accessToken: accessToken || UNCONFIGURED_ACCESS_TOKEN,
|
|
39
40
|
// Reporting is opt-in on a seeded token. Unconfigured environments -- developer machines,
|
|
40
41
|
// tests, any tier not yet seeded -- get an inert client rather than a broken one, so the error
|
|
41
42
|
// boundary still behaves exactly as it does in production.
|
|
@@ -144,6 +145,7 @@ var createHttpFailureReporter = (rollbar) => (failure) => {
|
|
|
144
145
|
};
|
|
145
146
|
|
|
146
147
|
exports.RollbarProvider = RollbarProvider;
|
|
148
|
+
exports.UNCONFIGURED_ACCESS_TOKEN = UNCONFIGURED_ACCESS_TOKEN;
|
|
147
149
|
exports.attachQueryErrorReporting = attachQueryErrorReporting;
|
|
148
150
|
exports.createHttpFailureReporter = createHttpFailureReporter;
|
|
149
151
|
exports.createRollbarConfig = createRollbarConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/observability/rollbar.config.ts","../../src/observability/rollbar.instance.ts","../../src/observability/report-query-errors.ts","../../src/observability/rollbar.provider.tsx","../../src/observability/report-http-errors.ts"],"names":["getRuntimeEnv","Rollbar","HttpError","jsxs","jsx","useMemo","useEffect","getQueryClient","Provider","ErrorBoundary"],"mappings":";;;;;;;;;;;;;;AAUA,IAAM,oBAAA,GAA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,GACX,CAAC,OAAA,KACD,CAAC,OAAA,KAAsC;AACrC,EAAA,IAAI,CAAC,QAAQ,SAAA,EAAW;AAExB,EAAA,MAAM,KAAA,GACJ,OAAA,CAAQ,KAAA,YAAiB,KAAA,GACrB,OAAA,CAAQ,KAAA,GACR,IAAI,KAAA,CAAM,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAC,CAAA;AAErC,EAAA,OAAA,CAAQ,MAAM,KAAA,EAAO;AAAA,IACnB,MAAA,EAAQ,aAAA;AAAA,IACR,KAAK,OAAA,CAAQ,GAAA;AAAA,IACb,QAAQ,OAAA,CAAQ;AAAA,GACjB,CAAA;AACH","file":"index.cjs","sourcesContent":["import Rollbar from \"rollbar\";\nimport { getRuntimeEnv } from \"@/lib/runtime-env\";\n\n/**\n * Payload keys and header names that must never leave the browser.\n *\n * Rollbar scrubs a default set already; these are the platform-specific ones. Getting this wrong\n * ships a tenant's credentials to a third party, which is why it lives here rather than being\n * restated in every app.\n */\nconst DEFAULT_SCRUB_FIELDS = [\n \"x-blocks-key\",\n \"X-Blocks-Key\",\n \"Authorization\",\n \"authorization\",\n \"access_token\",\n \"refresh_token\",\n \"accessToken\",\n \"refreshToken\",\n \"password\",\n \"clientSecret\",\n \"client_secret\",\n \"connectionString\",\n \"secretValue\",\n];\n\n/**\n * Noise that reaches `window.onerror` but says nothing about the app: browser extensions,\n * cross-origin frames, and the ResizeObserver warning Chrome raises during ordinary layout.\n */\nconst DEFAULT_IGNORED_MESSAGES = [\n \"ResizeObserver loop limit exceeded\",\n \"ResizeObserver loop completed with undelivered notifications\",\n \"Script error.\",\n];\n\nexport interface RollbarConfigOptions {\n /**\n * The app reporting, e.g. `\"blocks-os\"`. Pass the same name the app already gives\n * `BlocksAppLayout`, so items can be traced back to a service without a project-id lookup.\n */\n service: string;\n /** Appended to, not replacing, the platform scrub list. */\n extraScrubFields?: string[];\n /** Appended to, not replacing, the default ignore list. */\n extraIgnoredMessages?: string[];\n /** Identifies the build. Required for source-map deobfuscation once maps are uploaded. */\n codeVersion?: string;\n}\n\n/**\n * Builds the browser Rollbar configuration from runtime env.\n *\n * Separate from the provider so it can be asserted on directly: most of the risk in this module is\n * in the configuration -- scrubbing, and whether reporting is on at all -- not in Rollbar itself.\n */\nexport const createRollbarConfig = (\n options: RollbarConfigOptions,\n): Rollbar.Configuration => {\n const accessToken = getRuntimeEnv(\"BLOCKS_ROLLBAR_CLIENT_TOKEN\");\n\n return {\n accessToken,\n // Reporting is opt-in on a seeded token. Unconfigured environments -- developer machines,\n // tests, any tier not yet seeded -- get an inert client rather than a broken one, so the error\n // boundary still behaves exactly as it does in production.\n enabled: accessToken.length > 0,\n environment: getRuntimeEnv(\"BLOCKS_ROLLBAR_ENV\") || \"unknown\",\n captureUncaught: true,\n captureUnhandledRejections: true,\n scrubFields: [...DEFAULT_SCRUB_FIELDS, ...(options.extraScrubFields ?? [])],\n ignoredMessages: [\n ...DEFAULT_IGNORED_MESSAGES,\n ...(options.extraIgnoredMessages ?? []),\n ],\n payload: {\n // `service` identifies the app, `component` which half of it. Two fields rather than one\n // `blocks-os-client` string, so either can be filtered on without parsing.\n service: options.service,\n component: \"client\",\n client: {\n javascript: {\n source_map_enabled: Boolean(options.codeVersion),\n code_version: options.codeVersion,\n },\n },\n },\n };\n};\n","import Rollbar from \"rollbar\";\nimport {\n createRollbarConfig,\n type RollbarConfigOptions,\n} from \"./rollbar.config\";\n\nlet instance: Rollbar | undefined;\n\n/**\n * The one Rollbar instance for the app.\n *\n * Memoised on first call so that code outside the React tree -- an `HttpClient` built at module\n * scope, for instance -- reports through the same client the provider renders. A second instance\n * would install a second set of window handlers and split the telemetry buffer in two.\n *\n * First call wins: later calls return the existing instance and ignore their options. In practice\n * every call site passes the same service, and load order between a module-scope client and the\n * provider is not something an app should have to reason about.\n *\n * Created lazily, so merely importing this module installs nothing.\n */\nexport const getRollbar = (options: RollbarConfigOptions): Rollbar =>\n (instance ??= new Rollbar(createRollbarConfig(options)));\n","import type { QueryClient } from \"@tanstack/react-query\";\nimport type Rollbar from \"rollbar\";\nimport { HttpError } from \"@/lib/http/error\";\n\n/**\n * Reports errors thrown inside query and mutation functions that are not request failures.\n *\n * Narrow on purpose. Every failure from `HttpClient` arrives as an `HttpError` and is skipped here:\n * transport failures are already handled by `createHttpFailureReporter`, and HTTP statuses are\n * either business outcomes or faults the server reported itself. What remains is a genuine bug in a\n * query function -- a bad mapping, a null dereference on a response -- which React Query catches\n * and stores as query state, so it never reaches `window.onerror` and would otherwise be invisible.\n *\n * Returns an unsubscribe function.\n */\nexport const attachQueryErrorReporting = (\n queryClient: QueryClient,\n rollbar: Rollbar,\n): (() => void) => {\n const report = (error: unknown, context: Record<string, unknown>) => {\n if (error instanceof HttpError) return;\n // Belt and braces: an HttpError that crossed a module boundary may fail `instanceof`.\n if (typeof (error as { status?: unknown })?.status === \"number\") return;\n\n rollbar.error(error instanceof Error ? error : new Error(String(error)), {\n source: \"react-query\",\n ...context,\n });\n };\n\n const unsubscribeQueries = queryClient.getQueryCache().subscribe((event) => {\n if (event.type !== \"updated\" || event.action.type !== \"error\") return;\n\n report(event.action.error, {\n kind: \"query\",\n queryHash: event.query.queryHash,\n });\n });\n\n const unsubscribeMutations = queryClient\n .getMutationCache()\n .subscribe((event) => {\n if (event.type !== \"updated\" || event.action.type !== \"error\") return;\n\n report(event.action.error, {\n kind: \"mutation\",\n mutationKey: event.mutation.options.mutationKey,\n });\n });\n\n return () => {\n unsubscribeQueries();\n unsubscribeMutations();\n };\n};\n","import { ErrorBoundary, Provider } from \"@rollbar/react\";\nimport { useEffect, useMemo, type ComponentType, type ReactNode } from \"react\";\nimport { getQueryClient } from \"@/providers/query-client\";\nimport { attachQueryErrorReporting } from \"./report-query-errors\";\nimport { type RollbarConfigOptions } from \"./rollbar.config\";\nimport { getRollbar } from \"./rollbar.instance\";\n\nexport interface RollbarFallbackProps {\n error: Error | null;\n resetError: () => void;\n}\n\n/**\n * Shown instead of a blank page when a render throws. Deliberately plain: it has to render when the\n * app's own state is already known-bad, so it depends on nothing but theme tokens.\n */\nconst DefaultFallback = ({ resetError }: RollbarFallbackProps) => (\n <div\n className=\"flex min-h-screen flex-col items-center justify-center gap-4 bg-background px-6 text-center\"\n role=\"alert\"\n >\n <div className=\"space-y-1\">\n <p className=\"text-lg font-semibold text-foreground\">\n Something went wrong\n </p>\n <p className=\"text-sm text-medium-emphasis\">\n The error has been reported. Try again, or reload the page if it keeps\n happening.\n </p>\n </div>\n <button\n onClick={resetError}\n className=\"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground\"\n >\n Try again\n </button>\n </div>\n);\n\nexport interface RollbarProviderProps extends RollbarConfigOptions {\n children: ReactNode;\n /** Replaces the built-in crash screen. */\n fallback?: ComponentType<RollbarFallbackProps>;\n}\n\n/**\n * Puts Rollbar in front of the whole tree.\n *\n * Mount this outermost -- above the query, theme and router providers -- so a throw during their\n * own setup is still caught and reported rather than blanking the page.\n *\n * Reporting is inert until a client token is seeded (see `createRollbarConfig`), but the boundary is\n * always live, so the crash screen behaves identically in local development and in production.\n *\n * Covers uncaught errors, unhandled rejections, render crashes, and bugs thrown inside query\n * functions. Request failures are not covered here: pass `createHttpFailureReporter` to your\n * `HttpClient` as `onError` for those.\n */\nexport const RollbarProvider = ({\n children,\n fallback = DefaultFallback,\n ...configOptions\n}: RollbarProviderProps) => {\n // Shared with anything reporting from outside the tree, and stable for the life of the app:\n // reconstructing it on re-render would reinstall the window handlers and drop Rollbar's own\n // telemetry buffer.\n const rollbar = useMemo(\n () => getRollbar(configOptions),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n useEffect(\n () => attachQueryErrorReporting(getQueryClient(), rollbar),\n [rollbar],\n );\n\n return (\n <Provider instance={rollbar}>\n <ErrorBoundary fallbackUI={fallback} level=\"critical\">\n {children}\n </ErrorBoundary>\n </Provider>\n );\n};\n","import type Rollbar from \"rollbar\";\nimport type { HttpRequestFailure } from \"@/lib/http/types\";\n\n/**\n * Builds an `onError` handler for `HttpClientConfig` that reports only transport failures.\n *\n * Failures that produced an HTTP response are skipped deliberately: a 4xx is a business outcome the\n * UI already surfaces, and a 5xx has already been reported by the server with a real stack trace,\n * so reporting it again from the browser only buries the better item. What is left -- the API\n * unreachable, DNS, CORS, TLS, offline -- the server cannot report by definition, because it never\n * received the request.\n *\n * `HttpClient` normalises every failure to an `HttpError` with status 500 before callers see it, so\n * this distinction only exists inside the `onError` hook. Reporting from a `catch` further out\n * cannot tell the two apart.\n */\nexport const createHttpFailureReporter =\n (rollbar: Rollbar) =>\n (failure: HttpRequestFailure): void => {\n if (!failure.transport) return;\n\n const error =\n failure.error instanceof Error\n ? failure.error\n : new Error(String(failure.error));\n\n rollbar.error(error, {\n source: \"http-client\",\n url: failure.url,\n method: failure.method,\n });\n };\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/observability/rollbar.config.ts","../../src/observability/rollbar.instance.ts","../../src/observability/report-query-errors.ts","../../src/observability/rollbar.provider.tsx","../../src/observability/report-http-errors.ts"],"names":["getRuntimeEnv","Rollbar","HttpError","jsxs","jsx","useMemo","useEffect","getQueryClient","Provider","ErrorBoundary"],"mappings":";;;;;;;;;;;;;;AAUA,IAAM,oBAAA,GAAuB;AAAA,EAC3B,cAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,eAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACF,CAAA;AAMA,IAAM,wBAAA,GAA2B;AAAA,EAC/B,oCAAA;AAAA,EACA,8DAAA;AAAA,EACA;AACF,CAAA;AAaO,IAAM,yBAAA,GAA4B;AAsBlC,IAAM,mBAAA,GAAsB,CACjC,OAAA,KAC0B;AAC1B,EAAA,MAAM,WAAA,GAAcA,gCAAc,6BAA6B,CAAA;AAE/D,EAAA,OAAO;AAAA,IACL,aAAa,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\"rollbar\";\nimport { getRuntimeEnv } from \"@/lib/runtime-env\";\n\n/**\n * Payload keys and header names that must never leave the browser.\n *\n * Rollbar scrubs a default set already; these are the platform-specific ones. Getting this wrong\n * ships a tenant's credentials to a third party, which is why it lives here rather than being\n * restated in every app.\n */\nconst DEFAULT_SCRUB_FIELDS = [\n \"x-blocks-key\",\n \"X-Blocks-Key\",\n \"Authorization\",\n \"authorization\",\n \"access_token\",\n \"refresh_token\",\n \"accessToken\",\n \"refreshToken\",\n \"password\",\n \"clientSecret\",\n \"client_secret\",\n \"connectionString\",\n \"secretValue\",\n];\n\n/**\n * Noise that reaches `window.onerror` but says nothing about the app: browser extensions,\n * cross-origin frames, and the ResizeObserver warning Chrome raises during ordinary layout.\n */\nconst DEFAULT_IGNORED_MESSAGES = [\n \"ResizeObserver loop limit exceeded\",\n \"ResizeObserver loop completed with undelivered notifications\",\n \"Script error.\",\n];\n\n/**\n * Stands in for a real token when none is seeded.\n *\n * `@rollbar/react`'s `Provider` rejects an instance whose `options.accessToken` is falsy -- it\n * throws \"`instance` must be a configured instance of Rollbar\" from its own constructor, which is\n * above the error boundary, so an unconfigured app renders nothing at all. Reporting is switched\n * off by `enabled`, not by the token: the notifier refuses to send before it reaches a transport\n * and telemetry instrumentation is never installed. A placeholder therefore costs nothing and\n * keeps reporting genuinely optional, which is the point -- no tier should go blank because a\n * secret has not been seeded yet.\n */\nexport const UNCONFIGURED_ACCESS_TOKEN = \"rollbar-reporting-disabled\";\n\nexport interface RollbarConfigOptions {\n /**\n * The app reporting, e.g. `\"blocks-os\"`. Pass the same name the app already gives\n * `BlocksAppLayout`, so items can be traced back to a service without a project-id lookup.\n */\n service: string;\n /** Appended to, not replacing, the platform scrub list. */\n extraScrubFields?: string[];\n /** Appended to, not replacing, the default ignore list. */\n extraIgnoredMessages?: string[];\n /** Identifies the build. Required for source-map deobfuscation once maps are uploaded. */\n codeVersion?: string;\n}\n\n/**\n * Builds the browser Rollbar configuration from runtime env.\n *\n * Separate from the provider so it can be asserted on directly: most of the risk in this module is\n * in the configuration -- scrubbing, and whether reporting is on at all -- not in Rollbar itself.\n */\nexport const createRollbarConfig = (\n options: RollbarConfigOptions,\n): Rollbar.Configuration => {\n const accessToken = getRuntimeEnv(\"BLOCKS_ROLLBAR_CLIENT_TOKEN\");\n\n return {\n accessToken: accessToken || UNCONFIGURED_ACCESS_TOKEN,\n // Reporting is opt-in on a seeded token. Unconfigured environments -- developer machines,\n // tests, any tier not yet seeded -- get an inert client rather than a broken one, so the error\n // boundary still behaves exactly as it does in production.\n enabled: accessToken.length > 0,\n environment: getRuntimeEnv(\"BLOCKS_ROLLBAR_ENV\") || \"unknown\",\n captureUncaught: true,\n captureUnhandledRejections: true,\n scrubFields: [...DEFAULT_SCRUB_FIELDS, ...(options.extraScrubFields ?? [])],\n ignoredMessages: [\n ...DEFAULT_IGNORED_MESSAGES,\n ...(options.extraIgnoredMessages ?? []),\n ],\n payload: {\n // `service` identifies the app, `component` which half of it. Two fields rather than one\n // `blocks-os-client` string, so either can be filtered on without parsing.\n service: options.service,\n component: \"client\",\n client: {\n javascript: {\n source_map_enabled: Boolean(options.codeVersion),\n code_version: options.codeVersion,\n },\n },\n },\n };\n};\n","import Rollbar from \"rollbar\";\nimport {\n createRollbarConfig,\n type RollbarConfigOptions,\n} from \"./rollbar.config\";\n\nlet instance: Rollbar | undefined;\n\n/**\n * The one Rollbar instance for the app.\n *\n * Memoised on first call so that code outside the React tree -- an `HttpClient` built at module\n * scope, for instance -- reports through the same client the provider renders. A second instance\n * would install a second set of window handlers and split the telemetry buffer in two.\n *\n * First call wins: later calls return the existing instance and ignore their options. In practice\n * every call site passes the same service, and load order between a module-scope client and the\n * provider is not something an app should have to reason about.\n *\n * Created lazily, so merely importing this module installs nothing.\n */\nexport const getRollbar = (options: RollbarConfigOptions): Rollbar =>\n (instance ??= new Rollbar(createRollbarConfig(options)));\n","import type { QueryClient } from \"@tanstack/react-query\";\nimport type Rollbar from \"rollbar\";\nimport { HttpError } from \"@/lib/http/error\";\n\n/**\n * Reports errors thrown inside query and mutation functions that are not request failures.\n *\n * Narrow on purpose. Every failure from `HttpClient` arrives as an `HttpError` and is skipped here:\n * transport failures are already handled by `createHttpFailureReporter`, and HTTP statuses are\n * either business outcomes or faults the server reported itself. What remains is a genuine bug in a\n * query function -- a bad mapping, a null dereference on a response -- which React Query catches\n * and stores as query state, so it never reaches `window.onerror` and would otherwise be invisible.\n *\n * Returns an unsubscribe function.\n */\nexport const attachQueryErrorReporting = (\n queryClient: QueryClient,\n rollbar: Rollbar,\n): (() => void) => {\n const report = (error: unknown, context: Record<string, unknown>) => {\n if (error instanceof HttpError) return;\n // Belt and braces: an HttpError that crossed a module boundary may fail `instanceof`.\n if (typeof (error as { status?: unknown })?.status === \"number\") return;\n\n rollbar.error(error instanceof Error ? error : new Error(String(error)), {\n source: \"react-query\",\n ...context,\n });\n };\n\n const unsubscribeQueries = queryClient.getQueryCache().subscribe((event) => {\n if (event.type !== \"updated\" || event.action.type !== \"error\") return;\n\n report(event.action.error, {\n kind: \"query\",\n queryHash: event.query.queryHash,\n });\n });\n\n const unsubscribeMutations = queryClient\n .getMutationCache()\n .subscribe((event) => {\n if (event.type !== \"updated\" || event.action.type !== \"error\") return;\n\n report(event.action.error, {\n kind: \"mutation\",\n mutationKey: event.mutation.options.mutationKey,\n });\n });\n\n return () => {\n unsubscribeQueries();\n unsubscribeMutations();\n };\n};\n","import { ErrorBoundary, Provider } from \"@rollbar/react\";\nimport { useEffect, useMemo, type ComponentType, type ReactNode } from \"react\";\nimport { getQueryClient } from \"@/providers/query-client\";\nimport { attachQueryErrorReporting } from \"./report-query-errors\";\nimport { type RollbarConfigOptions } from \"./rollbar.config\";\nimport { getRollbar } from \"./rollbar.instance\";\n\nexport interface RollbarFallbackProps {\n error: Error | null;\n resetError: () => void;\n}\n\n/**\n * Shown instead of a blank page when a render throws. Deliberately plain: it has to render when the\n * app's own state is already known-bad, so it depends on nothing but theme tokens.\n */\nconst DefaultFallback = ({ resetError }: RollbarFallbackProps) => (\n <div\n className=\"flex min-h-screen flex-col items-center justify-center gap-4 bg-background px-6 text-center\"\n role=\"alert\"\n >\n <div className=\"space-y-1\">\n <p className=\"text-lg font-semibold text-foreground\">\n Something went wrong\n </p>\n <p className=\"text-sm text-medium-emphasis\">\n The error has been reported. Try again, or reload the page if it keeps\n happening.\n </p>\n </div>\n <button\n onClick={resetError}\n className=\"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground\"\n >\n Try again\n </button>\n </div>\n);\n\nexport interface RollbarProviderProps extends RollbarConfigOptions {\n children: ReactNode;\n /** Replaces the built-in crash screen. */\n fallback?: ComponentType<RollbarFallbackProps>;\n}\n\n/**\n * Puts Rollbar in front of the whole tree.\n *\n * Mount this outermost -- above the query, theme and router providers -- so a throw during their\n * own setup is still caught and reported rather than blanking the page.\n *\n * Reporting is inert until a client token is seeded (see `createRollbarConfig`), but the boundary is\n * always live, so the crash screen behaves identically in local development and in production.\n *\n * Covers uncaught errors, unhandled rejections, render crashes, and bugs thrown inside query\n * functions. Request failures are not covered here: pass `createHttpFailureReporter` to your\n * `HttpClient` as `onError` for those.\n */\nexport const RollbarProvider = ({\n children,\n fallback = DefaultFallback,\n ...configOptions\n}: RollbarProviderProps) => {\n // Shared with anything reporting from outside the tree, and stable for the life of the app:\n // reconstructing it on re-render would reinstall the window handlers and drop Rollbar's own\n // telemetry buffer.\n const rollbar = useMemo(\n () => getRollbar(configOptions),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n useEffect(\n () => attachQueryErrorReporting(getQueryClient(), rollbar),\n [rollbar],\n );\n\n return (\n <Provider instance={rollbar}>\n <ErrorBoundary fallbackUI={fallback} level=\"critical\">\n {children}\n </ErrorBoundary>\n </Provider>\n );\n};\n","import type Rollbar from \"rollbar\";\nimport type { HttpRequestFailure } from \"@/lib/http/types\";\n\n/**\n * Builds an `onError` handler for `HttpClientConfig` that reports only transport failures.\n *\n * Failures that produced an HTTP response are skipped deliberately: a 4xx is a business outcome the\n * UI already surfaces, and a 5xx has already been reported by the server with a real stack trace,\n * so reporting it again from the browser only buries the better item. What is left -- the API\n * unreachable, DNS, CORS, TLS, offline -- the server cannot report by definition, because it never\n * received the request.\n *\n * `HttpClient` normalises every failure to an `HttpError` with status 500 before callers see it, so\n * this distinction only exists inside the `onError` hook. Reporting from a `catch` further out\n * cannot tell the two apart.\n */\nexport const createHttpFailureReporter =\n (rollbar: Rollbar) =>\n (failure: HttpRequestFailure): void => {\n if (!failure.transport) return;\n\n const error =\n failure.error instanceof Error\n ? failure.error\n : new Error(String(failure.error));\n\n rollbar.error(error, {\n source: \"http-client\",\n url: failure.url,\n method: failure.method,\n });\n };\n"]}
|
|
@@ -7,6 +7,18 @@ import '../auth.model-BHLqtZG5.cjs';
|
|
|
7
7
|
import '../user.model-D-yeFp-2.cjs';
|
|
8
8
|
import '../base.types-XgGxHPNY.cjs';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Stands in for a real token when none is seeded.
|
|
12
|
+
*
|
|
13
|
+
* `@rollbar/react`'s `Provider` rejects an instance whose `options.accessToken` is falsy -- it
|
|
14
|
+
* throws "`instance` must be a configured instance of Rollbar" from its own constructor, which is
|
|
15
|
+
* above the error boundary, so an unconfigured app renders nothing at all. Reporting is switched
|
|
16
|
+
* off by `enabled`, not by the token: the notifier refuses to send before it reaches a transport
|
|
17
|
+
* and telemetry instrumentation is never installed. A placeholder therefore costs nothing and
|
|
18
|
+
* keeps reporting genuinely optional, which is the point -- no tier should go blank because a
|
|
19
|
+
* secret has not been seeded yet.
|
|
20
|
+
*/
|
|
21
|
+
declare const UNCONFIGURED_ACCESS_TOKEN = "rollbar-reporting-disabled";
|
|
10
22
|
interface RollbarConfigOptions {
|
|
11
23
|
/**
|
|
12
24
|
* The app reporting, e.g. `"blocks-os"`. Pass the same name the app already gives
|
|
@@ -95,4 +107,4 @@ declare const createHttpFailureReporter: (rollbar: Rollbar) => (failure: HttpReq
|
|
|
95
107
|
*/
|
|
96
108
|
declare const attachQueryErrorReporting: (queryClient: QueryClient, rollbar: Rollbar) => (() => void);
|
|
97
109
|
|
|
98
|
-
export { type RollbarConfigOptions, type RollbarFallbackProps, RollbarProvider, type RollbarProviderProps, attachQueryErrorReporting, createHttpFailureReporter, createRollbarConfig, getRollbar };
|
|
110
|
+
export { type RollbarConfigOptions, type RollbarFallbackProps, RollbarProvider, type RollbarProviderProps, UNCONFIGURED_ACCESS_TOKEN, attachQueryErrorReporting, createHttpFailureReporter, createRollbarConfig, getRollbar };
|
|
@@ -7,6 +7,18 @@ import '../auth.model-6We_OkEZ.js';
|
|
|
7
7
|
import '../user.model-jYC7Cd3G.js';
|
|
8
8
|
import '../base.types-XgGxHPNY.js';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Stands in for a real token when none is seeded.
|
|
12
|
+
*
|
|
13
|
+
* `@rollbar/react`'s `Provider` rejects an instance whose `options.accessToken` is falsy -- it
|
|
14
|
+
* throws "`instance` must be a configured instance of Rollbar" from its own constructor, which is
|
|
15
|
+
* above the error boundary, so an unconfigured app renders nothing at all. Reporting is switched
|
|
16
|
+
* off by `enabled`, not by the token: the notifier refuses to send before it reaches a transport
|
|
17
|
+
* and telemetry instrumentation is never installed. A placeholder therefore costs nothing and
|
|
18
|
+
* keeps reporting genuinely optional, which is the point -- no tier should go blank because a
|
|
19
|
+
* secret has not been seeded yet.
|
|
20
|
+
*/
|
|
21
|
+
declare const UNCONFIGURED_ACCESS_TOKEN = "rollbar-reporting-disabled";
|
|
10
22
|
interface RollbarConfigOptions {
|
|
11
23
|
/**
|
|
12
24
|
* The app reporting, e.g. `"blocks-os"`. Pass the same name the app already gives
|
|
@@ -95,4 +107,4 @@ declare const createHttpFailureReporter: (rollbar: Rollbar) => (failure: HttpReq
|
|
|
95
107
|
*/
|
|
96
108
|
declare const attachQueryErrorReporting: (queryClient: QueryClient, rollbar: Rollbar) => (() => void);
|
|
97
109
|
|
|
98
|
-
export { type RollbarConfigOptions, type RollbarFallbackProps, RollbarProvider, type RollbarProviderProps, attachQueryErrorReporting, createHttpFailureReporter, createRollbarConfig, getRollbar };
|
|
110
|
+
export { type RollbarConfigOptions, type RollbarFallbackProps, RollbarProvider, type RollbarProviderProps, UNCONFIGURED_ACCESS_TOKEN, attachQueryErrorReporting, createHttpFailureReporter, createRollbarConfig, getRollbar };
|
|
@@ -26,10 +26,11 @@ var DEFAULT_IGNORED_MESSAGES = [
|
|
|
26
26
|
"ResizeObserver loop completed with undelivered notifications",
|
|
27
27
|
"Script error."
|
|
28
28
|
];
|
|
29
|
+
var UNCONFIGURED_ACCESS_TOKEN = "rollbar-reporting-disabled";
|
|
29
30
|
var createRollbarConfig = (options) => {
|
|
30
31
|
const accessToken = getRuntimeEnv("BLOCKS_ROLLBAR_CLIENT_TOKEN");
|
|
31
32
|
return {
|
|
32
|
-
accessToken,
|
|
33
|
+
accessToken: accessToken || UNCONFIGURED_ACCESS_TOKEN,
|
|
33
34
|
// Reporting is opt-in on a seeded token. Unconfigured environments -- developer machines,
|
|
34
35
|
// tests, any tier not yet seeded -- get an inert client rather than a broken one, so the error
|
|
35
36
|
// boundary still behaves exactly as it does in production.
|
|
@@ -137,6 +138,6 @@ var createHttpFailureReporter = (rollbar) => (failure) => {
|
|
|
137
138
|
});
|
|
138
139
|
};
|
|
139
140
|
|
|
140
|
-
export { RollbarProvider, attachQueryErrorReporting, createHttpFailureReporter, createRollbarConfig, getRollbar };
|
|
141
|
+
export { RollbarProvider, UNCONFIGURED_ACCESS_TOKEN, attachQueryErrorReporting, createHttpFailureReporter, createRollbarConfig, getRollbar };
|
|
141
142
|
//# sourceMappingURL=index.js.map
|
|
142
143
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/observability/rollbar.config.ts","../../src/observability/rollbar.instance.ts","../../src/observability/report-query-errors.ts","../../src/observability/rollbar.provider.tsx","../../src/observability/report-http-errors.ts"],"names":["Roll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ACpEO,IAAM,yBAAA,GACX,CAAC,OAAA,KACD,CAAC,OAAA,KAAsC;AACrC,EAAA,IAAI,CAAC,QAAQ,SAAA,EAAW;AAExB,EAAA,MAAM,KAAA,GACJ,OAAA,CAAQ,KAAA,YAAiB,KAAA,GACrB,OAAA,CAAQ,KAAA,GACR,IAAI,KAAA,CAAM,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAC,CAAA;AAErC,EAAA,OAAA,CAAQ,MAAM,KAAA,EAAO;AAAA,IACnB,MAAA,EAAQ,aAAA;AAAA,IACR,KAAK,OAAA,CAAQ,GAAA;AAAA,IACb,QAAQ,OAAA,CAAQ;AAAA,GACjB,CAAA;AACH","file":"index.js","sourcesContent":["import Rollbar from \"rollbar\";\nimport { getRuntimeEnv } from \"@/lib/runtime-env\";\n\n/**\n * Payload keys and header names that must never leave the browser.\n *\n * Rollbar scrubs a default set already; these are the platform-specific ones. Getting this wrong\n * ships a tenant's credentials to a third party, which is why it lives here rather than being\n * restated in every app.\n */\nconst DEFAULT_SCRUB_FIELDS = [\n \"x-blocks-key\",\n \"X-Blocks-Key\",\n \"Authorization\",\n \"authorization\",\n \"access_token\",\n \"refresh_token\",\n \"accessToken\",\n \"refreshToken\",\n \"password\",\n \"clientSecret\",\n \"client_secret\",\n \"connectionString\",\n \"secretValue\",\n];\n\n/**\n * Noise that reaches `window.onerror` but says nothing about the app: browser extensions,\n * cross-origin frames, and the ResizeObserver warning Chrome raises during ordinary layout.\n */\nconst DEFAULT_IGNORED_MESSAGES = [\n \"ResizeObserver loop limit exceeded\",\n \"ResizeObserver loop completed with undelivered notifications\",\n \"Script error.\",\n];\n\nexport interface RollbarConfigOptions {\n /**\n * The app reporting, e.g. `\"blocks-os\"`. Pass the same name the app already gives\n * `BlocksAppLayout`, so items can be traced back to a service without a project-id lookup.\n */\n service: string;\n /** Appended to, not replacing, the platform scrub list. */\n extraScrubFields?: string[];\n /** Appended to, not replacing, the default ignore list. */\n extraIgnoredMessages?: string[];\n /** Identifies the build. Required for source-map deobfuscation once maps are uploaded. */\n codeVersion?: string;\n}\n\n/**\n * Builds the browser Rollbar configuration from runtime env.\n *\n * Separate from the provider so it can be asserted on directly: most of the risk in this module is\n * in the configuration -- scrubbing, and whether reporting is on at all -- not in Rollbar itself.\n */\nexport const createRollbarConfig = (\n options: RollbarConfigOptions,\n): Rollbar.Configuration => {\n const accessToken = getRuntimeEnv(\"BLOCKS_ROLLBAR_CLIENT_TOKEN\");\n\n return {\n accessToken,\n // Reporting is opt-in on a seeded token. Unconfigured environments -- developer machines,\n // tests, any tier not yet seeded -- get an inert client rather than a broken one, so the error\n // boundary still behaves exactly as it does in production.\n enabled: accessToken.length > 0,\n environment: getRuntimeEnv(\"BLOCKS_ROLLBAR_ENV\") || \"unknown\",\n captureUncaught: true,\n captureUnhandledRejections: true,\n scrubFields: [...DEFAULT_SCRUB_FIELDS, ...(options.extraScrubFields ?? [])],\n ignoredMessages: [\n ...DEFAULT_IGNORED_MESSAGES,\n ...(options.extraIgnoredMessages ?? []),\n ],\n payload: {\n // `service` identifies the app, `component` which half of it. Two fields rather than one\n // `blocks-os-client` string, so either can be filtered on without parsing.\n service: options.service,\n component: \"client\",\n client: {\n javascript: {\n source_map_enabled: Boolean(options.codeVersion),\n code_version: options.codeVersion,\n },\n },\n },\n };\n};\n","import Rollbar from \"rollbar\";\nimport {\n createRollbarConfig,\n type RollbarConfigOptions,\n} from \"./rollbar.config\";\n\nlet instance: Rollbar | undefined;\n\n/**\n * The one Rollbar instance for the app.\n *\n * Memoised on first call so that code outside the React tree -- an `HttpClient` built at module\n * scope, for instance -- reports through the same client the provider renders. A second instance\n * would install a second set of window handlers and split the telemetry buffer in two.\n *\n * First call wins: later calls return the existing instance and ignore their options. In practice\n * every call site passes the same service, and load order between a module-scope client and the\n * provider is not something an app should have to reason about.\n *\n * Created lazily, so merely importing this module installs nothing.\n */\nexport const getRollbar = (options: RollbarConfigOptions): Rollbar =>\n (instance ??= new Rollbar(createRollbarConfig(options)));\n","import type { QueryClient } from \"@tanstack/react-query\";\nimport type Rollbar from \"rollbar\";\nimport { HttpError } from \"@/lib/http/error\";\n\n/**\n * Reports errors thrown inside query and mutation functions that are not request failures.\n *\n * Narrow on purpose. Every failure from `HttpClient` arrives as an `HttpError` and is skipped here:\n * transport failures are already handled by `createHttpFailureReporter`, and HTTP statuses are\n * either business outcomes or faults the server reported itself. What remains is a genuine bug in a\n * query function -- a bad mapping, a null dereference on a response -- which React Query catches\n * and stores as query state, so it never reaches `window.onerror` and would otherwise be invisible.\n *\n * Returns an unsubscribe function.\n */\nexport const attachQueryErrorReporting = (\n queryClient: QueryClient,\n rollbar: Rollbar,\n): (() => void) => {\n const report = (error: unknown, context: Record<string, unknown>) => {\n if (error instanceof HttpError) return;\n // Belt and braces: an HttpError that crossed a module boundary may fail `instanceof`.\n if (typeof (error as { status?: unknown })?.status === \"number\") return;\n\n rollbar.error(error instanceof Error ? error : new Error(String(error)), {\n source: \"react-query\",\n ...context,\n });\n };\n\n const unsubscribeQueries = queryClient.getQueryCache().subscribe((event) => {\n if (event.type !== \"updated\" || event.action.type !== \"error\") return;\n\n report(event.action.error, {\n kind: \"query\",\n queryHash: event.query.queryHash,\n });\n });\n\n const unsubscribeMutations = queryClient\n .getMutationCache()\n .subscribe((event) => {\n if (event.type !== \"updated\" || event.action.type !== \"error\") return;\n\n report(event.action.error, {\n kind: \"mutation\",\n mutationKey: event.mutation.options.mutationKey,\n });\n });\n\n return () => {\n unsubscribeQueries();\n unsubscribeMutations();\n };\n};\n","import { ErrorBoundary, Provider } from \"@rollbar/react\";\nimport { useEffect, useMemo, type ComponentType, type ReactNode } from \"react\";\nimport { getQueryClient } from \"@/providers/query-client\";\nimport { attachQueryErrorReporting } from \"./report-query-errors\";\nimport { type RollbarConfigOptions } from \"./rollbar.config\";\nimport { getRollbar } from \"./rollbar.instance\";\n\nexport interface RollbarFallbackProps {\n error: Error | null;\n resetError: () => void;\n}\n\n/**\n * Shown instead of a blank page when a render throws. Deliberately plain: it has to render when the\n * app's own state is already known-bad, so it depends on nothing but theme tokens.\n */\nconst DefaultFallback = ({ resetError }: RollbarFallbackProps) => (\n <div\n className=\"flex min-h-screen flex-col items-center justify-center gap-4 bg-background px-6 text-center\"\n role=\"alert\"\n >\n <div className=\"space-y-1\">\n <p className=\"text-lg font-semibold text-foreground\">\n Something went wrong\n </p>\n <p className=\"text-sm text-medium-emphasis\">\n The error has been reported. Try again, or reload the page if it keeps\n happening.\n </p>\n </div>\n <button\n onClick={resetError}\n className=\"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground\"\n >\n Try again\n </button>\n </div>\n);\n\nexport interface RollbarProviderProps extends RollbarConfigOptions {\n children: ReactNode;\n /** Replaces the built-in crash screen. */\n fallback?: ComponentType<RollbarFallbackProps>;\n}\n\n/**\n * Puts Rollbar in front of the whole tree.\n *\n * Mount this outermost -- above the query, theme and router providers -- so a throw during their\n * own setup is still caught and reported rather than blanking the page.\n *\n * Reporting is inert until a client token is seeded (see `createRollbarConfig`), but the boundary is\n * always live, so the crash screen behaves identically in local development and in production.\n *\n * Covers uncaught errors, unhandled rejections, render crashes, and bugs thrown inside query\n * functions. Request failures are not covered here: pass `createHttpFailureReporter` to your\n * `HttpClient` as `onError` for those.\n */\nexport const RollbarProvider = ({\n children,\n fallback = DefaultFallback,\n ...configOptions\n}: RollbarProviderProps) => {\n // Shared with anything reporting from outside the tree, and stable for the life of the app:\n // reconstructing it on re-render would reinstall the window handlers and drop Rollbar's own\n // telemetry buffer.\n const rollbar = useMemo(\n () => getRollbar(configOptions),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n useEffect(\n () => attachQueryErrorReporting(getQueryClient(), rollbar),\n [rollbar],\n );\n\n return (\n <Provider instance={rollbar}>\n <ErrorBoundary fallbackUI={fallback} level=\"critical\">\n {children}\n </ErrorBoundary>\n </Provider>\n );\n};\n","import type Rollbar from \"rollbar\";\nimport type { HttpRequestFailure } from \"@/lib/http/types\";\n\n/**\n * Builds an `onError` handler for `HttpClientConfig` that reports only transport failures.\n *\n * Failures that produced an HTTP response are skipped deliberately: a 4xx is a business outcome the\n * UI already surfaces, and a 5xx has already been reported by the server with a real stack trace,\n * so reporting it again from the browser only buries the better item. What is left -- the API\n * unreachable, DNS, CORS, TLS, offline -- the server cannot report by definition, because it never\n * received the request.\n *\n * `HttpClient` normalises every failure to an `HttpError` with status 500 before callers see it, so\n * this distinction only exists inside the `onError` hook. Reporting from a `catch` further out\n * cannot tell the two apart.\n */\nexport const createHttpFailureReporter =\n (rollbar: Rollbar) =>\n (failure: HttpRequestFailure): void => {\n if (!failure.transport) return;\n\n const error =\n failure.error instanceof Error\n ? failure.error\n : new Error(String(failure.error));\n\n rollbar.error(error, {\n source: \"http-client\",\n url: failure.url,\n method: failure.method,\n });\n };\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/observability/rollbar.config.ts","../../src/observability/rollbar.instance.ts","../../src/observability/report-query-errors.ts","../../src/observability/rollbar.provider.tsx","../../src/observability/report-http-errors.ts"],"names":["Rollbar"],"mappings":";;;;;;;;AAUA,IAAM,oBAAA,GAAuB;AAAA,EAC3B,cAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,eAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,eAAA;AAAA,EACA,kBAAA;AAAA,EACA;AACF,CAAA;AAMA,IAAM,wBAAA,GAA2B;AAAA,EAC/B,oCAAA;AAAA,EACA,8DAAA;AAAA,EACA;AACF,CAAA;AAaO,IAAM,yBAAA,GAA4B;AAsBlC,IAAM,mBAAA,GAAsB,CACjC,OAAA,KAC0B;AAC1B,EAAA,MAAM,WAAA,GAAc,cAAc,6BAA6B,CAAA;AAE/D,EAAA,OAAO;AAAA,IACL,aAAa,WAAA,IAAe,yBAAA;AAAA;AAAA;AAAA;AAAA,IAI5B,OAAA,EA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CAAA;AAAA,sBACA,GAAA;AAAA,QAAC,QAAA;AAAA,QAAA;AAAA,UACC,OAAA,EAAS,UAAA;AAAA,UACT,SAAA,EAAU,6EAAA;AAAA,UACX,QAAA,EAAA;AAAA;AAAA;AAED;AAAA;AACF,CAAA;AAsBK,IAAM,kBAAkB,CAAC;AAAA,EAC9B,QAAA;AAAA,EACA,QAAA,GAAW,eAAA;AAAA,EACX,GAAG;AACL,CAAA,KAA4B;AAI1B,EAAA,MAAM,OAAA,GAAU,OAAA;AAAA,IACd,MAAM,WAAW,aAAa,CAAA;AAAA;AAAA,IAE9B;AAAC,GACH;AAEA,EAAA,SAAA;AAAA,IACE,MAAM,yBAAA,CAA0B,cAAA,EAAe,EAAG,OAAO,CAAA;AAAA,IACzD,CAAC,OAAO;AAAA,GACV;AAEA,EAAA,uBACE,GAAA,CAAC,QAAA,EAAA,EAAS,QAAA,EAAU,OAAA,EAClB,QAAA,kBAAA,GAAA,CAAC,aAAA,EAAA,EAAc,UAAA,EAAY,QAAA,EAAU,KAAA,EAAM,UAAA,EACxC,QAAA,EACH,CAAA,EACF,CAAA;AAEJ;;;ACpEO,IAAM,yBAAA,GACX,CAAC,OAAA,KACD,CAAC,OAAA,KAAsC;AACrC,EAAA,IAAI,CAAC,QAAQ,SAAA,EAAW;AAExB,EAAA,MAAM,KAAA,GACJ,OAAA,CAAQ,KAAA,YAAiB,KAAA,GACrB,OAAA,CAAQ,KAAA,GACR,IAAI,KAAA,CAAM,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAC,CAAA;AAErC,EAAA,OAAA,CAAQ,MAAM,KAAA,EAAO;AAAA,IACnB,MAAA,EAAQ,aAAA;AAAA,IACR,KAAK,OAAA,CAAQ,GAAA;AAAA,IACb,QAAQ,OAAA,CAAQ;AAAA,GACjB,CAAA;AACH","file":"index.js","sourcesContent":["import Rollbar from \"rollbar\";\nimport { getRuntimeEnv } from \"@/lib/runtime-env\";\n\n/**\n * Payload keys and header names that must never leave the browser.\n *\n * Rollbar scrubs a default set already; these are the platform-specific ones. Getting this wrong\n * ships a tenant's credentials to a third party, which is why it lives here rather than being\n * restated in every app.\n */\nconst DEFAULT_SCRUB_FIELDS = [\n \"x-blocks-key\",\n \"X-Blocks-Key\",\n \"Authorization\",\n \"authorization\",\n \"access_token\",\n \"refresh_token\",\n \"accessToken\",\n \"refreshToken\",\n \"password\",\n \"clientSecret\",\n \"client_secret\",\n \"connectionString\",\n \"secretValue\",\n];\n\n/**\n * Noise that reaches `window.onerror` but says nothing about the app: browser extensions,\n * cross-origin frames, and the ResizeObserver warning Chrome raises during ordinary layout.\n */\nconst DEFAULT_IGNORED_MESSAGES = [\n \"ResizeObserver loop limit exceeded\",\n \"ResizeObserver loop completed with undelivered notifications\",\n \"Script error.\",\n];\n\n/**\n * Stands in for a real token when none is seeded.\n *\n * `@rollbar/react`'s `Provider` rejects an instance whose `options.accessToken` is falsy -- it\n * throws \"`instance` must be a configured instance of Rollbar\" from its own constructor, which is\n * above the error boundary, so an unconfigured app renders nothing at all. Reporting is switched\n * off by `enabled`, not by the token: the notifier refuses to send before it reaches a transport\n * and telemetry instrumentation is never installed. A placeholder therefore costs nothing and\n * keeps reporting genuinely optional, which is the point -- no tier should go blank because a\n * secret has not been seeded yet.\n */\nexport const UNCONFIGURED_ACCESS_TOKEN = \"rollbar-reporting-disabled\";\n\nexport interface RollbarConfigOptions {\n /**\n * The app reporting, e.g. `\"blocks-os\"`. Pass the same name the app already gives\n * `BlocksAppLayout`, so items can be traced back to a service without a project-id lookup.\n */\n service: string;\n /** Appended to, not replacing, the platform scrub list. */\n extraScrubFields?: string[];\n /** Appended to, not replacing, the default ignore list. */\n extraIgnoredMessages?: string[];\n /** Identifies the build. Required for source-map deobfuscation once maps are uploaded. */\n codeVersion?: string;\n}\n\n/**\n * Builds the browser Rollbar configuration from runtime env.\n *\n * Separate from the provider so it can be asserted on directly: most of the risk in this module is\n * in the configuration -- scrubbing, and whether reporting is on at all -- not in Rollbar itself.\n */\nexport const createRollbarConfig = (\n options: RollbarConfigOptions,\n): Rollbar.Configuration => {\n const accessToken = getRuntimeEnv(\"BLOCKS_ROLLBAR_CLIENT_TOKEN\");\n\n return {\n accessToken: accessToken || UNCONFIGURED_ACCESS_TOKEN,\n // Reporting is opt-in on a seeded token. Unconfigured environments -- developer machines,\n // tests, any tier not yet seeded -- get an inert client rather than a broken one, so the error\n // boundary still behaves exactly as it does in production.\n enabled: accessToken.length > 0,\n environment: getRuntimeEnv(\"BLOCKS_ROLLBAR_ENV\") || \"unknown\",\n captureUncaught: true,\n captureUnhandledRejections: true,\n scrubFields: [...DEFAULT_SCRUB_FIELDS, ...(options.extraScrubFields ?? [])],\n ignoredMessages: [\n ...DEFAULT_IGNORED_MESSAGES,\n ...(options.extraIgnoredMessages ?? []),\n ],\n payload: {\n // `service` identifies the app, `component` which half of it. Two fields rather than one\n // `blocks-os-client` string, so either can be filtered on without parsing.\n service: options.service,\n component: \"client\",\n client: {\n javascript: {\n source_map_enabled: Boolean(options.codeVersion),\n code_version: options.codeVersion,\n },\n },\n },\n };\n};\n","import Rollbar from \"rollbar\";\nimport {\n createRollbarConfig,\n type RollbarConfigOptions,\n} from \"./rollbar.config\";\n\nlet instance: Rollbar | undefined;\n\n/**\n * The one Rollbar instance for the app.\n *\n * Memoised on first call so that code outside the React tree -- an `HttpClient` built at module\n * scope, for instance -- reports through the same client the provider renders. A second instance\n * would install a second set of window handlers and split the telemetry buffer in two.\n *\n * First call wins: later calls return the existing instance and ignore their options. In practice\n * every call site passes the same service, and load order between a module-scope client and the\n * provider is not something an app should have to reason about.\n *\n * Created lazily, so merely importing this module installs nothing.\n */\nexport const getRollbar = (options: RollbarConfigOptions): Rollbar =>\n (instance ??= new Rollbar(createRollbarConfig(options)));\n","import type { QueryClient } from \"@tanstack/react-query\";\nimport type Rollbar from \"rollbar\";\nimport { HttpError } from \"@/lib/http/error\";\n\n/**\n * Reports errors thrown inside query and mutation functions that are not request failures.\n *\n * Narrow on purpose. Every failure from `HttpClient` arrives as an `HttpError` and is skipped here:\n * transport failures are already handled by `createHttpFailureReporter`, and HTTP statuses are\n * either business outcomes or faults the server reported itself. What remains is a genuine bug in a\n * query function -- a bad mapping, a null dereference on a response -- which React Query catches\n * and stores as query state, so it never reaches `window.onerror` and would otherwise be invisible.\n *\n * Returns an unsubscribe function.\n */\nexport const attachQueryErrorReporting = (\n queryClient: QueryClient,\n rollbar: Rollbar,\n): (() => void) => {\n const report = (error: unknown, context: Record<string, unknown>) => {\n if (error instanceof HttpError) return;\n // Belt and braces: an HttpError that crossed a module boundary may fail `instanceof`.\n if (typeof (error as { status?: unknown })?.status === \"number\") return;\n\n rollbar.error(error instanceof Error ? error : new Error(String(error)), {\n source: \"react-query\",\n ...context,\n });\n };\n\n const unsubscribeQueries = queryClient.getQueryCache().subscribe((event) => {\n if (event.type !== \"updated\" || event.action.type !== \"error\") return;\n\n report(event.action.error, {\n kind: \"query\",\n queryHash: event.query.queryHash,\n });\n });\n\n const unsubscribeMutations = queryClient\n .getMutationCache()\n .subscribe((event) => {\n if (event.type !== \"updated\" || event.action.type !== \"error\") return;\n\n report(event.action.error, {\n kind: \"mutation\",\n mutationKey: event.mutation.options.mutationKey,\n });\n });\n\n return () => {\n unsubscribeQueries();\n unsubscribeMutations();\n };\n};\n","import { ErrorBoundary, Provider } from \"@rollbar/react\";\nimport { useEffect, useMemo, type ComponentType, type ReactNode } from \"react\";\nimport { getQueryClient } from \"@/providers/query-client\";\nimport { attachQueryErrorReporting } from \"./report-query-errors\";\nimport { type RollbarConfigOptions } from \"./rollbar.config\";\nimport { getRollbar } from \"./rollbar.instance\";\n\nexport interface RollbarFallbackProps {\n error: Error | null;\n resetError: () => void;\n}\n\n/**\n * Shown instead of a blank page when a render throws. Deliberately plain: it has to render when the\n * app's own state is already known-bad, so it depends on nothing but theme tokens.\n */\nconst DefaultFallback = ({ resetError }: RollbarFallbackProps) => (\n <div\n className=\"flex min-h-screen flex-col items-center justify-center gap-4 bg-background px-6 text-center\"\n role=\"alert\"\n >\n <div className=\"space-y-1\">\n <p className=\"text-lg font-semibold text-foreground\">\n Something went wrong\n </p>\n <p className=\"text-sm text-medium-emphasis\">\n The error has been reported. Try again, or reload the page if it keeps\n happening.\n </p>\n </div>\n <button\n onClick={resetError}\n className=\"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground\"\n >\n Try again\n </button>\n </div>\n);\n\nexport interface RollbarProviderProps extends RollbarConfigOptions {\n children: ReactNode;\n /** Replaces the built-in crash screen. */\n fallback?: ComponentType<RollbarFallbackProps>;\n}\n\n/**\n * Puts Rollbar in front of the whole tree.\n *\n * Mount this outermost -- above the query, theme and router providers -- so a throw during their\n * own setup is still caught and reported rather than blanking the page.\n *\n * Reporting is inert until a client token is seeded (see `createRollbarConfig`), but the boundary is\n * always live, so the crash screen behaves identically in local development and in production.\n *\n * Covers uncaught errors, unhandled rejections, render crashes, and bugs thrown inside query\n * functions. Request failures are not covered here: pass `createHttpFailureReporter` to your\n * `HttpClient` as `onError` for those.\n */\nexport const RollbarProvider = ({\n children,\n fallback = DefaultFallback,\n ...configOptions\n}: RollbarProviderProps) => {\n // Shared with anything reporting from outside the tree, and stable for the life of the app:\n // reconstructing it on re-render would reinstall the window handlers and drop Rollbar's own\n // telemetry buffer.\n const rollbar = useMemo(\n () => getRollbar(configOptions),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n useEffect(\n () => attachQueryErrorReporting(getQueryClient(), rollbar),\n [rollbar],\n );\n\n return (\n <Provider instance={rollbar}>\n <ErrorBoundary fallbackUI={fallback} level=\"critical\">\n {children}\n </ErrorBoundary>\n </Provider>\n );\n};\n","import type Rollbar from \"rollbar\";\nimport type { HttpRequestFailure } from \"@/lib/http/types\";\n\n/**\n * Builds an `onError` handler for `HttpClientConfig` that reports only transport failures.\n *\n * Failures that produced an HTTP response are skipped deliberately: a 4xx is a business outcome the\n * UI already surfaces, and a 5xx has already been reported by the server with a real stack trace,\n * so reporting it again from the browser only buries the better item. What is left -- the API\n * unreachable, DNS, CORS, TLS, offline -- the server cannot report by definition, because it never\n * received the request.\n *\n * `HttpClient` normalises every failure to an `HttpError` with status 500 before callers see it, so\n * this distinction only exists inside the `onError` hook. Reporting from a `catch` further out\n * cannot tell the two apart.\n */\nexport const createHttpFailureReporter =\n (rollbar: Rollbar) =>\n (failure: HttpRequestFailure): void => {\n if (!failure.transport) return;\n\n const error =\n failure.error instanceof Error\n ? failure.error\n : new Error(String(failure.error));\n\n rollbar.error(error, {\n source: \"http-client\",\n url: failure.url,\n method: failure.method,\n });\n };\n"]}
|