{"version":3,"file":"index.worker.mjs","names":["CacheFirst","ExpirationPlugin","NetworkFirst","NetworkOnly","RangeRequestsPlugin","StaleWhileRevalidate","PAGES_CACHE_NAME","rscPrefetch","rsc","html","defaultCache","process","env","NODE_ENV","matcher","handler","cacheName","plugins","maxEntries","maxAgeSeconds","maxAgeFrom","networkTimeoutSeconds","sameOrigin","url","pathname","startsWith","method","request","headers","get","includes"],"sources":["../src/index.worker.ts"],"sourcesContent":["import type { RuntimeCaching } from \"serwist\";\nimport { CacheFirst, ExpirationPlugin, NetworkFirst, NetworkOnly, RangeRequestsPlugin, StaleWhileRevalidate } from \"serwist\";\n\nexport const PAGES_CACHE_NAME = {\n  rscPrefetch: \"pages-rsc-prefetch\",\n  rsc: \"pages-rsc\",\n  html: \"pages\",\n} as const;\n\n/**\n * The default, recommended list of caching strategies for applications\n * built with Next.js.\n *\n * @see https://serwist.pages.dev/docs/next/worker-exports#default-cache\n */\nexport const defaultCache: RuntimeCaching[] =\n  process.env.NODE_ENV !== \"production\"\n    ? [\n        {\n          matcher: /.*/i,\n          handler: new NetworkOnly(),\n        },\n      ]\n    : [\n        {\n          matcher: /^https:\\/\\/fonts\\.(?:gstatic)\\.com\\/.*/i,\n          handler: new CacheFirst({\n            cacheName: \"google-fonts-webfonts\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 4,\n                maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days\n                maxAgeFrom: \"last-used\",\n              }),\n            ],\n          }),\n        },\n        {\n          matcher: /^https:\\/\\/fonts\\.(?:googleapis)\\.com\\/.*/i,\n          handler: new StaleWhileRevalidate({\n            cacheName: \"google-fonts-stylesheets\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 4,\n                maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days\n                maxAgeFrom: \"last-used\",\n              }),\n            ],\n          }),\n        },\n        {\n          matcher: /\\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,\n          handler: new StaleWhileRevalidate({\n            cacheName: \"static-font-assets\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 4,\n                maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days\n                maxAgeFrom: \"last-used\",\n              }),\n            ],\n          }),\n        },\n        {\n          matcher: /\\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,\n          handler: new StaleWhileRevalidate({\n            cacheName: \"static-image-assets\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 64,\n                maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days\n                maxAgeFrom: \"last-used\",\n              }),\n            ],\n          }),\n        },\n        {\n          matcher: /\\/_next\\/static.+\\.js$/i,\n          handler: new CacheFirst({\n            cacheName: \"next-static-js-assets\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 64,\n                maxAgeSeconds: 24 * 60 * 60, // 24 hours\n                maxAgeFrom: \"last-used\",\n              }),\n            ],\n          }),\n        },\n        {\n          matcher: /\\/_next\\/image\\?url=.+$/i,\n          handler: new StaleWhileRevalidate({\n            cacheName: \"next-image\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 64,\n                maxAgeSeconds: 24 * 60 * 60, // 24 hours\n                maxAgeFrom: \"last-used\",\n              }),\n            ],\n          }),\n        },\n        {\n          matcher: /\\.(?:mp3|wav|ogg)$/i,\n          handler: new CacheFirst({\n            cacheName: \"static-audio-assets\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 32,\n                maxAgeSeconds: 24 * 60 * 60, // 24 hours\n                maxAgeFrom: \"last-used\",\n              }),\n              new RangeRequestsPlugin(),\n            ],\n          }),\n        },\n        {\n          matcher: /\\.(?:mp4|webm)$/i,\n          handler: new CacheFirst({\n            cacheName: \"static-video-assets\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 32,\n                maxAgeSeconds: 24 * 60 * 60, // 24 hours\n                maxAgeFrom: \"last-used\",\n              }),\n              new RangeRequestsPlugin(),\n            ],\n          }),\n        },\n        {\n          matcher: /\\.(?:js)$/i,\n          handler: new StaleWhileRevalidate({\n            cacheName: \"static-js-assets\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 48,\n                maxAgeSeconds: 24 * 60 * 60, // 24 hours\n                maxAgeFrom: \"last-used\",\n              }),\n            ],\n          }),\n        },\n        {\n          matcher: /\\.(?:css|less)$/i,\n          handler: new StaleWhileRevalidate({\n            cacheName: \"static-style-assets\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 32,\n                maxAgeSeconds: 24 * 60 * 60, // 24 hours\n                maxAgeFrom: \"last-used\",\n              }),\n            ],\n          }),\n        },\n        {\n          matcher: /\\/_next\\/data\\/.+\\/.+\\.json$/i,\n          handler: new NetworkFirst({\n            cacheName: \"next-data\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 32,\n                maxAgeSeconds: 24 * 60 * 60, // 24 hours\n                maxAgeFrom: \"last-used\",\n              }),\n            ],\n          }),\n        },\n        {\n          matcher: /\\.(?:json|xml|csv)$/i,\n          handler: new NetworkFirst({\n            cacheName: \"static-data-assets\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 32,\n                maxAgeSeconds: 24 * 60 * 60, // 24 hours\n                maxAgeFrom: \"last-used\",\n              }),\n            ],\n          }),\n        },\n        {\n          // Exclude /api/auth/* to fix auth callback\n          // https://github.com/serwist/serwist/discussions/28\n          matcher: /\\/api\\/auth\\/.*/,\n          handler: new NetworkOnly({\n            networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds\n          }),\n        },\n        {\n          matcher: ({ sameOrigin, url: { pathname } }) => sameOrigin && pathname.startsWith(\"/api/\"),\n          method: \"GET\",\n          handler: new NetworkFirst({\n            cacheName: \"apis\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 16,\n                maxAgeSeconds: 24 * 60 * 60, // 24 hours\n                maxAgeFrom: \"last-used\",\n              }),\n            ],\n            networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds\n          }),\n        },\n        {\n          matcher: ({ request, url: { pathname }, sameOrigin }) =>\n            request.headers.get(\"RSC\") === \"1\" && request.headers.get(\"Next-Router-Prefetch\") === \"1\" && sameOrigin && !pathname.startsWith(\"/api/\"),\n          handler: new NetworkFirst({\n            cacheName: PAGES_CACHE_NAME.rscPrefetch,\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 32,\n                maxAgeSeconds: 24 * 60 * 60, // 24 hours\n              }),\n            ],\n          }),\n        },\n        {\n          matcher: ({ request, url: { pathname }, sameOrigin }) => request.headers.get(\"RSC\") === \"1\" && sameOrigin && !pathname.startsWith(\"/api/\"),\n          handler: new NetworkFirst({\n            cacheName: PAGES_CACHE_NAME.rsc,\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 32,\n                maxAgeSeconds: 24 * 60 * 60, // 24 hours\n              }),\n            ],\n          }),\n        },\n        {\n          matcher: ({ request, url: { pathname }, sameOrigin }) =>\n            request.headers.get(\"Content-Type\")?.includes(\"text/html\") && sameOrigin && !pathname.startsWith(\"/api/\"),\n          handler: new NetworkFirst({\n            cacheName: PAGES_CACHE_NAME.html,\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 32,\n                maxAgeSeconds: 24 * 60 * 60, // 24 hours\n              }),\n            ],\n          }),\n        },\n        {\n          matcher: ({ url: { pathname }, sameOrigin }) => sameOrigin && !pathname.startsWith(\"/api/\"),\n          handler: new NetworkFirst({\n            cacheName: \"others\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 32,\n                maxAgeSeconds: 24 * 60 * 60, // 24 hours\n              }),\n            ],\n          }),\n        },\n        {\n          matcher: ({ sameOrigin }) => !sameOrigin,\n          handler: new NetworkFirst({\n            cacheName: \"cross-origin\",\n            plugins: [\n              new ExpirationPlugin({\n                maxEntries: 32,\n                maxAgeSeconds: 60 * 60, // 1 hour\n              }),\n            ],\n            networkTimeoutSeconds: 10,\n          }),\n        },\n        {\n          matcher: /.*/i,\n          method: \"GET\",\n          handler: new NetworkOnly(),\n        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