{"version":3,"file":"pages-plugin.js","sources":["../../src/pages-plugin.ts"],"sourcesContent":["import { setAsyncLocalStorageAsyncContextStrategy } from './async';\nimport type { CloudflareOptions } from './client';\nimport { wrapRequestHandler } from './request';\n\n/**\n * Plugin middleware for Cloudflare Pages.\n *\n * Initializes the SDK and wraps cloudflare pages requests with SDK instrumentation.\n *\n * @example Simple usage\n *\n * ```javascript\n * // functions/_middleware.js\n * import * as Sentry from '@sentry/cloudflare';\n *\n * export const onRequest = Sentry.sentryPagesPlugin({\n * dsn: process.env.SENTRY_DSN,\n * tracesSampleRate: 1.0,\n * });\n * ```\n *\n * @example Usage with handler function to access context for environmental variables\n *\n * ```javascript\n * import * as Sentry from '@sentry/cloudflare';\n *\n * const const onRequest = Sentry.sentryPagesPlugin((context) => ({\n * dsn: context.env.SENTRY_DSN,\n * tracesSampleRate: 1.0,\n * })\n * ```\n *\n * @param handlerOrOptions Configuration options or a function that returns configuration options.\n * @returns A plugin function that can be used in Cloudflare Pages.\n */\nexport function sentryPagesPlugin<\n Env = unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Params extends string = any,\n Data extends Record = Record,\n // Although it is not ideal to use `any` here, it makes usage more flexible for different setups.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n PluginParams = any,\n>(\n handlerOrOptions:\n | CloudflareOptions\n | ((context: EventPluginContext) => CloudflareOptions),\n): PagesPluginFunction {\n setAsyncLocalStorageAsyncContextStrategy();\n return context => {\n if (context.request.method === 'OPTIONS' || context.request.method === 'HEAD') {\n return context.next();\n }\n\n const options = typeof handlerOrOptions === 'function' ? handlerOrOptions(context) : handlerOrOptions;\n return wrapRequestHandler({ options, request: context.request, context: { ...context, props: {} } }, () =>\n context.next(),\n );\n };\n}\n"],"names":[],"mappings":";;;AAmCO,SAAS,kBASd,gBAAA,EAGsD;AACtD,EAAA,wCAAA,EAAyC;AACzC,EAAA,OAAO,CAAA,OAAA,KAAW;AAChB,IAAA,IAAI,QAAQ,OAAA,CAAQ,MAAA,KAAW,aAAa,OAAA,CAAQ,OAAA,CAAQ,WAAW,MAAA,EAAQ;AAC7E,MAAA,OAAO,QAAQ,IAAA,EAAK;AAAA,IACtB;AAEA,IAAA,MAAM,UAAU,OAAO,gBAAA,KAAqB,UAAA,GAAa,gBAAA,CAAiB,OAAO,CAAA,GAAI,gBAAA;AACrF,IAAA,OAAO,kBAAA;AAAA,MAAmB,EAAE,OAAA,EAAS,OAAA,EAAS,OAAA,CAAQ,OAAA,EAAS,OAAA,EAAS,EAAE,GAAG,OAAA,EAAS,KAAA,EAAO,EAAC,EAAE,EAAE;AAAA,MAAG,MACnG,QAAQ,IAAA;AAAK,KACf;AAAA,EACF,CAAA;AACF;;;;"}