@carlonicora/nextjs-jsonapi 4.0.8 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/{BlockNoteEditor-MCYQBKT5.js → BlockNoteEditor-6CBMNJPU.js} +9 -9
  2. package/dist/{BlockNoteEditor-MCYQBKT5.js.map → BlockNoteEditor-6CBMNJPU.js.map} +1 -1
  3. package/dist/{BlockNoteEditor-A2E4VUYB.mjs → BlockNoteEditor-7N66JABP.mjs} +2 -2
  4. package/dist/billing/index.js +335 -335
  5. package/dist/billing/index.mjs +1 -1
  6. package/dist/{chunk-DJRTJBSZ.mjs → chunk-HQKTQBUC.mjs} +15 -4
  7. package/dist/chunk-HQKTQBUC.mjs.map +1 -0
  8. package/dist/{chunk-PL2FHXHR.js → chunk-MJVEKDM4.js} +246 -235
  9. package/dist/chunk-MJVEKDM4.js.map +1 -0
  10. package/dist/client/index.js +2 -2
  11. package/dist/client/index.mjs +1 -1
  12. package/dist/components/index.js +2 -2
  13. package/dist/components/index.mjs +1 -1
  14. package/dist/contexts/index.js +2 -2
  15. package/dist/contexts/index.mjs +1 -1
  16. package/dist/features/analytics/index.js +88 -88
  17. package/dist/features/analytics/index.mjs +1 -1
  18. package/dist/features/help/index.js +31 -31
  19. package/dist/features/help/index.mjs +1 -1
  20. package/dist/features/tokenusage/index.js +75 -75
  21. package/dist/features/tokenusage/index.mjs +1 -1
  22. package/dist/next-config/index.d.mts +8 -1
  23. package/dist/next-config/index.d.ts +8 -1
  24. package/dist/next-config/index.js +31 -9
  25. package/dist/next-config/index.js.map +1 -1
  26. package/dist/next-config/index.mjs +31 -9
  27. package/dist/next-config/index.mjs.map +1 -1
  28. package/package.json +1 -1
  29. package/src/features/company/components/details/CompanyContent.tsx +9 -2
  30. package/src/features/company/components/forms/CompanyEditor.tsx +2 -0
  31. package/src/next-config/__tests__/createNextConfig.test.ts +45 -3
  32. package/src/next-config/csp.ts +25 -4
  33. package/src/next-config/index.ts +19 -12
  34. package/dist/chunk-DJRTJBSZ.mjs.map +0 -1
  35. package/dist/chunk-PL2FHXHR.js.map +0 -1
  36. /package/dist/{BlockNoteEditor-A2E4VUYB.mjs.map → BlockNoteEditor-7N66JABP.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/next-config/index.js","../../src/next-config/csp.ts","../../src/next-config/headers.ts","../../src/next-config/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,uDAA6B;AAC7B;AACA;ACoBA,IAAM,gBAAA,EAA+E;AAAA,EACnF,MAAA,EAAQ;AAAA,IACN,YAAA,EAAc,CAAC,uBAAuB,CAAA;AAAA,IACtC,SAAA,EAAW,CAAC,sBAAsB,CAAA;AAAA,IAClC,aAAA,EAAe,CAAC,wBAAwB,CAAA;AAAA,IACxC,WAAA,EAAa,CAAC,uBAAA,EAAyB,0BAA0B;AAAA,EACnE,CAAA;AAAA,EACA,UAAA,EAAY;AAAA,IACV,YAAA,EAAc,CAAC,6BAA6B,CAAA;AAAA,IAC5C,SAAA,EAAW,CAAC,6BAAA,EAA+B,0BAA0B,CAAA;AAAA,IACrE,aAAA,EAAe,CAAC,6BAAA,EAA+B,+BAA+B;AAAA,EAChF,CAAA;AAAA,EACA,SAAA,EAAW;AAAA,IACT,YAAA,EAAc,CAAC,mCAAmC,CAAA;AAAA,IAClD,aAAA,EAAe,CAAC,mCAAmC,CAAA;AAAA,IACnD,WAAA,EAAa,CAAC,mCAAmC;AAAA,EACnD,CAAA;AAAA,EACA,OAAA,EAAS;AAAA,IACP,SAAA,EAAW,CAAC,4BAA4B;AAAA,EAC1C,CAAA;AAAA,EACA,WAAA,EAAa;AAAA,IACX,WAAA,EAAa,CAAC,8BAA8B,CAAA;AAAA,IAC5C,UAAA,EAAY,CAAC,2BAA2B;AAAA,EAC1C;AACF,CAAA;AAEA,SAAS,gBAAA,CAAiB,GAAA,EAAk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AA,GAAA,CAAI,OAAA,CAAQ,gBAAA,IAAoB,KAAA,EAAO;AACrC,IAAA,MAAA,CAAO,QAAA,EAAU,MAAA,CAAA,EAAA,GAAY,oBAAA,CAAqB,OAAA,EAAS,OAAA,CAAQ,GAAG,CAAA;AAAA,EACxE;AAEA,EAAA,GAAA,CAAI,OAAA,CAAQ,QAAA,EAAU,MAAA,CAAO,SAAA,EAAW,OAAA,CAAQ,QAAA;AAEhD,EAAA,OAAO,OAAA,CAAQ,OAAA,EAAS,OAAA,CAAQ,MAAA,CAAO,MAAM,EAAA,EAAI,MAAA;AACnD;AArEgB,qCAAA,gBAAA,EAAA,kBAAA,CAAA;AHqLhB;AACE;AACA;AACF,yEAAC","file":"/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/next-config/index.js","sourcesContent":[null,"// Runtime imports: none. next.config.js loads this at RUNTIME under `next start`\n// in an image installed with --prod, so it may import only Node built-ins.\n\nexport type CspDirective =\n \"script-src\" | \"style-src\" | \"img-src\" | \"font-src\" | \"connect-src\" | \"frame-src\" | \"worker-src\";\n\n/**\n * Third-party services an app may load. Each one adds its hosts to the\n * directives it needs; nothing is allowed unless the app names it.\n *\n * - `stripe`: the billing feature (`@carlonicora/nextjs-jsonapi/billing`).\n * - `googleMaps`: `FormPlaceAutocomplete` (Places API) and Maps JS/static tiles.\n * - `turnstile`: Cloudflare Turnstile widgets (contact and waitlist forms).\n * - `discord`: Discord avatars shown for users who log in with Discord.\n * - `googleFonts`: fonts linked at runtime from Google Fonts. Not needed for\n * `next/font/google`, which self-hosts at build time.\n */\nexport type CspService = \"stripe\" | \"googleMaps\" | \"turnstile\" | \"discord\" | \"googleFonts\";\n\nexport interface CspOptions {\n services?: CspService[];\n csp?: Partial<Record<CspDirective, string[]>>;\n}\n\nconst SERVICE_SOURCES: Record<CspService, Partial<Record<CspDirective, string[]>>> = {\n stripe: {\n \"script-src\": [\"https://js.stripe.com\"],\n \"img-src\": [\"https://*.stripe.com\"],\n \"connect-src\": [\"https://api.stripe.com\"],\n \"frame-src\": [\"https://js.stripe.com\", \"https://hooks.stripe.com\"],\n },\n googleMaps: {\n \"script-src\": [\"https://maps.googleapis.com\"],\n \"img-src\": [\"https://maps.googleapis.com\", \"https://maps.gstatic.com\"],\n \"connect-src\": [\"https://maps.googleapis.com\", \"https://places.googleapis.com\"],\n },\n turnstile: {\n \"script-src\": [\"https://challenges.cloudflare.com\"],\n \"connect-src\": [\"https://challenges.cloudflare.com\"],\n \"frame-src\": [\"https://challenges.cloudflare.com\"],\n },\n discord: {\n \"img-src\": [\"https://cdn.discordapp.com\"],\n },\n googleFonts: {\n \"style-src\": [\"https://fonts.googleapis.com\"],\n \"font-src\": [\"https://fonts.gstatic.com\"],\n },\n};\n\nfunction listImageSources(env: NodeJS.ProcessEnv): string[] {\n return env.IMAGE_SOURCES ? env.IMAGE_SOURCES.split(\",\").map((s) => s.trim()) : [];\n}\n\n// Build CSP directives\n// Note: 'unsafe-inline' and 'unsafe-eval' needed for Next.js dev mode and some runtime features\n// In production, consider using nonces for stricter CSP\nexport function buildCsp(options: CspOptions, env: NodeJS.ProcessEnv): string {\n const apiUrl = env.NEXT_PUBLIC_API_URL || \"\";\n const imageSources = listImageSources(env);\n const services = options.services ?? [];\n\n // Each fetch directive: what Next itself needs, then the named services, then\n // the app's extras, then the sources derived from the env.\n const fetchDirectives: Record<CspDirective, { base: string[]; fromEnv: string[] }> = {\n // Scripts: self, and unsafe-inline/eval for Next.js\n \"script-src\": { base: [\"'self'\", \"'unsafe-inline'\", \"'unsafe-eval'\"], fromEnv: [] },\n // Styles: self and unsafe-inline for styled-components/emotion\n \"style-src\": { base: [\"'self'\", \"'unsafe-inline'\"], fromEnv: [] },\n // Images: self, data URIs, blobs, and configured image sources\n \"img-src\": { base: [\"'self'\", \"data:\", \"blob:\"], fromEnv: imageSources },\n // Fonts: self\n \"font-src\": { base: [\"'self'\"], fromEnv: [] },\n // Connect: self, API (http + ws for socket.io), and storage (for uploads)\n \"connect-src\": {\n base: [\"'self'\"],\n fromEnv: [\n apiUrl,\n // Add WebSocket URL for socket.io (convert http->ws, https->wss)\n apiUrl.replace(/^http/, \"ws\"),\n env.NEXT_PUBLIC_ADDRESS || \"\",\n ...imageSources,\n ],\n },\n // Frames: self\n \"frame-src\": { base: [\"'self'\"], fromEnv: [] },\n // Worker sources: self and blob (for Web Workers with dynamic imports)\n \"worker-src\": { base: [\"'self'\", \"blob:\"], fromEnv: [] },\n };\n\n const directive = (name: CspDirective): string => {\n const { base, fromEnv } = fetchDirectives[name];\n const fromServices = services.flatMap((service) => SERVICE_SOURCES[service][name] ?? []);\n const sources = [...base, ...fromServices, ...(options.csp?.[name] ?? []), ...fromEnv].filter(\n (source) => source !== \"\",\n );\n return [name, ...new Set(sources)].join(\" \");\n };\n\n return [\n \"default-src 'self'\",\n directive(\"script-src\"),\n directive(\"style-src\"),\n directive(\"img-src\"),\n directive(\"font-src\"),\n directive(\"connect-src\"),\n directive(\"frame-src\"),\n // Frame ancestors: deny embedding (equivalent to X-Frame-Options: DENY)\n \"frame-ancestors 'none'\",\n // Form actions: only self\n \"form-action 'self'\",\n // Base URI: only self\n \"base-uri 'self'\",\n // Object sources: none (no plugins)\n \"object-src 'none'\",\n directive(\"worker-src\"),\n // Upgrade insecure requests in production.\n //\n // NOT under E2E_BUILD: the e2e harness runs a PRODUCTION build (for speed)\n // and serves it over plain http on a custom hostname. With this directive\n // the browser rewrites every /_next/static asset to https, which nothing is\n // listening on — every chunk fails with ERR_SSL_PROTOCOL_ERROR, the page\n // never hydrates, and each spec sees only server-rendered markup.\n env.NODE_ENV === \"production\" && env.E2E_BUILD !== \"true\" ? \"upgrade-insecure-requests\" : \"\",\n ]\n .filter(Boolean)\n .join(\"; \");\n}\n","// Runtime imports: relative only. See csp.ts.\nimport { buildCsp, type CspOptions } from \"./csp\";\n\nexport interface SecurityHeaderOptions extends CspOptions {\n permissionsPolicy?: { camera?: \"none\" | \"self\" };\n}\n\nexport interface HeaderRule {\n source: string;\n headers: { key: string; value: string }[];\n}\n\nexport function buildSecurityHeaders(options: SecurityHeaderOptions, env: NodeJS.ProcessEnv): HeaderRule[] {\n const camera = options.permissionsPolicy?.camera === \"none\" ? \"\" : \"self\";\n\n return [\n {\n // Apply to all routes\n source: \"/:path*\",\n headers: [\n // Content Security Policy - prevents XSS attacks\n {\n key: \"Content-Security-Policy\",\n value: buildCsp(options, env),\n },\n // X-Frame-Options - prevents clickjacking (backup for older browsers)\n {\n key: \"X-Frame-Options\",\n value: \"DENY\",\n },\n // X-Content-Type-Options - prevents MIME sniffing\n {\n key: \"X-Content-Type-Options\",\n value: \"nosniff\",\n },\n // Strict-Transport-Security - enforces HTTPS (1 year, include subdomains).\n // Omitted under E2E_BUILD for the same reason as upgrade-insecure-requests:\n // the suite speaks plain http, and an HSTS pin would force https on every\n // later request to this host from the same browser profile.\n ...(env.E2E_BUILD === \"true\"\n ? []\n : [\n {\n key: \"Strict-Transport-Security\",\n value: \"max-age=31536000; includeSubDomains\",\n },\n ]),\n // Referrer-Policy - controls referrer information\n {\n key: \"Referrer-Policy\",\n value: \"strict-origin-when-cross-origin\",\n },\n // Permissions-Policy - restricts browser features\n {\n key: \"Permissions-Policy\",\n value: `camera=(${camera}), microphone=(), geolocation=()`,\n },\n ],\n },\n ];\n}\n","// Shared next.config for the nja fleet. Apps wrap the result with their own\n// plugins: `withNextIntl(withMDX(createNextConfig({...})))`.\n//\n// next.config.js is loaded at RUNTIME by `next start`, and the production image\n// installs with --prod. This entry may therefore import only Node built-ins at\n// runtime: never next-intl, @next/mdx, serwist or any devDependency. `next` is\n// imported for its types only.\nimport type { NextConfig } from \"next\";\nimport { buildCsp, type CspDirective, type CspService } from \"./csp\";\nimport { buildSecurityHeaders } from \"./headers\";\n\nexport { buildCsp };\nexport type { CspDirective, CspService };\n\nexport interface NjaNextConfigOptions {\n devOrigins: string[];\n /** Third-party services the app loads; each adds its own hosts to the CSP. Nothing is allowed by default. */\n services?: CspService[];\n /** Extra CSP sources per directive, for hosts no named service covers. */\n csp?: Partial<Record<CspDirective, string[]>>;\n env?: Record<string, string>;\n imageMinimumCacheTTL?: number;\n permissionsPolicy?: { camera?: \"none\" | \"self\" };\n mdx?: boolean;\n serwist?: boolean;\n securityHeaders?: boolean;\n authInterrupts?: boolean;\n reactCompiler?: boolean;\n rewrites?: NextConfig[\"rewrites\"];\n extend?: (config: NextConfig) => NextConfig;\n}\n\ntype RemotePattern = { protocol: \"http\" | \"https\"; hostname: string; port?: string };\n\nfunction parseImageSources(env: NodeJS.ProcessEnv): RemotePattern[] {\n return env.IMAGE_SOURCES\n ? env.IMAGE_SOURCES.split(\",\").map((url) => {\n const { hostname, protocol, port } = new URL(url.trim());\n return {\n protocol: protocol.replace(\":\", \"\") as RemotePattern[\"protocol\"],\n hostname,\n port: port || undefined,\n };\n })\n : [];\n}\n\nexport function createNextConfig(options: NjaNextConfigOptions): NextConfig {\n const env = process.env;\n const reactCompiler = options.reactCompiler === true;\n\n const config: NextConfig = {\n // The e2e stack (scripts/e2e.sh) runs a PRODUCTION build of this app while a\n // `next dev` server may still be running against the same worktree. `next\n // build` and `next dev` share `.next`, so a build performed underneath a live\n // dev server clobbers it and that dev server then 404s every route. Giving\n // the e2e build its own directory keeps the two independent. E2E_BUILD must\n // be set for `next build` AND for `next start`, or `start` looks in `.next`\n // and serves someone else's output.\n ...(env.E2E_BUILD === \"true\" ? { distDir: \".next-e2e\" } : {}),\n cacheComponents: true,\n partialPrefetching: true,\n reactCompiler,\n experimental: {\n serverActions: {\n bodySizeLimit: \"5mb\",\n },\n // Required by `unauthorized()` (next/navigation): without this flag it throws a plain\n // Error instead of rendering the nearest unauthorized.tsx. The flag is for app code that\n // calls it; ServerSession.checkPermission does not, it still does `redirect(\"/401\")`.\n authInterrupts: options.authInterrupts ?? true,\n turbopackGc: true,\n // No turbopackLazyDynamicImports: in `next dev` it leaves this package's lazily\n // imported request module unactivated (\"Lazily compiled dynamic import of ...\n // JsonApiRequest ... was not activated\"), so every client-side read returns\n // nothing. Seen with the package installed from npm; production builds are unaffected.\n ...(reactCompiler ? { turbopackRustReactCompiler: true } : {}),\n },\n allowedDevOrigins: options.devOrigins,\n pageExtensions: options.mdx ? [\"ts\", \"tsx\", \"mdx\"] : [\"ts\", \"tsx\"],\n images: {\n minimumCacheTTL: options.imageMinimumCacheTTL ?? 60,\n remotePatterns: parseImageSources(env),\n dangerouslyAllowLocalIP: true,\n },\n poweredByHeader: false,\n reactStrictMode: false,\n env: {\n NEXT_PUBLIC_API_URL: env.NEXT_PUBLIC_API_URL ?? \"\",\n NEXT_PUBLIC_ADDRESS: env.NEXT_PUBLIC_ADDRESS ?? \"\",\n NEXT_PUBLIC_VAPID_PUBLIC_KEY: env.NEXT_PUBLIC_VAPID_PUBLIC_KEY ?? \"\",\n NEXT_PUBLIC_GOOGLE_MAPS_API_KEY: env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY ?? \"\",\n ...options.env,\n },\n // Inlined replacement for @serwist/turbopack's withSerwist wrapper, which\n // does nothing but append these two entries. Requiring the package here\n // instead CRASHES production: it is a devDependency, next.config.js is loaded\n // at RUNTIME by `next start`, and the web-production image installs with\n // --prod. Do not re-add a require of any devDependency to this file.\n ...(options.serwist ? { serverExternalPackages: [\"esbuild\", \"esbuild-wasm\"] } : {}),\n // Next 16 builds AND serves dev with Turbopack, so this is what pins yjs to a\n // single instance in both modes.\n turbopack: {\n resolveAlias: {\n yjs: \"./node_modules/yjs\",\n },\n },\n };\n\n if (options.securityHeaders !== false) {\n config.headers = async () => buildSecurityHeaders(options, process.env);\n }\n\n if (options.rewrites) config.rewrites = options.rewrites;\n\n return options.extend ? options.extend(config) : config;\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/next-config/index.js","../../src/next-config/csp.ts","../../src/next-config/headers.ts","../../src/next-config/index.ts"],"names":[],"mappings":"AAAA;AACE;AACF,uDAA6B;AAC7B;AACA;ACoBA,IAAM,gBAAA,EAA+E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mMhB;AACE;AACA;AACA;AACF,kHAAC","file":"/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/next-config/index.js","sourcesContent":[null,"// Runtime imports: none. next.config.js loads this at RUNTIME under `next start`\n// in an image installed with --prod, so it may import only Node built-ins.\n\nexport type CspDirective =\n \"script-src\" | \"style-src\" | \"img-src\" | \"font-src\" | \"connect-src\" | \"frame-src\" | \"worker-src\";\n\n/**\n * Third-party services an app may load. Each one adds its hosts to the\n * directives it needs; nothing is allowed unless the app names it.\n *\n * - `stripe`: the billing feature (`@carlonicora/nextjs-jsonapi/billing`).\n * - `googleMaps`: `FormPlaceAutocomplete` (Places API) and Maps JS/static tiles.\n * - `turnstile`: Cloudflare Turnstile widgets (contact and waitlist forms).\n * - `discord`: Discord avatars shown for users who log in with Discord.\n * - `googleFonts`: fonts linked at runtime from Google Fonts. Not needed for\n * `next/font/google`, which self-hosts at build time.\n */\nexport type CspService = \"stripe\" | \"googleMaps\" | \"turnstile\" | \"discord\" | \"googleFonts\";\n\nexport interface CspOptions {\n services?: CspService[];\n csp?: Partial<Record<CspDirective, string[]>>;\n}\n\nconst SERVICE_SOURCES: Record<CspService, Partial<Record<CspDirective, string[]>>> = {\n stripe: {\n \"script-src\": [\"https://js.stripe.com\"],\n \"img-src\": [\"https://*.stripe.com\"],\n \"connect-src\": [\"https://api.stripe.com\"],\n \"frame-src\": [\"https://js.stripe.com\", \"https://hooks.stripe.com\"],\n },\n googleMaps: {\n \"script-src\": [\"https://maps.googleapis.com\"],\n \"img-src\": [\"https://maps.googleapis.com\", \"https://maps.gstatic.com\"],\n \"connect-src\": [\"https://maps.googleapis.com\", \"https://places.googleapis.com\"],\n },\n turnstile: {\n \"script-src\": [\"https://challenges.cloudflare.com\"],\n \"connect-src\": [\"https://challenges.cloudflare.com\"],\n \"frame-src\": [\"https://challenges.cloudflare.com\"],\n },\n discord: {\n \"img-src\": [\"https://cdn.discordapp.com\"],\n },\n googleFonts: {\n \"style-src\": [\"https://fonts.googleapis.com\"],\n \"font-src\": [\"https://fonts.gstatic.com\"],\n },\n};\n\nfunction listImageSources(env: NodeJS.ProcessEnv): string[] {\n return env.IMAGE_SOURCES ? env.IMAGE_SOURCES.split(\",\").map((s) => s.trim()) : [];\n}\n\n/**\n * Origins of the app's own servers, the API and the corpus, from\n * `NEXT_PUBLIC_API_URL` and `NEXT_PUBLIC_CORPUS_URL`. They serve every stored\n * object link, so images and frames must be allowed from them. Unset or invalid\n * URLs are skipped; the result has no duplicates.\n */\nexport function listAppOrigins(env: NodeJS.ProcessEnv): string[] {\n const origins: string[] = [];\n for (const url of [env.NEXT_PUBLIC_API_URL, env.NEXT_PUBLIC_CORPUS_URL]) {\n if (!url) continue;\n try {\n const { origin } = new URL(url.trim());\n if (origin !== \"null\" && !origins.includes(origin)) origins.push(origin);\n } catch {\n // Not a URL: nothing to allow.\n }\n }\n return origins;\n}\n\n// Build CSP directives\n// Note: 'unsafe-inline' and 'unsafe-eval' needed for Next.js dev mode and some runtime features\n// In production, consider using nonces for stricter CSP\nexport function buildCsp(options: CspOptions, env: NodeJS.ProcessEnv): string {\n const apiUrl = env.NEXT_PUBLIC_API_URL || \"\";\n const imageSources = listImageSources(env);\n const appOrigins = listAppOrigins(env);\n const services = options.services ?? [];\n\n // Each fetch directive: what Next itself needs, then the named services, then\n // the app's extras, then the sources derived from the env.\n const fetchDirectives: Record<CspDirective, { base: string[]; fromEnv: string[] }> = {\n // Scripts: self, and unsafe-inline/eval for Next.js\n \"script-src\": { base: [\"'self'\", \"'unsafe-inline'\", \"'unsafe-eval'\"], fromEnv: [] },\n // Styles: self and unsafe-inline for styled-components/emotion\n \"style-src\": { base: [\"'self'\", \"'unsafe-inline'\"], fromEnv: [] },\n // Images: self, data URIs, blobs, configured image sources, and the api/corpus origins\n \"img-src\": { base: [\"'self'\", \"data:\", \"blob:\"], fromEnv: [...imageSources, ...appOrigins] },\n // Fonts: self\n \"font-src\": { base: [\"'self'\"], fromEnv: [] },\n // Connect: self, API (http + ws for socket.io), and storage (for uploads)\n \"connect-src\": {\n base: [\"'self'\"],\n fromEnv: [\n apiUrl,\n // Add WebSocket URL for socket.io (convert http->ws, https->wss)\n apiUrl.replace(/^http/, \"ws\"),\n env.NEXT_PUBLIC_ADDRESS || \"\",\n ...imageSources,\n ],\n },\n // Frames: self, and the api/corpus origins (inline previews of stored objects)\n \"frame-src\": { base: [\"'self'\"], fromEnv: appOrigins },\n // Worker sources: self and blob (for Web Workers with dynamic imports)\n \"worker-src\": { base: [\"'self'\", \"blob:\"], fromEnv: [] },\n };\n\n const directive = (name: CspDirective): string => {\n const { base, fromEnv } = fetchDirectives[name];\n const fromServices = services.flatMap((service) => SERVICE_SOURCES[service][name] ?? []);\n const sources = [...base, ...fromServices, ...(options.csp?.[name] ?? []), ...fromEnv].filter(\n (source) => source !== \"\",\n );\n return [name, ...new Set(sources)].join(\" \");\n };\n\n return [\n \"default-src 'self'\",\n directive(\"script-src\"),\n directive(\"style-src\"),\n directive(\"img-src\"),\n directive(\"font-src\"),\n directive(\"connect-src\"),\n directive(\"frame-src\"),\n // Frame ancestors: deny embedding (equivalent to X-Frame-Options: DENY)\n \"frame-ancestors 'none'\",\n // Form actions: only self\n \"form-action 'self'\",\n // Base URI: only self\n \"base-uri 'self'\",\n // Object sources: none (no plugins)\n \"object-src 'none'\",\n directive(\"worker-src\"),\n // Upgrade insecure requests in production.\n //\n // NOT under E2E_BUILD: the e2e harness runs a PRODUCTION build (for speed)\n // and serves it over plain http on a custom hostname. With this directive\n // the browser rewrites every /_next/static asset to https, which nothing is\n // listening on — every chunk fails with ERR_SSL_PROTOCOL_ERROR, the page\n // never hydrates, and each spec sees only server-rendered markup.\n env.NODE_ENV === \"production\" && env.E2E_BUILD !== \"true\" ? \"upgrade-insecure-requests\" : \"\",\n ]\n .filter(Boolean)\n .join(\"; \");\n}\n","// Runtime imports: relative only. See csp.ts.\nimport { buildCsp, type CspOptions } from \"./csp\";\n\nexport interface SecurityHeaderOptions extends CspOptions {\n permissionsPolicy?: { camera?: \"none\" | \"self\" };\n}\n\nexport interface HeaderRule {\n source: string;\n headers: { key: string; value: string }[];\n}\n\nexport function buildSecurityHeaders(options: SecurityHeaderOptions, env: NodeJS.ProcessEnv): HeaderRule[] {\n const camera = options.permissionsPolicy?.camera === \"none\" ? \"\" : \"self\";\n\n return [\n {\n // Apply to all routes\n source: \"/:path*\",\n headers: [\n // Content Security Policy - prevents XSS attacks\n {\n key: \"Content-Security-Policy\",\n value: buildCsp(options, env),\n },\n // X-Frame-Options - prevents clickjacking (backup for older browsers)\n {\n key: \"X-Frame-Options\",\n value: \"DENY\",\n },\n // X-Content-Type-Options - prevents MIME sniffing\n {\n key: \"X-Content-Type-Options\",\n value: \"nosniff\",\n },\n // Strict-Transport-Security - enforces HTTPS (1 year, include subdomains).\n // Omitted under E2E_BUILD for the same reason as upgrade-insecure-requests:\n // the suite speaks plain http, and an HSTS pin would force https on every\n // later request to this host from the same browser profile.\n ...(env.E2E_BUILD === \"true\"\n ? []\n : [\n {\n key: \"Strict-Transport-Security\",\n value: \"max-age=31536000; includeSubDomains\",\n },\n ]),\n // Referrer-Policy - controls referrer information\n {\n key: \"Referrer-Policy\",\n value: \"strict-origin-when-cross-origin\",\n },\n // Permissions-Policy - restricts browser features\n {\n key: \"Permissions-Policy\",\n value: `camera=(${camera}), microphone=(), geolocation=()`,\n },\n ],\n },\n ];\n}\n","// Shared next.config for the nja fleet. Apps wrap the result with their own\n// plugins: `withNextIntl(withMDX(createNextConfig({...})))`.\n//\n// next.config.js is loaded at RUNTIME by `next start`, and the production image\n// installs with --prod. This entry may therefore import only Node built-ins at\n// runtime: never next-intl, @next/mdx, serwist or any devDependency. `next` is\n// imported for its types only.\nimport type { NextConfig } from \"next\";\nimport { buildCsp, listAppOrigins, type CspDirective, type CspService } from \"./csp\";\nimport { buildSecurityHeaders } from \"./headers\";\n\nexport { buildCsp, listAppOrigins };\nexport type { CspDirective, CspService };\n\nexport interface NjaNextConfigOptions {\n devOrigins: string[];\n /** Third-party services the app loads; each adds its own hosts to the CSP. Nothing is allowed by default. */\n services?: CspService[];\n /** Extra CSP sources per directive, for hosts no named service covers. */\n csp?: Partial<Record<CspDirective, string[]>>;\n env?: Record<string, string>;\n imageMinimumCacheTTL?: number;\n permissionsPolicy?: { camera?: \"none\" | \"self\" };\n mdx?: boolean;\n serwist?: boolean;\n securityHeaders?: boolean;\n authInterrupts?: boolean;\n reactCompiler?: boolean;\n rewrites?: NextConfig[\"rewrites\"];\n extend?: (config: NextConfig) => NextConfig;\n}\n\ntype RemotePattern = { protocol: \"http\" | \"https\"; hostname: string; port?: string };\n\n// IMAGE_SOURCES, then the api and corpus origins (they serve every stored object\n// link), without duplicates.\nfunction parseImageSources(env: NodeJS.ProcessEnv): RemotePattern[] {\n const imageSources = env.IMAGE_SOURCES ? env.IMAGE_SOURCES.split(\",\").map((url) => url.trim()) : [];\n const patterns: RemotePattern[] = [];\n for (const url of [...imageSources, ...listAppOrigins(env)]) {\n const { hostname, protocol, port } = new URL(url);\n const pattern: RemotePattern = {\n protocol: protocol.replace(\":\", \"\") as RemotePattern[\"protocol\"],\n hostname,\n port: port || undefined,\n };\n const seen = patterns.some(\n (p) => p.protocol === pattern.protocol && p.hostname === pattern.hostname && p.port === pattern.port,\n );\n if (!seen) patterns.push(pattern);\n }\n return patterns;\n}\n\nexport function createNextConfig(options: NjaNextConfigOptions): NextConfig {\n const env = process.env;\n const reactCompiler = options.reactCompiler === true;\n\n const config: NextConfig = {\n // The e2e stack (scripts/e2e.sh) runs a PRODUCTION build of this app while a\n // `next dev` server may still be running against the same worktree. `next\n // build` and `next dev` share `.next`, so a build performed underneath a live\n // dev server clobbers it and that dev server then 404s every route. Giving\n // the e2e build its own directory keeps the two independent. E2E_BUILD must\n // be set for `next build` AND for `next start`, or `start` looks in `.next`\n // and serves someone else's output.\n ...(env.E2E_BUILD === \"true\" ? { distDir: \".next-e2e\" } : {}),\n cacheComponents: true,\n partialPrefetching: true,\n reactCompiler,\n experimental: {\n serverActions: {\n bodySizeLimit: \"5mb\",\n },\n // Required by `unauthorized()` (next/navigation): without this flag it throws a plain\n // Error instead of rendering the nearest unauthorized.tsx. The flag is for app code that\n // calls it; ServerSession.checkPermission does not, it still does `redirect(\"/401\")`.\n authInterrupts: options.authInterrupts ?? true,\n turbopackGc: true,\n // No turbopackLazyDynamicImports: in `next dev` it leaves this package's lazily\n // imported request module unactivated (\"Lazily compiled dynamic import of ...\n // JsonApiRequest ... was not activated\"), so every client-side read returns\n // nothing. Seen with the package installed from npm; production builds are unaffected.\n ...(reactCompiler ? { turbopackRustReactCompiler: true } : {}),\n },\n allowedDevOrigins: options.devOrigins,\n pageExtensions: options.mdx ? [\"ts\", \"tsx\", \"mdx\"] : [\"ts\", \"tsx\"],\n images: {\n minimumCacheTTL: options.imageMinimumCacheTTL ?? 60,\n remotePatterns: parseImageSources(env),\n dangerouslyAllowLocalIP: true,\n },\n poweredByHeader: false,\n reactStrictMode: false,\n env: {\n NEXT_PUBLIC_API_URL: env.NEXT_PUBLIC_API_URL ?? \"\",\n NEXT_PUBLIC_ADDRESS: env.NEXT_PUBLIC_ADDRESS ?? \"\",\n NEXT_PUBLIC_VAPID_PUBLIC_KEY: env.NEXT_PUBLIC_VAPID_PUBLIC_KEY ?? \"\",\n NEXT_PUBLIC_GOOGLE_MAPS_API_KEY: env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY ?? \"\",\n ...options.env,\n },\n // Inlined replacement for @serwist/turbopack's withSerwist wrapper, which\n // does nothing but append these two entries. Requiring the package here\n // instead CRASHES production: it is a devDependency, next.config.js is loaded\n // at RUNTIME by `next start`, and the web-production image installs with\n // --prod. Do not re-add a require of any devDependency to this file.\n ...(options.serwist ? { serverExternalPackages: [\"esbuild\", \"esbuild-wasm\"] } : {}),\n // Next 16 builds AND serves dev with Turbopack, so this is what pins yjs to a\n // single instance in both modes.\n turbopack: {\n resolveAlias: {\n yjs: \"./node_modules/yjs\",\n },\n },\n };\n\n if (options.securityHeaders !== false) {\n config.headers = async () => buildSecurityHeaders(options, process.env);\n }\n\n if (options.rewrites) config.rewrites = options.rewrites;\n\n return options.extend ? options.extend(config) : config;\n}\n"]}
@@ -32,17 +32,31 @@ function listImageSources(env) {
32
32
  return env.IMAGE_SOURCES ? env.IMAGE_SOURCES.split(",").map((s) => s.trim()) : [];
33
33
  }
34
34
  __name(listImageSources, "listImageSources");
35
+ function listAppOrigins(env) {
36
+ const origins = [];
37
+ for (const url of [env.NEXT_PUBLIC_API_URL, env.NEXT_PUBLIC_CORPUS_URL]) {
38
+ if (!url) continue;
39
+ try {
40
+ const { origin } = new URL(url.trim());
41
+ if (origin !== "null" && !origins.includes(origin)) origins.push(origin);
42
+ } catch {
43
+ }
44
+ }
45
+ return origins;
46
+ }
47
+ __name(listAppOrigins, "listAppOrigins");
35
48
  function buildCsp(options, env) {
36
49
  const apiUrl = env.NEXT_PUBLIC_API_URL || "";
37
50
  const imageSources = listImageSources(env);
51
+ const appOrigins = listAppOrigins(env);
38
52
  const services = options.services ?? [];
39
53
  const fetchDirectives = {
40
54
  // Scripts: self, and unsafe-inline/eval for Next.js
41
55
  "script-src": { base: ["'self'", "'unsafe-inline'", "'unsafe-eval'"], fromEnv: [] },
42
56
  // Styles: self and unsafe-inline for styled-components/emotion
43
57
  "style-src": { base: ["'self'", "'unsafe-inline'"], fromEnv: [] },
44
- // Images: self, data URIs, blobs, and configured image sources
45
- "img-src": { base: ["'self'", "data:", "blob:"], fromEnv: imageSources },
58
+ // Images: self, data URIs, blobs, configured image sources, and the api/corpus origins
59
+ "img-src": { base: ["'self'", "data:", "blob:"], fromEnv: [...imageSources, ...appOrigins] },
46
60
  // Fonts: self
47
61
  "font-src": { base: ["'self'"], fromEnv: [] },
48
62
  // Connect: self, API (http + ws for socket.io), and storage (for uploads)
@@ -56,8 +70,8 @@ function buildCsp(options, env) {
56
70
  ...imageSources
57
71
  ]
58
72
  },
59
- // Frames: self
60
- "frame-src": { base: ["'self'"], fromEnv: [] },
73
+ // Frames: self, and the api/corpus origins (inline previews of stored objects)
74
+ "frame-src": { base: ["'self'"], fromEnv: appOrigins },
61
75
  // Worker sources: self and blob (for Web Workers with dynamic imports)
62
76
  "worker-src": { base: ["'self'", "blob:"], fromEnv: [] }
63
77
  };
@@ -149,14 +163,21 @@ __name(buildSecurityHeaders, "buildSecurityHeaders");
149
163
 
150
164
  // src/next-config/index.ts
151
165
  function parseImageSources(env) {
152
- return env.IMAGE_SOURCES ? env.IMAGE_SOURCES.split(",").map((url) => {
153
- const { hostname, protocol, port } = new URL(url.trim());
154
- return {
166
+ const imageSources = env.IMAGE_SOURCES ? env.IMAGE_SOURCES.split(",").map((url) => url.trim()) : [];
167
+ const patterns = [];
168
+ for (const url of [...imageSources, ...listAppOrigins(env)]) {
169
+ const { hostname, protocol, port } = new URL(url);
170
+ const pattern = {
155
171
  protocol: protocol.replace(":", ""),
156
172
  hostname,
157
173
  port: port || void 0
158
174
  };
159
- }) : [];
175
+ const seen = patterns.some(
176
+ (p) => p.protocol === pattern.protocol && p.hostname === pattern.hostname && p.port === pattern.port
177
+ );
178
+ if (!seen) patterns.push(pattern);
179
+ }
180
+ return patterns;
160
181
  }
161
182
  __name(parseImageSources, "parseImageSources");
162
183
  function createNextConfig(options) {
@@ -228,6 +249,7 @@ function createNextConfig(options) {
228
249
  __name(createNextConfig, "createNextConfig");
229
250
  export {
230
251
  buildCsp,
231
- createNextConfig
252
+ createNextConfig,
253
+ listAppOrigins
232
254
  };
233
255
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next-config/csp.ts","../../src/next-config/headers.ts","../../src/next-config/index.ts"],"sourcesContent":["// Runtime imports: none. next.config.js loads this at RUNTIME under `next start`\n// in an image installed with --prod, so it may import only Node built-ins.\n\nexport type CspDirective =\n \"script-src\" | \"style-src\" | \"img-src\" | \"font-src\" | \"connect-src\" | \"frame-src\" | \"worker-src\";\n\n/**\n * Third-party services an app may load. Each one adds its hosts to the\n * directives it needs; nothing is allowed unless the app names it.\n *\n * - `stripe`: the billing feature (`@carlonicora/nextjs-jsonapi/billing`).\n * - `googleMaps`: `FormPlaceAutocomplete` (Places API) and Maps JS/static tiles.\n * - `turnstile`: Cloudflare Turnstile widgets (contact and waitlist forms).\n * - `discord`: Discord avatars shown for users who log in with Discord.\n * - `googleFonts`: fonts linked at runtime from Google Fonts. Not needed for\n * `next/font/google`, which self-hosts at build time.\n */\nexport type CspService = \"stripe\" | \"googleMaps\" | \"turnstile\" | \"discord\" | \"googleFonts\";\n\nexport interface CspOptions {\n services?: CspService[];\n csp?: Partial<Record<CspDirective, string[]>>;\n}\n\nconst SERVICE_SOURCES: Record<CspService, Partial<Record<CspDirective, string[]>>> = {\n stripe: {\n \"script-src\": [\"https://js.stripe.com\"],\n \"img-src\": [\"https://*.stripe.com\"],\n \"connect-src\": [\"https://api.stripe.com\"],\n \"frame-src\": [\"https://js.stripe.com\", \"https://hooks.stripe.com\"],\n },\n googleMaps: {\n \"script-src\": [\"https://maps.googleapis.com\"],\n \"img-src\": [\"https://maps.googleapis.com\", \"https://maps.gstatic.com\"],\n \"connect-src\": [\"https://maps.googleapis.com\", \"https://places.googleapis.com\"],\n },\n turnstile: {\n \"script-src\": [\"https://challenges.cloudflare.com\"],\n \"connect-src\": [\"https://challenges.cloudflare.com\"],\n \"frame-src\": [\"https://challenges.cloudflare.com\"],\n },\n discord: {\n \"img-src\": [\"https://cdn.discordapp.com\"],\n },\n googleFonts: {\n \"style-src\": [\"https://fonts.googleapis.com\"],\n \"font-src\": [\"https://fonts.gstatic.com\"],\n },\n};\n\nfunction listImageSources(env: NodeJS.ProcessEnv): string[] {\n return env.IMAGE_SOURCES ? env.IMAGE_SOURCES.split(\",\").map((s) => s.trim()) : [];\n}\n\n// Build CSP directives\n// Note: 'unsafe-inline' and 'unsafe-eval' needed for Next.js dev mode and some runtime features\n// In production, consider using nonces for stricter CSP\nexport function buildCsp(options: CspOptions, env: NodeJS.ProcessEnv): string {\n const apiUrl = env.NEXT_PUBLIC_API_URL || \"\";\n const imageSources = listImageSources(env);\n const services = options.services ?? [];\n\n // Each fetch directive: what Next itself needs, then the named services, then\n // the app's extras, then the sources derived from the env.\n const fetchDirectives: Record<CspDirective, { base: string[]; fromEnv: string[] }> = {\n // Scripts: self, and unsafe-inline/eval for Next.js\n \"script-src\": { base: [\"'self'\", \"'unsafe-inline'\", \"'unsafe-eval'\"], fromEnv: [] },\n // Styles: self and unsafe-inline for styled-components/emotion\n \"style-src\": { base: [\"'self'\", \"'unsafe-inline'\"], fromEnv: [] },\n // Images: self, data URIs, blobs, and configured image sources\n \"img-src\": { base: [\"'self'\", \"data:\", \"blob:\"], fromEnv: imageSources },\n // Fonts: self\n \"font-src\": { base: [\"'self'\"], fromEnv: [] },\n // Connect: self, API (http + ws for socket.io), and storage (for uploads)\n \"connect-src\": {\n base: [\"'self'\"],\n fromEnv: [\n apiUrl,\n // Add WebSocket URL for socket.io (convert http->ws, https->wss)\n apiUrl.replace(/^http/, \"ws\"),\n env.NEXT_PUBLIC_ADDRESS || \"\",\n ...imageSources,\n ],\n },\n // Frames: self\n \"frame-src\": { base: [\"'self'\"], fromEnv: [] },\n // Worker sources: self and blob (for Web Workers with dynamic imports)\n \"worker-src\": { base: [\"'self'\", \"blob:\"], fromEnv: [] },\n };\n\n const directive = (name: CspDirective): string => {\n const { base, fromEnv } = fetchDirectives[name];\n const fromServices = services.flatMap((service) => SERVICE_SOURCES[service][name] ?? []);\n const sources = [...base, ...fromServices, ...(options.csp?.[name] ?? []), ...fromEnv].filter(\n (source) => source !== \"\",\n );\n return [name, ...new Set(sources)].join(\" \");\n };\n\n return [\n \"default-src 'self'\",\n directive(\"script-src\"),\n directive(\"style-src\"),\n directive(\"img-src\"),\n directive(\"font-src\"),\n directive(\"connect-src\"),\n directive(\"frame-src\"),\n // Frame ancestors: deny embedding (equivalent to X-Frame-Options: DENY)\n \"frame-ancestors 'none'\",\n // Form actions: only self\n \"form-action 'self'\",\n // Base URI: only self\n \"base-uri 'self'\",\n // Object sources: none (no plugins)\n \"object-src 'none'\",\n directive(\"worker-src\"),\n // Upgrade insecure requests in production.\n //\n // NOT under E2E_BUILD: the e2e harness runs a PRODUCTION build (for speed)\n // and serves it over plain http on a custom hostname. With this directive\n // the browser rewrites every /_next/static asset to https, which nothing is\n // listening on — every chunk fails with ERR_SSL_PROTOCOL_ERROR, the page\n // never hydrates, and each spec sees only server-rendered markup.\n env.NODE_ENV === \"production\" && env.E2E_BUILD !== \"true\" ? \"upgrade-insecure-requests\" : \"\",\n ]\n .filter(Boolean)\n .join(\"; \");\n}\n","// Runtime imports: relative only. See csp.ts.\nimport { buildCsp, type CspOptions } from \"./csp\";\n\nexport interface SecurityHeaderOptions extends CspOptions {\n permissionsPolicy?: { camera?: \"none\" | \"self\" };\n}\n\nexport interface HeaderRule {\n source: string;\n headers: { key: string; value: string }[];\n}\n\nexport function buildSecurityHeaders(options: SecurityHeaderOptions, env: NodeJS.ProcessEnv): HeaderRule[] {\n const camera = options.permissionsPolicy?.camera === \"none\" ? \"\" : \"self\";\n\n return [\n {\n // Apply to all routes\n source: \"/:path*\",\n headers: [\n // Content Security Policy - prevents XSS attacks\n {\n key: \"Content-Security-Policy\",\n value: buildCsp(options, env),\n },\n // X-Frame-Options - prevents clickjacking (backup for older browsers)\n {\n key: \"X-Frame-Options\",\n value: \"DENY\",\n },\n // X-Content-Type-Options - prevents MIME sniffing\n {\n key: \"X-Content-Type-Options\",\n value: \"nosniff\",\n },\n // Strict-Transport-Security - enforces HTTPS (1 year, include subdomains).\n // Omitted under E2E_BUILD for the same reason as upgrade-insecure-requests:\n // the suite speaks plain http, and an HSTS pin would force https on every\n // later request to this host from the same browser profile.\n ...(env.E2E_BUILD === \"true\"\n ? []\n : [\n {\n key: \"Strict-Transport-Security\",\n value: \"max-age=31536000; includeSubDomains\",\n },\n ]),\n // Referrer-Policy - controls referrer information\n {\n key: \"Referrer-Policy\",\n value: \"strict-origin-when-cross-origin\",\n },\n // Permissions-Policy - restricts browser features\n {\n key: \"Permissions-Policy\",\n value: `camera=(${camera}), microphone=(), geolocation=()`,\n },\n ],\n },\n ];\n}\n","// Shared next.config for the nja fleet. Apps wrap the result with their own\n// plugins: `withNextIntl(withMDX(createNextConfig({...})))`.\n//\n// next.config.js is loaded at RUNTIME by `next start`, and the production image\n// installs with --prod. This entry may therefore import only Node built-ins at\n// runtime: never next-intl, @next/mdx, serwist or any devDependency. `next` is\n// imported for its types only.\nimport type { NextConfig } from \"next\";\nimport { buildCsp, type CspDirective, type CspService } from \"./csp\";\nimport { buildSecurityHeaders } from \"./headers\";\n\nexport { buildCsp };\nexport type { CspDirective, CspService };\n\nexport interface NjaNextConfigOptions {\n devOrigins: string[];\n /** Third-party services the app loads; each adds its own hosts to the CSP. Nothing is allowed by default. */\n services?: CspService[];\n /** Extra CSP sources per directive, for hosts no named service covers. */\n csp?: Partial<Record<CspDirective, string[]>>;\n env?: Record<string, string>;\n imageMinimumCacheTTL?: number;\n permissionsPolicy?: { camera?: \"none\" | \"self\" };\n mdx?: boolean;\n serwist?: boolean;\n securityHeaders?: boolean;\n authInterrupts?: boolean;\n reactCompiler?: boolean;\n rewrites?: NextConfig[\"rewrites\"];\n extend?: (config: NextConfig) => NextConfig;\n}\n\ntype RemotePattern = { protocol: \"http\" | \"https\"; hostname: string; port?: string };\n\nfunction parseImageSources(env: NodeJS.ProcessEnv): RemotePattern[] {\n return env.IMAGE_SOURCES\n ? env.IMAGE_SOURCES.split(\",\").map((url) => {\n const { hostname, protocol, port } = new URL(url.trim());\n return {\n protocol: protocol.replace(\":\", \"\") as RemotePattern[\"protocol\"],\n hostname,\n port: port || undefined,\n };\n })\n : [];\n}\n\nexport function createNextConfig(options: NjaNextConfigOptions): NextConfig {\n const env = process.env;\n const reactCompiler = options.reactCompiler === true;\n\n const config: NextConfig = {\n // The e2e stack (scripts/e2e.sh) runs a PRODUCTION build of this app while a\n // `next dev` server may still be running against the same worktree. `next\n // build` and `next dev` share `.next`, so a build performed underneath a live\n // dev server clobbers it and that dev server then 404s every route. Giving\n // the e2e build its own directory keeps the two independent. E2E_BUILD must\n // be set for `next build` AND for `next start`, or `start` looks in `.next`\n // and serves someone else's output.\n ...(env.E2E_BUILD === \"true\" ? { distDir: \".next-e2e\" } : {}),\n cacheComponents: true,\n partialPrefetching: true,\n reactCompiler,\n experimental: {\n serverActions: {\n bodySizeLimit: \"5mb\",\n },\n // Required by `unauthorized()` (next/navigation): without this flag it throws a plain\n // Error instead of rendering the nearest unauthorized.tsx. The flag is for app code that\n // calls it; ServerSession.checkPermission does not, it still does `redirect(\"/401\")`.\n authInterrupts: options.authInterrupts ?? true,\n turbopackGc: true,\n // No turbopackLazyDynamicImports: in `next dev` it leaves this package's lazily\n // imported request module unactivated (\"Lazily compiled dynamic import of ...\n // JsonApiRequest ... was not activated\"), so every client-side read returns\n // nothing. Seen with the package installed from npm; production builds are unaffected.\n ...(reactCompiler ? { turbopackRustReactCompiler: true } : {}),\n },\n allowedDevOrigins: options.devOrigins,\n pageExtensions: options.mdx ? [\"ts\", \"tsx\", \"mdx\"] : [\"ts\", \"tsx\"],\n images: {\n minimumCacheTTL: options.imageMinimumCacheTTL ?? 60,\n remotePatterns: parseImageSources(env),\n dangerouslyAllowLocalIP: true,\n },\n poweredByHeader: false,\n reactStrictMode: false,\n env: {\n NEXT_PUBLIC_API_URL: env.NEXT_PUBLIC_API_URL ?? \"\",\n NEXT_PUBLIC_ADDRESS: env.NEXT_PUBLIC_ADDRESS ?? \"\",\n NEXT_PUBLIC_VAPID_PUBLIC_KEY: env.NEXT_PUBLIC_VAPID_PUBLIC_KEY ?? \"\",\n NEXT_PUBLIC_GOOGLE_MAPS_API_KEY: env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY ?? \"\",\n ...options.env,\n },\n // Inlined replacement for @serwist/turbopack's withSerwist wrapper, which\n // does nothing but append these two entries. Requiring the package here\n // instead CRASHES production: it is a devDependency, next.config.js is loaded\n // at RUNTIME by `next start`, and the web-production image installs with\n // --prod. Do not re-add a require of any devDependency to this file.\n ...(options.serwist ? { serverExternalPackages: [\"esbuild\", \"esbuild-wasm\"] } : {}),\n // Next 16 builds AND serves dev with Turbopack, so this is what pins yjs to a\n // single instance in both modes.\n turbopack: {\n resolveAlias: {\n yjs: \"./node_modules/yjs\",\n },\n },\n };\n\n if (options.securityHeaders !== false) {\n config.headers = async () => buildSecurityHeaders(options, process.env);\n }\n\n if (options.rewrites) config.rewrites = options.rewrites;\n\n return options.extend ? options.extend(config) : config;\n}\n"],"mappings":";;;;;AAwBA,IAAM,kBAA+E;AAAA,EACnF,QAAQ;AAAA,IACN,cAAc,CAAC,uBAAuB;AAAA,IACtC,WAAW,CAAC,sBAAsB;AAAA,IAClC,eAAe,CAAC,wBAAwB;AAAA,IACxC,aAAa,CAAC,yBAAyB,0BAA0B;AAAA,EACnE;AAAA,EACA,YAAY;AAAA,IACV,cAAc,CAAC,6BAA6B;AAAA,IAC5C,WAAW,CAAC,+BAA+B,0BAA0B;AAAA,IACrE,eAAe,CAAC,+BAA+B,+BAA+B;AAAA,EAChF;AAAA,EACA,WAAW;AAAA,IACT,cAAc,CAAC,mCAAmC;AAAA,IAClD,eAAe,CAAC,mCAAmC;AAAA,IACnD,aAAa,CAAC,mCAAmC;AAAA,EACnD;AAAA,EACA,SAAS;AAAA,IACP,WAAW,CAAC,4BAA4B;AAAA,EAC1C;AAAA,EACA,aAAa;AAAA,IACX,aAAa,CAAC,8BAA8B;AAAA,IAC5C,YAAY,CAAC,2BAA2B;AAAA,EAC1C;AACF;AAEA,SAAS,iBAAiB,KAAkC;AAC1D,SAAO,IAAI,gBAAgB,IAAI,cAAc,MAAM,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC;AAClF;AAFS;AAOF,SAAS,SAAS,SAAqB,KAAgC;AAC5E,QAAM,SAAS,IAAI,uBAAuB;AAC1C,QAAM,eAAe,iBAAiB,GAAG;AACzC,QAAM,WAAW,QAAQ,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AA,QACZ,KAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AAEA,MAAI,QAAQ,oBAAoB,OAAO;AACrC,WAAO,UAAU,YAAY,qBAAqB,SAAS,QAAQ,GAAG;AAAA,EACxE;AAEA,MAAI,QAAQ,SAAU,QAAO,WAAW,QAAQ;AAEhD,SAAO,QAAQ,SAAS,QAAQ,OAAO,MAAM,IAAI;AACnD;AArEgB;","names":[]}
1
+ {"version":3,"sources":["../../src/next-config/csp.ts","../../src/next-config/headers.ts","../../src/next-config/index.ts"],"sourcesContent":["// Runtime imports: none. next.config.js loads this at RUNTIME under `next start`\n// in an image installed with --prod, so it may import only Node built-ins.\n\nexport type CspDirective =\n \"script-src\" | \"style-src\" | \"img-src\" | \"font-src\" | \"connect-src\" | \"frame-src\" | \"worker-src\";\n\n/**\n * Third-party services an app may load. Each one adds its hosts to the\n * directives it needs; nothing is allowed unless the app names it.\n *\n * - `stripe`: the billing feature (`@carlonicora/nextjs-jsonapi/billing`).\n * - `googleMaps`: `FormPlaceAutocomplete` (Places API) and Maps JS/static tiles.\n * - `turnstile`: Cloudflare Turnstile widgets (contact and waitlist forms).\n * - `discord`: Discord avatars shown for users who log in with Discord.\n * - `googleFonts`: fonts linked at runtime from Google Fonts. Not needed for\n * `next/font/google`, which self-hosts at build time.\n */\nexport type CspService = \"stripe\" | \"googleMaps\" | \"turnstile\" | \"discord\" | \"googleFonts\";\n\nexport interface CspOptions {\n services?: CspService[];\n csp?: Partial<Record<CspDirective, string[]>>;\n}\n\nconst SERVICE_SOURCES: Record<CspService, Partial<Record<CspDirective, string[]>>> = {\n stripe: {\n \"script-src\": [\"https://js.stripe.com\"],\n \"img-src\": [\"https://*.stripe.com\"],\n \"connect-src\": [\"https://api.stripe.com\"],\n \"frame-src\": [\"https://js.stripe.com\", \"https://hooks.stripe.com\"],\n },\n googleMaps: {\n \"script-src\": [\"https://maps.googleapis.com\"],\n \"img-src\": [\"https://maps.googleapis.com\", \"https://maps.gstatic.com\"],\n \"connect-src\": [\"https://maps.googleapis.com\", \"https://places.googleapis.com\"],\n },\n turnstile: {\n \"script-src\": [\"https://challenges.cloudflare.com\"],\n \"connect-src\": [\"https://challenges.cloudflare.com\"],\n \"frame-src\": [\"https://challenges.cloudflare.com\"],\n },\n discord: {\n \"img-src\": [\"https://cdn.discordapp.com\"],\n },\n googleFonts: {\n \"style-src\": [\"https://fonts.googleapis.com\"],\n \"font-src\": [\"https://fonts.gstatic.com\"],\n },\n};\n\nfunction listImageSources(env: NodeJS.ProcessEnv): string[] {\n return env.IMAGE_SOURCES ? env.IMAGE_SOURCES.split(\",\").map((s) => s.trim()) : [];\n}\n\n/**\n * Origins of the app's own servers, the API and the corpus, from\n * `NEXT_PUBLIC_API_URL` and `NEXT_PUBLIC_CORPUS_URL`. They serve every stored\n * object link, so images and frames must be allowed from them. Unset or invalid\n * URLs are skipped; the result has no duplicates.\n */\nexport function listAppOrigins(env: NodeJS.ProcessEnv): string[] {\n const origins: string[] = [];\n for (const url of [env.NEXT_PUBLIC_API_URL, env.NEXT_PUBLIC_CORPUS_URL]) {\n if (!url) continue;\n try {\n const { origin } = new URL(url.trim());\n if (origin !== \"null\" && !origins.includes(origin)) origins.push(origin);\n } catch {\n // Not a URL: nothing to allow.\n }\n }\n return origins;\n}\n\n// Build CSP directives\n// Note: 'unsafe-inline' and 'unsafe-eval' needed for Next.js dev mode and some runtime features\n// In production, consider using nonces for stricter CSP\nexport function buildCsp(options: CspOptions, env: NodeJS.ProcessEnv): string {\n const apiUrl = env.NEXT_PUBLIC_API_URL || \"\";\n const imageSources = listImageSources(env);\n const appOrigins = listAppOrigins(env);\n const services = options.services ?? [];\n\n // Each fetch directive: what Next itself needs, then the named services, then\n // the app's extras, then the sources derived from the env.\n const fetchDirectives: Record<CspDirective, { base: string[]; fromEnv: string[] }> = {\n // Scripts: self, and unsafe-inline/eval for Next.js\n \"script-src\": { base: [\"'self'\", \"'unsafe-inline'\", \"'unsafe-eval'\"], fromEnv: [] },\n // Styles: self and unsafe-inline for styled-components/emotion\n \"style-src\": { base: [\"'self'\", \"'unsafe-inline'\"], fromEnv: [] },\n // Images: self, data URIs, blobs, configured image sources, and the api/corpus origins\n \"img-src\": { base: [\"'self'\", \"data:\", \"blob:\"], fromEnv: [...imageSources, ...appOrigins] },\n // Fonts: self\n \"font-src\": { base: [\"'self'\"], fromEnv: [] },\n // Connect: self, API (http + ws for socket.io), and storage (for uploads)\n \"connect-src\": {\n base: [\"'self'\"],\n fromEnv: [\n apiUrl,\n // Add WebSocket URL for socket.io (convert http->ws, https->wss)\n apiUrl.replace(/^http/, \"ws\"),\n env.NEXT_PUBLIC_ADDRESS || \"\",\n ...imageSources,\n ],\n },\n // Frames: self, and the api/corpus origins (inline previews of stored objects)\n \"frame-src\": { base: [\"'self'\"], fromEnv: appOrigins },\n // Worker sources: self and blob (for Web Workers with dynamic imports)\n \"worker-src\": { base: [\"'self'\", \"blob:\"], fromEnv: [] },\n };\n\n const directive = (name: CspDirective): string => {\n const { base, fromEnv } = fetchDirectives[name];\n const fromServices = services.flatMap((service) => SERVICE_SOURCES[service][name] ?? []);\n const sources = [...base, ...fromServices, ...(options.csp?.[name] ?? []), ...fromEnv].filter(\n (source) => source !== \"\",\n );\n return [name, ...new Set(sources)].join(\" \");\n };\n\n return [\n \"default-src 'self'\",\n directive(\"script-src\"),\n directive(\"style-src\"),\n directive(\"img-src\"),\n directive(\"font-src\"),\n directive(\"connect-src\"),\n directive(\"frame-src\"),\n // Frame ancestors: deny embedding (equivalent to X-Frame-Options: DENY)\n \"frame-ancestors 'none'\",\n // Form actions: only self\n \"form-action 'self'\",\n // Base URI: only self\n \"base-uri 'self'\",\n // Object sources: none (no plugins)\n \"object-src 'none'\",\n directive(\"worker-src\"),\n // Upgrade insecure requests in production.\n //\n // NOT under E2E_BUILD: the e2e harness runs a PRODUCTION build (for speed)\n // and serves it over plain http on a custom hostname. With this directive\n // the browser rewrites every /_next/static asset to https, which nothing is\n // listening on — every chunk fails with ERR_SSL_PROTOCOL_ERROR, the page\n // never hydrates, and each spec sees only server-rendered markup.\n env.NODE_ENV === \"production\" && env.E2E_BUILD !== \"true\" ? \"upgrade-insecure-requests\" : \"\",\n ]\n .filter(Boolean)\n .join(\"; \");\n}\n","// Runtime imports: relative only. See csp.ts.\nimport { buildCsp, type CspOptions } from \"./csp\";\n\nexport interface SecurityHeaderOptions extends CspOptions {\n permissionsPolicy?: { camera?: \"none\" | \"self\" };\n}\n\nexport interface HeaderRule {\n source: string;\n headers: { key: string; value: string }[];\n}\n\nexport function buildSecurityHeaders(options: SecurityHeaderOptions, env: NodeJS.ProcessEnv): HeaderRule[] {\n const camera = options.permissionsPolicy?.camera === \"none\" ? \"\" : \"self\";\n\n return [\n {\n // Apply to all routes\n source: \"/:path*\",\n headers: [\n // Content Security Policy - prevents XSS attacks\n {\n key: \"Content-Security-Policy\",\n value: buildCsp(options, env),\n },\n // X-Frame-Options - prevents clickjacking (backup for older browsers)\n {\n key: \"X-Frame-Options\",\n value: \"DENY\",\n },\n // X-Content-Type-Options - prevents MIME sniffing\n {\n key: \"X-Content-Type-Options\",\n value: \"nosniff\",\n },\n // Strict-Transport-Security - enforces HTTPS (1 year, include subdomains).\n // Omitted under E2E_BUILD for the same reason as upgrade-insecure-requests:\n // the suite speaks plain http, and an HSTS pin would force https on every\n // later request to this host from the same browser profile.\n ...(env.E2E_BUILD === \"true\"\n ? []\n : [\n {\n key: \"Strict-Transport-Security\",\n value: \"max-age=31536000; includeSubDomains\",\n },\n ]),\n // Referrer-Policy - controls referrer information\n {\n key: \"Referrer-Policy\",\n value: \"strict-origin-when-cross-origin\",\n },\n // Permissions-Policy - restricts browser features\n {\n key: \"Permissions-Policy\",\n value: `camera=(${camera}), microphone=(), geolocation=()`,\n },\n ],\n },\n ];\n}\n","// Shared next.config for the nja fleet. Apps wrap the result with their own\n// plugins: `withNextIntl(withMDX(createNextConfig({...})))`.\n//\n// next.config.js is loaded at RUNTIME by `next start`, and the production image\n// installs with --prod. This entry may therefore import only Node built-ins at\n// runtime: never next-intl, @next/mdx, serwist or any devDependency. `next` is\n// imported for its types only.\nimport type { NextConfig } from \"next\";\nimport { buildCsp, listAppOrigins, type CspDirective, type CspService } from \"./csp\";\nimport { buildSecurityHeaders } from \"./headers\";\n\nexport { buildCsp, listAppOrigins };\nexport type { CspDirective, CspService };\n\nexport interface NjaNextConfigOptions {\n devOrigins: string[];\n /** Third-party services the app loads; each adds its own hosts to the CSP. Nothing is allowed by default. */\n services?: CspService[];\n /** Extra CSP sources per directive, for hosts no named service covers. */\n csp?: Partial<Record<CspDirective, string[]>>;\n env?: Record<string, string>;\n imageMinimumCacheTTL?: number;\n permissionsPolicy?: { camera?: \"none\" | \"self\" };\n mdx?: boolean;\n serwist?: boolean;\n securityHeaders?: boolean;\n authInterrupts?: boolean;\n reactCompiler?: boolean;\n rewrites?: NextConfig[\"rewrites\"];\n extend?: (config: NextConfig) => NextConfig;\n}\n\ntype RemotePattern = { protocol: \"http\" | \"https\"; hostname: string; port?: string };\n\n// IMAGE_SOURCES, then the api and corpus origins (they serve every stored object\n// link), without duplicates.\nfunction parseImageSources(env: NodeJS.ProcessEnv): RemotePattern[] {\n const imageSources = env.IMAGE_SOURCES ? env.IMAGE_SOURCES.split(\",\").map((url) => url.trim()) : [];\n const patterns: RemotePattern[] = [];\n for (const url of [...imageSources, ...listAppOrigins(env)]) {\n const { hostname, protocol, port } = new URL(url);\n const pattern: RemotePattern = {\n protocol: protocol.replace(\":\", \"\") as RemotePattern[\"protocol\"],\n hostname,\n port: port || undefined,\n };\n const seen = patterns.some(\n (p) => p.protocol === pattern.protocol && p.hostname === pattern.hostname && p.port === pattern.port,\n );\n if (!seen) patterns.push(pattern);\n }\n return patterns;\n}\n\nexport function createNextConfig(options: NjaNextConfigOptions): NextConfig {\n const env = process.env;\n const reactCompiler = options.reactCompiler === true;\n\n const config: NextConfig = {\n // The e2e stack (scripts/e2e.sh) runs a PRODUCTION build of this app while a\n // `next dev` server may still be running against the same worktree. `next\n // build` and `next dev` share `.next`, so a build performed underneath a live\n // dev server clobbers it and that dev server then 404s every route. Giving\n // the e2e build its own directory keeps the two independent. E2E_BUILD must\n // be set for `next build` AND for `next start`, or `start` looks in `.next`\n // and serves someone else's output.\n ...(env.E2E_BUILD === \"true\" ? { distDir: \".next-e2e\" } : {}),\n cacheComponents: true,\n partialPrefetching: true,\n reactCompiler,\n experimental: {\n serverActions: {\n bodySizeLimit: \"5mb\",\n },\n // Required by `unauthorized()` (next/navigation): without this flag it throws a plain\n // Error instead of rendering the nearest unauthorized.tsx. The flag is for app code that\n // calls it; ServerSession.checkPermission does not, it still does `redirect(\"/401\")`.\n authInterrupts: options.authInterrupts ?? true,\n turbopackGc: true,\n // No turbopackLazyDynamicImports: in `next dev` it leaves this package's lazily\n // imported request module unactivated (\"Lazily compiled dynamic import of ...\n // JsonApiRequest ... was not activated\"), so every client-side read returns\n // nothing. Seen with the package installed from npm; production builds are unaffected.\n ...(reactCompiler ? { turbopackRustReactCompiler: true } : {}),\n },\n allowedDevOrigins: options.devOrigins,\n pageExtensions: options.mdx ? [\"ts\", \"tsx\", \"mdx\"] : [\"ts\", \"tsx\"],\n images: {\n minimumCacheTTL: options.imageMinimumCacheTTL ?? 60,\n remotePatterns: parseImageSources(env),\n dangerouslyAllowLocalIP: true,\n },\n poweredByHeader: false,\n reactStrictMode: false,\n env: {\n NEXT_PUBLIC_API_URL: env.NEXT_PUBLIC_API_URL ?? \"\",\n NEXT_PUBLIC_ADDRESS: env.NEXT_PUBLIC_ADDRESS ?? \"\",\n NEXT_PUBLIC_VAPID_PUBLIC_KEY: env.NEXT_PUBLIC_VAPID_PUBLIC_KEY ?? \"\",\n NEXT_PUBLIC_GOOGLE_MAPS_API_KEY: env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY ?? \"\",\n ...options.env,\n },\n // Inlined replacement for @serwist/turbopack's withSerwist wrapper, which\n // does nothing but append these two entries. Requiring the package here\n // instead CRASHES production: it is a devDependency, next.config.js is loaded\n // at RUNTIME by `next start`, and the web-production image installs with\n // --prod. Do not re-add a require of any devDependency to this file.\n ...(options.serwist ? { serverExternalPackages: [\"esbuild\", \"esbuild-wasm\"] } : {}),\n // Next 16 builds AND serves dev with Turbopack, so this is what pins yjs to a\n // single instance in both modes.\n turbopack: {\n resolveAlias: {\n yjs: \"./node_modules/yjs\",\n },\n },\n };\n\n if (options.securityHeaders !== false) {\n config.headers = async () => buildSecurityHeaders(options, process.env);\n }\n\n if (options.rewrites) config.rewrites = options.rewrites;\n\n return options.extend ? options.extend(config) : config;\n}\n"],"mappings":";;;;;AAwBA,IAAM,kBAA+E;AAAA,EACnF,QAAQ;AAAA,IACN,cAAc,CAAC,uBAAuB;AAAA,IACtC,WAAW,CAAC,sBAAsB;AAAA,IAClC,eAAe,CAAC,wBAAwB;AAAA,IACxC,aAAa,CAAC,yBAAyB,0BAA0B;AAAA,EACnE;AAAA,EACA,YAAY;AAAA,IACV,cAAc,CAAC,6BAA6B;AAAA,IAC5C,WAAW,CAAC,+BAA+B,0BAA0B;AAAA,IACrE,eAAe,CAAC,+BAA+B,+BAA+B;AAAA,EAChF;AAAA,EACA,WAAW;AAAA,IACT,cAAc,CAAC,mCAAmC;AAAA,IAClD,eAAe,CAAC,mCAAmC;AAAA,IACnD,aAAa,CAAC,mCAAmC;AAAA,EACnD;AAAA,EACA,SAAS;AAAA,IACP,WAAW,CAAC,4BAA4B;AAAA,EAC1C;AAAA,EACA,aAAa;AAAA,IACX,aAAa,CAAC,8BAA8B;AAAA,IAC5C,YAAY,CAAC,2BAA2B;AAAA,EAC1C;AACF;AAEA,SAAS,iBAAiB,KAAkC;AAC1D,SAAO,IAAI,gBAAgB,IAAI,cAAc,MAAM,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC;AAClF;AAFS;AAUF,SAAS,eAAe,KAAkC;AAC/D,QAAM,UAAoB,CAAC;AAC3B,aAAW,OAAO,CAAC,IAAI,qBAAqB,IAAI,sBAA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AAA;AAAA;AAAA;AAAA,MAKb,GAAI,gBAAgB,EAAE,4BAA4B,KAAK,IAAI,CAAC;AAAA,IAC9D;AAAA,IACA,mBAAmB,QAAQ;AAAA,IAC3B,gBAAgB,QAAQ,MAAM,CAAC,MAAM,OAAO,KAAK,IAAI,CAAC,MAAM,KAAK;AAAA,IACjE,QAAQ;AAAA,MACN,iBAAiB,QAAQ,wBAAwB;AAAA,MACjD,gBAAgB,kBAAkB,GAAG;AAAA,MACrC,yBAAyB;AAAA,IAC3B;AAAA,IACA,iBAAiB;AAAA,IACjB,iBAAiB;AAAA,IACjB,KAAK;AAAA,MACH,qBAAqB,IAAI,uBAAuB;AAAA,MAChD,qBAAqB,IAAI,uBAAuB;AAAA,MAChD,8BAA8B,IAAI,gCAAgC;AAAA,MAClE,iCAAiC,IAAI,mCAAmC;AAAA,MACxE,GAAG,QAAQ;AAAA,IACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,GAAI,QAAQ,UAAU,EAAE,wBAAwB,CAAC,WAAW,cAAc,EAAE,IAAI,CAAC;AAAA;AAAA;AAAA,IAGjF,WAAW;AAAA,MACT,cAAc;AAAA,QACZ,KAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF;AAEA,MAAI,QAAQ,oBAAoB,OAAO;AACrC,WAAO,UAAU,YAAY,qBAAqB,SAAS,QAAQ,GAAG;AAAA,EACxE;AAEA,MAAI,QAAQ,SAAU,QAAO,WAAW,QAAQ;AAEhD,SAAO,QAAQ,SAAS,QAAQ,OAAO,MAAM,IAAI;AACnD;AArEgB;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carlonicora/nextjs-jsonapi",
3
- "version": "4.0.8",
3
+ "version": "4.1.0",
4
4
  "description": "Next.js JSON:API client with server/client support and caching",
5
5
  "author": "Carlo Nicora",
6
6
  "license": "GPL-3.0-or-later",
@@ -7,7 +7,7 @@ import { ReactNode } from "react";
7
7
  import { AttributeElement } from "../../../../components";
8
8
  import { SectionHeader, MicroLabel } from "../../../../components/typography";
9
9
  import { FiscalDataDisplay } from "../../../../components/fiscal/FiscalDataDisplay";
10
- import { cn } from "../../../../utils";
10
+ import { cn, isRemoteImageSrc } from "../../../../utils";
11
11
  import { CompanyInterface } from "../../data";
12
12
 
13
13
  type CompanyContentProps = {
@@ -44,7 +44,14 @@ export function CompanyContent({ company, actions }: CompanyContentProps) {
44
44
  {/* Hero Section */}
45
45
  <div className="flex items-start gap-x-6">
46
46
  {company.logo && (
47
- <Image src={company.logo} alt={company.name} width={150} height={150} className="rounded-md" />
47
+ <Image
48
+ src={company.logo}
49
+ alt={company.name}
50
+ width={150}
51
+ height={150}
52
+ className="rounded-md"
53
+ unoptimized={isRemoteImageSrc(company.logo)}
54
+ />
48
55
  )}
49
56
  <div className="flex flex-col gap-y-2">
50
57
  {company.legal_address && (
@@ -26,6 +26,7 @@ import { Modules } from "../../../../core";
26
26
  import { useI18nRouter } from "../../../../i18n";
27
27
  import { getRoleId } from "../../../../roles";
28
28
  import { ScrollArea } from "../../../../shadcnui";
29
+ import { isRemoteImageSrc } from "../../../../utils";
29
30
  import { FeatureInterface } from "../../../feature";
30
31
  import { FeatureService } from "../../../feature/data/feature.service";
31
32
  import { S3Interface } from "../../../s3";
@@ -232,6 +233,7 @@ function CompanyEditorInternal({
232
233
  alt="Company Logo"
233
234
  width={200}
234
235
  height={200}
236
+ unoptimized={isRemoteImageSrc(file ? undefined : company?.logo)}
235
237
  />
236
238
  ) : (
237
239
  <>
@@ -9,12 +9,12 @@ const FIXED_ENV = vi.hoisted(() => {
9
9
  NEXT_PUBLIC_API_URL: "https://api.test",
10
10
  NEXT_PUBLIC_ADDRESS: "https://app.test",
11
11
  IMAGE_SOURCES: "https://img.test",
12
+ NEXT_PUBLIC_CORPUS_URL: "https://corpus.test",
12
13
  APP_URL: "https://app.test",
13
14
  };
14
15
  for (const key of [
15
16
  "NEXT_PUBLIC_VAPID_PUBLIC_KEY",
16
17
  "NEXT_PUBLIC_GOOGLE_MAPS_API_KEY",
17
- "NEXT_PUBLIC_CORPUS_URL",
18
18
  "NEXT_PUBLIC_GTM_ID",
19
19
  "E2E_BUILD",
20
20
  ])
@@ -139,7 +139,11 @@ describe("createNextConfig: behaviour", () => {
139
139
  expect(plain.allowedDevOrigins).toEqual(["example.test"]);
140
140
  expect(plain.images).toEqual({
141
141
  minimumCacheTTL: 60,
142
- remotePatterns: [{ protocol: "https", hostname: "img.test" }],
142
+ remotePatterns: [
143
+ { protocol: "https", hostname: "img.test" },
144
+ { protocol: "https", hostname: "api.test" },
145
+ { protocol: "https", hostname: "corpus.test" },
146
+ ],
143
147
  dangerouslyAllowLocalIP: true,
144
148
  });
145
149
 
@@ -166,6 +170,16 @@ describe("createNextConfig: behaviour", () => {
166
170
  expect(production.distDir).toBeUndefined();
167
171
  });
168
172
 
173
+ it("lets the optimizer fetch from the api and corpus origins, skipping unset and duplicate ones", () => {
174
+ vi.stubEnv("NEXT_PUBLIC_CORPUS_URL", undefined);
175
+ vi.stubEnv("IMAGE_SOURCES", "https://img.test,https://api.test");
176
+ const config = createNextConfig(base) as { images: { remotePatterns: unknown[] } };
177
+ expect(config.images.remotePatterns).toEqual([
178
+ { protocol: "https", hostname: "img.test" },
179
+ { protocol: "https", hostname: "api.test" },
180
+ ]);
181
+ });
182
+
169
183
  it("reactCompiler option sets both reactCompiler and turbopackRustReactCompiler", () => {
170
184
  const on = createNextConfig({ ...base, reactCompiler: true });
171
185
  expect(on.reactCompiler).toBe(true);
@@ -197,7 +211,7 @@ describe("buildCsp", () => {
197
211
  expect(csp["script-src"]).toEqual(["'self'", "'unsafe-eval'", "'unsafe-inline'"]);
198
212
  expect(csp["style-src"]).toEqual(["'self'", "'unsafe-inline'"]);
199
213
  expect(csp["font-src"]).toEqual(["'self'"]);
200
- expect(csp["frame-src"]).toEqual(["'self'"]);
214
+ expect(csp["frame-src"]).toEqual(["'self'", "https://api.test", "https://corpus.test"]);
201
215
  expect(csp["worker-src"]).toEqual(["'self'", "blob:"]);
202
216
  expect(buildCsp({}, env)).not.toMatch(/stripe|google|cloudflare|discord/);
203
217
  });
@@ -246,6 +260,8 @@ describe("buildCsp", () => {
246
260
  const csp = parseCsp(buildCsp({ services: ["stripe"], csp: { "frame-src": ["https://docs.google.com/"] } }, env));
247
261
  expect(csp["frame-src"]).toEqual([
248
262
  "'self'",
263
+ "https://api.test",
264
+ "https://corpus.test",
249
265
  "https://docs.google.com/",
250
266
  "https://hooks.stripe.com",
251
267
  "https://js.stripe.com",
@@ -260,6 +276,32 @@ describe("buildCsp", () => {
260
276
  expect(csp["img-src"]).toContain("https://img.test");
261
277
  });
262
278
 
279
+ it("allows images and frames from the api and corpus origins", () => {
280
+ const csp = parseCsp(buildCsp({}, env));
281
+ for (const directive of ["img-src", "frame-src"]) {
282
+ expect(csp[directive]).toEqual(expect.arrayContaining(["https://api.test", "https://corpus.test"]));
283
+ }
284
+ });
285
+
286
+ it("lists the api and corpus origins once, and nothing for an unset corpus", () => {
287
+ const value = buildCsp({}, {
288
+ NODE_ENV: "production",
289
+ NEXT_PUBLIC_API_URL: "https://api.test/",
290
+ IMAGE_SOURCES: "https://api.test",
291
+ } as unknown as NodeJS.ProcessEnv);
292
+ for (const directive of ["img-src", "frame-src"]) {
293
+ const sources = value
294
+ .split(";")
295
+ .map((part) => part.trim().split(/\s+/))
296
+ .find(([name]) => name === directive)!
297
+ .slice(1);
298
+ expect(sources.filter((source) => source === "https://api.test")).toHaveLength(1);
299
+ expect(sources.join(" ")).not.toContain("corpus");
300
+ expect(sources).not.toContain("");
301
+ }
302
+ expect(value).not.toMatch(/\s{2,}/);
303
+ });
304
+
263
305
  it("drops empty sources when env values are missing", () => {
264
306
  const value = buildCsp({ csp: { "img-src": [""] } }, { NODE_ENV: "development" } as unknown as NodeJS.ProcessEnv);
265
307
  expect(value).not.toMatch(/\s{2,}/);
@@ -52,12 +52,33 @@ function listImageSources(env: NodeJS.ProcessEnv): string[] {
52
52
  return env.IMAGE_SOURCES ? env.IMAGE_SOURCES.split(",").map((s) => s.trim()) : [];
53
53
  }
54
54
 
55
+ /**
56
+ * Origins of the app's own servers, the API and the corpus, from
57
+ * `NEXT_PUBLIC_API_URL` and `NEXT_PUBLIC_CORPUS_URL`. They serve every stored
58
+ * object link, so images and frames must be allowed from them. Unset or invalid
59
+ * URLs are skipped; the result has no duplicates.
60
+ */
61
+ export function listAppOrigins(env: NodeJS.ProcessEnv): string[] {
62
+ const origins: string[] = [];
63
+ for (const url of [env.NEXT_PUBLIC_API_URL, env.NEXT_PUBLIC_CORPUS_URL]) {
64
+ if (!url) continue;
65
+ try {
66
+ const { origin } = new URL(url.trim());
67
+ if (origin !== "null" && !origins.includes(origin)) origins.push(origin);
68
+ } catch {
69
+ // Not a URL: nothing to allow.
70
+ }
71
+ }
72
+ return origins;
73
+ }
74
+
55
75
  // Build CSP directives
56
76
  // Note: 'unsafe-inline' and 'unsafe-eval' needed for Next.js dev mode and some runtime features
57
77
  // In production, consider using nonces for stricter CSP
58
78
  export function buildCsp(options: CspOptions, env: NodeJS.ProcessEnv): string {
59
79
  const apiUrl = env.NEXT_PUBLIC_API_URL || "";
60
80
  const imageSources = listImageSources(env);
81
+ const appOrigins = listAppOrigins(env);
61
82
  const services = options.services ?? [];
62
83
 
63
84
  // Each fetch directive: what Next itself needs, then the named services, then
@@ -67,8 +88,8 @@ export function buildCsp(options: CspOptions, env: NodeJS.ProcessEnv): string {
67
88
  "script-src": { base: ["'self'", "'unsafe-inline'", "'unsafe-eval'"], fromEnv: [] },
68
89
  // Styles: self and unsafe-inline for styled-components/emotion
69
90
  "style-src": { base: ["'self'", "'unsafe-inline'"], fromEnv: [] },
70
- // Images: self, data URIs, blobs, and configured image sources
71
- "img-src": { base: ["'self'", "data:", "blob:"], fromEnv: imageSources },
91
+ // Images: self, data URIs, blobs, configured image sources, and the api/corpus origins
92
+ "img-src": { base: ["'self'", "data:", "blob:"], fromEnv: [...imageSources, ...appOrigins] },
72
93
  // Fonts: self
73
94
  "font-src": { base: ["'self'"], fromEnv: [] },
74
95
  // Connect: self, API (http + ws for socket.io), and storage (for uploads)
@@ -82,8 +103,8 @@ export function buildCsp(options: CspOptions, env: NodeJS.ProcessEnv): string {
82
103
  ...imageSources,
83
104
  ],
84
105
  },
85
- // Frames: self
86
- "frame-src": { base: ["'self'"], fromEnv: [] },
106
+ // Frames: self, and the api/corpus origins (inline previews of stored objects)
107
+ "frame-src": { base: ["'self'"], fromEnv: appOrigins },
87
108
  // Worker sources: self and blob (for Web Workers with dynamic imports)
88
109
  "worker-src": { base: ["'self'", "blob:"], fromEnv: [] },
89
110
  };
@@ -6,10 +6,10 @@
6
6
  // runtime: never next-intl, @next/mdx, serwist or any devDependency. `next` is
7
7
  // imported for its types only.
8
8
  import type { NextConfig } from "next";
9
- import { buildCsp, type CspDirective, type CspService } from "./csp";
9
+ import { buildCsp, listAppOrigins, type CspDirective, type CspService } from "./csp";
10
10
  import { buildSecurityHeaders } from "./headers";
11
11
 
12
- export { buildCsp };
12
+ export { buildCsp, listAppOrigins };
13
13
  export type { CspDirective, CspService };
14
14
 
15
15
  export interface NjaNextConfigOptions {
@@ -32,17 +32,24 @@ export interface NjaNextConfigOptions {
32
32
 
33
33
  type RemotePattern = { protocol: "http" | "https"; hostname: string; port?: string };
34
34
 
35
+ // IMAGE_SOURCES, then the api and corpus origins (they serve every stored object
36
+ // link), without duplicates.
35
37
  function parseImageSources(env: NodeJS.ProcessEnv): RemotePattern[] {
36
- return env.IMAGE_SOURCES
37
- ? env.IMAGE_SOURCES.split(",").map((url) => {
38
- const { hostname, protocol, port } = new URL(url.trim());
39
- return {
40
- protocol: protocol.replace(":", "") as RemotePattern["protocol"],
41
- hostname,
42
- port: port || undefined,
43
- };
44
- })
45
- : [];
38
+ const imageSources = env.IMAGE_SOURCES ? env.IMAGE_SOURCES.split(",").map((url) => url.trim()) : [];
39
+ const patterns: RemotePattern[] = [];
40
+ for (const url of [...imageSources, ...listAppOrigins(env)]) {
41
+ const { hostname, protocol, port } = new URL(url);
42
+ const pattern: RemotePattern = {
43
+ protocol: protocol.replace(":", "") as RemotePattern["protocol"],
44
+ hostname,
45
+ port: port || undefined,
46
+ };
47
+ const seen = patterns.some(
48
+ (p) => p.protocol === pattern.protocol && p.hostname === pattern.hostname && p.port === pattern.port,
49
+ );
50
+ if (!seen) patterns.push(pattern);
51
+ }
52
+ return patterns;
46
53
  }
47
54
 
48
55
  export function createNextConfig(options: NjaNextConfigOptions): NextConfig {