@jasonshimmy/vite-plugin-cer-app 0.23.2 → 0.24.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.
- package/dist/cli/checks/lighthouse.d.ts +26 -0
- package/dist/cli/checks/lighthouse.d.ts.map +1 -0
- package/dist/cli/checks/lighthouse.js +121 -0
- package/dist/cli/checks/lighthouse.js.map +1 -0
- package/dist/cli/checks/links.d.ts +12 -0
- package/dist/cli/checks/links.d.ts.map +1 -0
- package/dist/cli/checks/links.js +89 -0
- package/dist/cli/checks/links.js.map +1 -0
- package/dist/cli/checks/performance.d.ts +17 -0
- package/dist/cli/checks/performance.d.ts.map +1 -0
- package/dist/cli/checks/performance.js +61 -0
- package/dist/cli/checks/performance.js.map +1 -0
- package/dist/cli/commands/check.d.ts +3 -0
- package/dist/cli/commands/check.d.ts.map +1 -0
- package/dist/cli/commands/check.js +85 -0
- package/dist/cli/commands/check.js.map +1 -0
- package/dist/cli/create/index.d.ts +11 -1
- package/dist/cli/create/index.d.ts.map +1 -1
- package/dist/cli/create/index.js +135 -65
- package/dist/cli/create/index.js.map +1 -1
- package/dist/cli/create/templates/spa/package.json.tpl +5 -3
- package/dist/cli/create/templates/ssg/cer.config.ts.tpl +2 -0
- package/dist/cli/create/templates/ssg/package.json.tpl +5 -3
- package/dist/cli/create/templates/ssr/package.json.tpl +5 -3
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/plugin/build-ssg.d.ts +22 -6
- package/dist/plugin/build-ssg.d.ts.map +1 -1
- package/dist/plugin/build-ssg.js +227 -17
- package/dist/plugin/build-ssg.js.map +1 -1
- package/dist/plugin/content/parser.d.ts.map +1 -1
- package/dist/plugin/content/parser.js +54 -10
- package/dist/plugin/content/parser.js.map +1 -1
- package/dist/plugin/dev-server.d.ts +4 -1
- package/dist/plugin/dev-server.d.ts.map +1 -1
- package/dist/plugin/dev-server.js.map +1 -1
- package/dist/plugin/dts-generator.d.ts.map +1 -1
- package/dist/plugin/dts-generator.js +50 -8
- package/dist/plugin/dts-generator.js.map +1 -1
- package/dist/plugin/generated-dir.d.ts +2 -0
- package/dist/plugin/generated-dir.d.ts.map +1 -1
- package/dist/plugin/generated-dir.js +17 -6
- package/dist/plugin/generated-dir.js.map +1 -1
- package/dist/plugin/html-post-process.d.ts +6 -0
- package/dist/plugin/html-post-process.d.ts.map +1 -1
- package/dist/plugin/html-post-process.js +24 -0
- package/dist/plugin/html-post-process.js.map +1 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +60 -13
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/transforms/auto-import.d.ts.map +1 -1
- package/dist/plugin/transforms/auto-import.js +7 -0
- package/dist/plugin/transforms/auto-import.js.map +1 -1
- package/dist/plugin/transforms/prune-runtime-css.d.ts +8 -0
- package/dist/plugin/transforms/prune-runtime-css.d.ts.map +1 -0
- package/dist/plugin/transforms/prune-runtime-css.js +40 -0
- package/dist/plugin/transforms/prune-runtime-css.js.map +1 -0
- package/dist/runtime/app-template.d.ts +1 -1
- package/dist/runtime/app-template.d.ts.map +1 -1
- package/dist/runtime/app-template.js +206 -36
- package/dist/runtime/app-template.js.map +1 -1
- package/dist/runtime/composables/index.d.ts +4 -0
- package/dist/runtime/composables/index.d.ts.map +1 -1
- package/dist/runtime/composables/index.js +2 -0
- package/dist/runtime/composables/index.js.map +1 -1
- package/dist/runtime/composables/use-active-headings.d.ts +24 -0
- package/dist/runtime/composables/use-active-headings.d.ts.map +1 -0
- package/dist/runtime/composables/use-active-headings.js +112 -0
- package/dist/runtime/composables/use-active-headings.js.map +1 -0
- package/dist/runtime/composables/use-content-page.d.ts +45 -0
- package/dist/runtime/composables/use-content-page.d.ts.map +1 -0
- package/dist/runtime/composables/use-content-page.js +179 -0
- package/dist/runtime/composables/use-content-page.js.map +1 -0
- package/dist/runtime/composables/use-content-search.d.ts.map +1 -1
- package/dist/runtime/composables/use-content-search.js +1 -5
- package/dist/runtime/composables/use-content-search.js.map +1 -1
- package/dist/runtime/composables/use-fetch.d.ts +2 -1
- package/dist/runtime/composables/use-fetch.d.ts.map +1 -1
- package/dist/runtime/composables/use-fetch.js +112 -43
- package/dist/runtime/composables/use-fetch.js.map +1 -1
- package/dist/runtime/composables/use-route.d.ts.map +1 -1
- package/dist/runtime/composables/use-route.js +39 -11
- package/dist/runtime/composables/use-route.js.map +1 -1
- package/dist/runtime/content/client.js +2 -2
- package/dist/runtime/content/client.js.map +1 -1
- package/dist/runtime/entry-server-template.d.ts +16 -1
- package/dist/runtime/entry-server-template.d.ts.map +1 -1
- package/dist/runtime/entry-server-template.js +120 -13
- package/dist/runtime/entry-server-template.js.map +1 -1
- package/dist/types/config.d.ts +45 -4
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js.map +1 -1
- package/dist/types/middleware.d.ts +2 -2
- package/dist/types/middleware.d.ts.map +1 -1
- package/package.json +22 -19
- package/.github/copilot-instructions.md +0 -169
- package/.github/workflows/publish.yml +0 -257
- package/.nvmrc +0 -1
- package/CHANGELOG.md +0 -236
- package/CLAUDE.md +0 -113
- package/commits.txt +0 -1
- package/cypress.config.ts +0 -16
- package/docs/authentication.md +0 -285
- package/docs/cli.md +0 -324
- package/docs/components.md +0 -237
- package/docs/composables.md +0 -907
- package/docs/configuration.md +0 -696
- package/docs/content.md +0 -570
- package/docs/data-loading.md +0 -336
- package/docs/getting-started.md +0 -237
- package/docs/head-management.md +0 -212
- package/docs/i18n.md +0 -159
- package/docs/layouts.md +0 -224
- package/docs/middleware.md +0 -234
- package/docs/plugins.md +0 -170
- package/docs/rendering-modes.md +0 -377
- package/docs/routing.md +0 -485
- package/docs/server-api.md +0 -253
- package/docs/testing.md +0 -455
- package/docs/use-fetch.md +0 -183
- package/e2e/cypress/e2e/api.cy.ts +0 -123
- package/e2e/cypress/e2e/async-component.cy.ts +0 -27
- package/e2e/cypress/e2e/component-splitting.cy.ts +0 -50
- package/e2e/cypress/e2e/content.cy.ts +0 -425
- package/e2e/cypress/e2e/cookie.cy.ts +0 -85
- package/e2e/cypress/e2e/data.cy.ts +0 -158
- package/e2e/cypress/e2e/error-boundary.cy.ts +0 -88
- package/e2e/cypress/e2e/fouc.cy.ts +0 -254
- package/e2e/cypress/e2e/group-meta.cy.ts +0 -36
- package/e2e/cypress/e2e/head.cy.ts +0 -89
- package/e2e/cypress/e2e/i18n.cy.ts +0 -79
- package/e2e/cypress/e2e/interactive.cy.ts +0 -137
- package/e2e/cypress/e2e/isr-nested-runtime.cy.ts +0 -102
- package/e2e/cypress/e2e/jit-css-custom-colors.cy.ts +0 -43
- package/e2e/cypress/e2e/middleware-chain.cy.ts +0 -89
- package/e2e/cypress/e2e/middleware-status.cy.ts +0 -30
- package/e2e/cypress/e2e/middleware.cy.ts +0 -45
- package/e2e/cypress/e2e/navigate.cy.ts +0 -39
- package/e2e/cypress/e2e/observability.cy.ts +0 -77
- package/e2e/cypress/e2e/per-route-error.cy.ts +0 -42
- package/e2e/cypress/e2e/per-route-render.cy.ts +0 -70
- package/e2e/cypress/e2e/preview-hardening.cy.ts +0 -88
- package/e2e/cypress/e2e/routes.cy.ts +0 -128
- package/e2e/cypress/e2e/seo-meta.cy.ts +0 -108
- package/e2e/cypress/e2e/server-middleware.cy.ts +0 -46
- package/e2e/cypress/e2e/session-rotation.cy.ts +0 -25
- package/e2e/cypress/e2e/session.cy.ts +0 -73
- package/e2e/cypress/e2e/ssr-render-error.cy.ts +0 -68
- package/e2e/cypress/e2e/synthetic-404.cy.ts +0 -45
- package/e2e/cypress/e2e/use-page-data.cy.ts +0 -122
- package/e2e/cypress/e2e/use-state.cy.ts +0 -138
- package/e2e/cypress/support/commands.ts +0 -120
- package/e2e/cypress/support/e2e.ts +0 -10
- package/e2e/cypress/tsconfig.json +0 -14
- package/e2e/kitchen-sink/app/components/ks-badge.ts +0 -8
- package/e2e/kitchen-sink/app/composables/useKsCounter.ts +0 -9
- package/e2e/kitchen-sink/app/error.ts +0 -18
- package/e2e/kitchen-sink/app/layouts/admin.ts +0 -13
- package/e2e/kitchen-sink/app/layouts/default.ts +0 -25
- package/e2e/kitchen-sink/app/layouts/group.ts +0 -9
- package/e2e/kitchen-sink/app/layouts/minimal.ts +0 -7
- package/e2e/kitchen-sink/app/loading.ts +0 -9
- package/e2e/kitchen-sink/app/middleware/auth.ts +0 -9
- package/e2e/kitchen-sink/app/middleware/custom-log.ts +0 -4
- package/e2e/kitchen-sink/app/middleware/group-auth.ts +0 -7
- package/e2e/kitchen-sink/app/middleware/logger.ts +0 -14
- package/e2e/kitchen-sink/app/pages/(auth)/login.ts +0 -13
- package/e2e/kitchen-sink/app/pages/(auth)/protected.ts +0 -16
- package/e2e/kitchen-sink/app/pages/404.ts +0 -9
- package/e2e/kitchen-sink/app/pages/about.ts +0 -17
- package/e2e/kitchen-sink/app/pages/admin/_layout.ts +0 -1
- package/e2e/kitchen-sink/app/pages/admin/dashboard.ts +0 -11
- package/e2e/kitchen-sink/app/pages/async-component-error-test.ts +0 -18
- package/e2e/kitchen-sink/app/pages/async-component-test.ts +0 -18
- package/e2e/kitchen-sink/app/pages/blog/[slug].ts +0 -59
- package/e2e/kitchen-sink/app/pages/blog/index.ts +0 -51
- package/e2e/kitchen-sink/app/pages/content-blog.ts +0 -37
- package/e2e/kitchen-sink/app/pages/content-doc.ts +0 -42
- package/e2e/kitchen-sink/app/pages/content-fallback.ts +0 -36
- package/e2e/kitchen-sink/app/pages/content-guides.ts +0 -35
- package/e2e/kitchen-sink/app/pages/content-index.ts +0 -39
- package/e2e/kitchen-sink/app/pages/content-search.ts +0 -36
- package/e2e/kitchen-sink/app/pages/cookie-test.ts +0 -22
- package/e2e/kitchen-sink/app/pages/counter.ts +0 -17
- package/e2e/kitchen-sink/app/pages/group-auth-blocked.ts +0 -9
- package/e2e/kitchen-sink/app/pages/group-meta-test/_layout.ts +0 -6
- package/e2e/kitchen-sink/app/pages/group-meta-test/custom-mw.ts +0 -14
- package/e2e/kitchen-sink/app/pages/group-meta-test/page.ts +0 -9
- package/e2e/kitchen-sink/app/pages/group-meta-test/protected.ts +0 -8
- package/e2e/kitchen-sink/app/pages/head.ts +0 -20
- package/e2e/kitchen-sink/app/pages/i18n-test.ts +0 -14
- package/e2e/kitchen-sink/app/pages/index.ts +0 -27
- package/e2e/kitchen-sink/app/pages/isr-test.ts +0 -17
- package/e2e/kitchen-sink/app/pages/items/[id].ts +0 -20
- package/e2e/kitchen-sink/app/pages/jit-css-custom-colors-test.ts +0 -14
- package/e2e/kitchen-sink/app/pages/loader-error-test.ts +0 -13
- package/e2e/kitchen-sink/app/pages/loader-props-test.ts +0 -19
- package/e2e/kitchen-sink/app/pages/loader-response-error-test.ts +0 -13
- package/e2e/kitchen-sink/app/pages/middleware-chain-test.ts +0 -12
- package/e2e/kitchen-sink/app/pages/middleware-status-test.ts +0 -9
- package/e2e/kitchen-sink/app/pages/navigate-test.ts +0 -16
- package/e2e/kitchen-sink/app/pages/observability-test.ts +0 -25
- package/e2e/kitchen-sink/app/pages/per-route-error-test.error.ts +0 -13
- package/e2e/kitchen-sink/app/pages/per-route-error-test.ts +0 -15
- package/e2e/kitchen-sink/app/pages/plugin-dsd-test.ts +0 -10
- package/e2e/kitchen-sink/app/pages/render-error-test.ts +0 -12
- package/e2e/kitchen-sink/app/pages/render-server-test.ts +0 -12
- package/e2e/kitchen-sink/app/pages/render-spa-test.ts +0 -12
- package/e2e/kitchen-sink/app/pages/route-info.ts +0 -14
- package/e2e/kitchen-sink/app/pages/seo-test.ts +0 -23
- package/e2e/kitchen-sink/app/pages/session-rotation-test.ts +0 -25
- package/e2e/kitchen-sink/app/pages/use-state-test.ts +0 -37
- package/e2e/kitchen-sink/app/plugins/01.setup.ts +0 -7
- package/e2e/kitchen-sink/app/plugins/02.ks-plugin-components.ts +0 -27
- package/e2e/kitchen-sink/cer-auto-imports.d.ts +0 -51
- package/e2e/kitchen-sink/cer-env.d.ts +0 -35
- package/e2e/kitchen-sink/cer-tsconfig.json +0 -30
- package/e2e/kitchen-sink/cer.config.ts +0 -43
- package/e2e/kitchen-sink/content/01.guides/01.index.md +0 -8
- package/e2e/kitchen-sink/content/01.guides/02.intro.md +0 -8
- package/e2e/kitchen-sink/content/01.guides/10.advanced.md +0 -8
- package/e2e/kitchen-sink/content/blog/2026-04-01-hello.md +0 -26
- package/e2e/kitchen-sink/content/blog/2026-04-02-draft.md +0 -10
- package/e2e/kitchen-sink/content/blog/index.md +0 -8
- package/e2e/kitchen-sink/content/blog/no-frontmatter.md +0 -7
- package/e2e/kitchen-sink/content/docs/getting-started.md +0 -48
- package/e2e/kitchen-sink/content/index.md +0 -16
- package/e2e/kitchen-sink/server/api/echo.ts +0 -12
- package/e2e/kitchen-sink/server/api/health.ts +0 -3
- package/e2e/kitchen-sink/server/api/posts/[slug].ts +0 -11
- package/e2e/kitchen-sink/server/api/posts/index.ts +0 -5
- package/e2e/kitchen-sink/server/api/session.ts +0 -23
- package/e2e/kitchen-sink/server/data/posts.ts +0 -21
- package/e2e/kitchen-sink/server/middleware/01-headers.ts +0 -6
- package/e2e/kitchen-sink/server/middleware/02-status-test.ts +0 -10
- package/e2e/kitchen-sink/tsconfig.json +0 -3
- package/e2e/scripts/clean.mjs +0 -14
- package/eslint.config.ts +0 -22
- package/src/__tests__/cli/adapters/cloudflare-worker.integration.test.ts +0 -132
- package/src/__tests__/cli/adapters/cloudflare.test.ts +0 -332
- package/src/__tests__/cli/adapters/netlify-bridge.integration.test.ts +0 -139
- package/src/__tests__/cli/adapters/netlify.test.ts +0 -286
- package/src/__tests__/cli/adapters/vercel-launcher.integration.test.ts +0 -129
- package/src/__tests__/cli/adapters/vercel.test.ts +0 -263
- package/src/__tests__/cli/preview-hardening.test.ts +0 -265
- package/src/__tests__/cli/preview-isr.test.ts +0 -320
- package/src/__tests__/index.test.ts +0 -21
- package/src/__tests__/plugin/app-template.test.ts +0 -166
- package/src/__tests__/plugin/build-ssg-render.test.ts +0 -155
- package/src/__tests__/plugin/build-ssg.test.ts +0 -598
- package/src/__tests__/plugin/build-ssr.test.ts +0 -192
- package/src/__tests__/plugin/cer-app-plugin.test.ts +0 -552
- package/src/__tests__/plugin/content/emitter.test.ts +0 -117
- package/src/__tests__/plugin/content/loader.test.ts +0 -154
- package/src/__tests__/plugin/content/parser.test.ts +0 -381
- package/src/__tests__/plugin/content/path-utils.test.ts +0 -69
- package/src/__tests__/plugin/content/search.test.ts +0 -119
- package/src/__tests__/plugin/dev-server.test.ts +0 -813
- package/src/__tests__/plugin/dts-generator.test.ts +0 -394
- package/src/__tests__/plugin/entry-server-template.test.ts +0 -385
- package/src/__tests__/plugin/generated-dir.test.ts +0 -144
- package/src/__tests__/plugin/html-post-process.test.ts +0 -146
- package/src/__tests__/plugin/path-utils.test.ts +0 -411
- package/src/__tests__/plugin/resolve-config.test.ts +0 -233
- package/src/__tests__/plugin/scanner.test.ts +0 -186
- package/src/__tests__/plugin/transforms/auto-import.test.ts +0 -510
- package/src/__tests__/plugin/transforms/head-inject.test.ts +0 -178
- package/src/__tests__/plugin/virtual/composables.test.ts +0 -57
- package/src/__tests__/plugin/virtual/content-components.test.ts +0 -66
- package/src/__tests__/plugin/virtual/error.test.ts +0 -71
- package/src/__tests__/plugin/virtual/layouts.test.ts +0 -70
- package/src/__tests__/plugin/virtual/loading.test.ts +0 -72
- package/src/__tests__/plugin/virtual/middleware.test.ts +0 -83
- package/src/__tests__/plugin/virtual/plugins.test.ts +0 -129
- package/src/__tests__/plugin/virtual/routes.test.ts +0 -884
- package/src/__tests__/plugin/virtual/server-api.test.ts +0 -164
- package/src/__tests__/plugin/virtual/server-middleware.test.ts +0 -102
- package/src/__tests__/runtime/app-template.test.ts +0 -208
- package/src/__tests__/runtime/define-middleware.test.ts +0 -64
- package/src/__tests__/runtime/define-server-middleware.test.ts +0 -54
- package/src/__tests__/runtime/entry-client-template.test.ts +0 -61
- package/src/__tests__/runtime/isr-handler.test.ts +0 -338
- package/src/__tests__/runtime/oauth/handler.test.ts +0 -358
- package/src/__tests__/runtime/oauth/providers.test.ts +0 -47
- package/src/__tests__/runtime/oauth-index.test.ts +0 -43
- package/src/__tests__/runtime/use-auth.test.ts +0 -169
- package/src/__tests__/runtime/use-content-search-composable.test.ts +0 -405
- package/src/__tests__/runtime/use-content-search.test.ts +0 -163
- package/src/__tests__/runtime/use-content.test.ts +0 -226
- package/src/__tests__/runtime/use-cookie.test.ts +0 -277
- package/src/__tests__/runtime/use-fetch-component.test.ts +0 -214
- package/src/__tests__/runtime/use-fetch.test.ts +0 -377
- package/src/__tests__/runtime/use-head.test.ts +0 -311
- package/src/__tests__/runtime/use-inject-client.test.ts +0 -67
- package/src/__tests__/runtime/use-inject.test.ts +0 -66
- package/src/__tests__/runtime/use-locale.test.ts +0 -152
- package/src/__tests__/runtime/use-navigate.test.ts +0 -121
- package/src/__tests__/runtime/use-page-data.test.ts +0 -298
- package/src/__tests__/runtime/use-route.test.ts +0 -156
- package/src/__tests__/runtime/use-runtime-config.test.ts +0 -182
- package/src/__tests__/runtime/use-seo-meta.test.ts +0 -109
- package/src/__tests__/runtime/use-session.test.ts +0 -320
- package/src/__tests__/runtime/use-state.test.ts +0 -340
- package/src/__tests__/types/config.test.ts +0 -18
- package/src/cli/adapters/cloudflare.ts +0 -335
- package/src/cli/adapters/netlify.ts +0 -326
- package/src/cli/adapters/vercel.ts +0 -311
- package/src/cli/commands/adapt.ts +0 -84
- package/src/cli/commands/build.ts +0 -165
- package/src/cli/commands/dev.ts +0 -125
- package/src/cli/commands/generate.ts +0 -91
- package/src/cli/commands/preview-isr.ts +0 -172
- package/src/cli/commands/preview.ts +0 -523
- package/src/cli/create/index.ts +0 -275
- package/src/cli/create/templates/shared/.gitignore.tpl +0 -25
- package/src/cli/create/templates/shared/app/layouts/default.ts.tpl +0 -15
- package/src/cli/create/templates/shared/app/pages/index.ts.tpl +0 -8
- package/src/cli/create/templates/shared/index.html.tpl +0 -12
- package/src/cli/create/templates/shared/tsconfig.json.tpl +0 -6
- package/src/cli/create/templates/spa/cer.config.ts.tpl +0 -6
- package/src/cli/create/templates/spa/package.json.tpl +0 -18
- package/src/cli/create/templates/ssg/cer.config.ts.tpl +0 -10
- package/src/cli/create/templates/ssg/package.json.tpl +0 -19
- package/src/cli/create/templates/ssr/cer.config.ts.tpl +0 -6
- package/src/cli/create/templates/ssr/package.json.tpl +0 -18
- package/src/cli/index.ts +0 -22
- package/src/index.ts +0 -20
- package/src/plugin/build-ssg.ts +0 -403
- package/src/plugin/build-ssr.ts +0 -134
- package/src/plugin/content/emitter.ts +0 -50
- package/src/plugin/content/index.ts +0 -233
- package/src/plugin/content/parser.ts +0 -259
- package/src/plugin/content/path-utils.ts +0 -55
- package/src/plugin/content/scanner.ts +0 -26
- package/src/plugin/content/search.ts +0 -28
- package/src/plugin/dev-server.ts +0 -379
- package/src/plugin/dts-generator.ts +0 -273
- package/src/plugin/generated-dir.ts +0 -121
- package/src/plugin/html-post-process.ts +0 -96
- package/src/plugin/index.ts +0 -584
- package/src/plugin/path-utils.ts +0 -186
- package/src/plugin/scanner.ts +0 -65
- package/src/plugin/transforms/auto-import.ts +0 -206
- package/src/plugin/transforms/head-inject.ts +0 -161
- package/src/plugin/virtual/composables.ts +0 -28
- package/src/plugin/virtual/content-components.ts +0 -83
- package/src/plugin/virtual/error.ts +0 -34
- package/src/plugin/virtual/layouts.ts +0 -41
- package/src/plugin/virtual/loading.ts +0 -32
- package/src/plugin/virtual/middleware.ts +0 -45
- package/src/plugin/virtual/plugins.ts +0 -46
- package/src/plugin/virtual/routes.ts +0 -514
- package/src/plugin/virtual/server-api.ts +0 -85
- package/src/plugin/virtual/server-middleware.ts +0 -44
- package/src/runtime/app-template.ts +0 -377
- package/src/runtime/composables/define-middleware.ts +0 -17
- package/src/runtime/composables/define-server-middleware.ts +0 -18
- package/src/runtime/composables/index.ts +0 -27
- package/src/runtime/composables/use-auth.ts +0 -125
- package/src/runtime/composables/use-content-search.ts +0 -205
- package/src/runtime/composables/use-content.ts +0 -146
- package/src/runtime/composables/use-cookie.ts +0 -135
- package/src/runtime/composables/use-fetch.ts +0 -438
- package/src/runtime/composables/use-head.ts +0 -234
- package/src/runtime/composables/use-inject.ts +0 -49
- package/src/runtime/composables/use-locale.ts +0 -109
- package/src/runtime/composables/use-navigate.ts +0 -58
- package/src/runtime/composables/use-page-data.ts +0 -93
- package/src/runtime/composables/use-route.ts +0 -71
- package/src/runtime/composables/use-runtime-config.ts +0 -123
- package/src/runtime/composables/use-seo-meta.ts +0 -80
- package/src/runtime/composables/use-session.ts +0 -186
- package/src/runtime/composables/use-state.ts +0 -92
- package/src/runtime/content/client.ts +0 -168
- package/src/runtime/entry-client-template.ts +0 -39
- package/src/runtime/entry-server-template.ts +0 -493
- package/src/runtime/isr-handler.ts +0 -184
- package/src/runtime/oauth/handler.ts +0 -407
- package/src/runtime/oauth/index.ts +0 -49
- package/src/runtime/oauth/providers.ts +0 -38
- package/src/types/api.ts +0 -40
- package/src/types/config.ts +0 -379
- package/src/types/content.ts +0 -66
- package/src/types/index.ts +0 -7
- package/src/types/middleware.ts +0 -63
- package/src/types/page.ts +0 -117
- package/src/types/plugin.ts +0 -34
- package/tsconfig.build.json +0 -10
- package/tsconfig.json +0 -19
- package/vitest.config.ts +0 -33
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAuth handler tests — handleOAuthInitiate, handleOAuthCallback, handleOAuthLogout.
|
|
3
|
-
*
|
|
4
|
-
* All tests run inside a __CER_REQ_STORE__ AsyncLocalStorage context so
|
|
5
|
-
* useSession() works correctly. fetch() is mocked throughout.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
9
|
-
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
10
|
-
|
|
11
|
-
// ─── Mock useSession ─────────────────────────────────────────────────────────
|
|
12
|
-
|
|
13
|
-
let _mockSessionData: Record<string, unknown> | null = null
|
|
14
|
-
const _setCookies: string[] = []
|
|
15
|
-
|
|
16
|
-
const mockSession = {
|
|
17
|
-
get: vi.fn(async () => _mockSessionData),
|
|
18
|
-
set: vi.fn(async (data: unknown) => { _mockSessionData = data as Record<string, unknown> }),
|
|
19
|
-
clear: vi.fn(async () => { _mockSessionData = null }),
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
vi.mock('../../../runtime/composables/use-session.js', () => ({
|
|
23
|
-
useSession: vi.fn(() => mockSession),
|
|
24
|
-
}))
|
|
25
|
-
|
|
26
|
-
import { handleOAuthInitiate, handleOAuthCallback, handleOAuthLogout } from '../../../runtime/oauth/handler.js'
|
|
27
|
-
import type { ResolvedAuthConfig } from '../../../runtime/oauth/handler.js'
|
|
28
|
-
|
|
29
|
-
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
30
|
-
|
|
31
|
-
const g = globalThis as Record<string, unknown>
|
|
32
|
-
|
|
33
|
-
const AUTH_CONFIG: ResolvedAuthConfig = {
|
|
34
|
-
providers: {
|
|
35
|
-
google: {
|
|
36
|
-
clientId: 'google-client-id',
|
|
37
|
-
clientSecret: 'google-client-secret',
|
|
38
|
-
},
|
|
39
|
-
github: {
|
|
40
|
-
clientId: 'github-client-id',
|
|
41
|
-
clientSecret: 'github-client-secret',
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
redirectAfterLogin: '/dashboard',
|
|
45
|
-
redirectAfterLogout: '/',
|
|
46
|
-
sessionKey: 'auth',
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function makeReqRes(url = '/api/auth/google') {
|
|
50
|
-
const headers: Record<string, string> = { host: 'localhost:3000' }
|
|
51
|
-
const req = {
|
|
52
|
-
url,
|
|
53
|
-
headers,
|
|
54
|
-
} as unknown as IncomingMessage
|
|
55
|
-
|
|
56
|
-
const responseHeaders: Record<string, string> = {}
|
|
57
|
-
let statusCode = 200
|
|
58
|
-
let body = ''
|
|
59
|
-
|
|
60
|
-
const res = {
|
|
61
|
-
get statusCode() { return statusCode },
|
|
62
|
-
set statusCode(v: number) { statusCode = v },
|
|
63
|
-
setHeader(name: string, value: string) {
|
|
64
|
-
if (name.toLowerCase() === 'set-cookie') {
|
|
65
|
-
_setCookies.push(value)
|
|
66
|
-
}
|
|
67
|
-
responseHeaders[name.toLowerCase()] = value
|
|
68
|
-
},
|
|
69
|
-
getHeader(name: string) { return responseHeaders[name.toLowerCase()] },
|
|
70
|
-
end(chunk?: string) { if (chunk) body = chunk },
|
|
71
|
-
_responseHeaders: responseHeaders,
|
|
72
|
-
_body: () => body,
|
|
73
|
-
} as unknown as ServerResponse & { _responseHeaders: Record<string, string>; _body: () => string }
|
|
74
|
-
|
|
75
|
-
return { req, res }
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function runInStore(req: unknown, res: unknown, fn: () => Promise<void>): Promise<void> {
|
|
79
|
-
const { AsyncLocalStorage } = require('node:async_hooks')
|
|
80
|
-
const store = new AsyncLocalStorage()
|
|
81
|
-
g['__CER_REQ_STORE__'] = store
|
|
82
|
-
return store.run({ req, res }, fn)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// ─── handleOAuthInitiate ──────────────────────────────────────────────────────
|
|
86
|
-
|
|
87
|
-
describe('handleOAuthInitiate()', () => {
|
|
88
|
-
beforeEach(() => {
|
|
89
|
-
vi.resetAllMocks()
|
|
90
|
-
_mockSessionData = null
|
|
91
|
-
_setCookies.length = 0
|
|
92
|
-
mockSession.get.mockImplementation(async () => _mockSessionData)
|
|
93
|
-
mockSession.set.mockImplementation(async (d: unknown) => { _mockSessionData = d as Record<string, unknown> })
|
|
94
|
-
mockSession.clear.mockImplementation(async () => { _mockSessionData = null })
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
afterEach(() => {
|
|
98
|
-
delete g['__CER_REQ_STORE__']
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
it('redirects to Google authorization URL', async () => {
|
|
102
|
-
const { req, res } = makeReqRes()
|
|
103
|
-
await runInStore(req, res, async () => {
|
|
104
|
-
await handleOAuthInitiate(req, res, 'google', AUTH_CONFIG)
|
|
105
|
-
})
|
|
106
|
-
expect((res as unknown as { _responseHeaders: Record<string, string> })._responseHeaders['location'])
|
|
107
|
-
.toMatch(/^https:\/\/accounts\.google\.com/)
|
|
108
|
-
expect((res as unknown as { statusCode: number }).statusCode).toBe(302)
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
it('includes PKCE code_challenge for Google', async () => {
|
|
112
|
-
const { req, res } = makeReqRes()
|
|
113
|
-
await runInStore(req, res, async () => {
|
|
114
|
-
await handleOAuthInitiate(req, res, 'google', AUTH_CONFIG)
|
|
115
|
-
})
|
|
116
|
-
const location: string = (res as unknown as { _responseHeaders: Record<string, string> })._responseHeaders['location']
|
|
117
|
-
const params = new URLSearchParams(location.split('?')[1])
|
|
118
|
-
expect(params.get('code_challenge')).toBeTruthy()
|
|
119
|
-
expect(params.get('code_challenge_method')).toBe('S256')
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
it('does NOT include PKCE for GitHub (pkce: false)', async () => {
|
|
123
|
-
const { req, res } = makeReqRes('/api/auth/github')
|
|
124
|
-
await runInStore(req, res, async () => {
|
|
125
|
-
await handleOAuthInitiate(req, res, 'github', AUTH_CONFIG)
|
|
126
|
-
})
|
|
127
|
-
const location: string = (res as unknown as { _responseHeaders: Record<string, string> })._responseHeaders['location']
|
|
128
|
-
const params = new URLSearchParams(location.split('?')[1])
|
|
129
|
-
expect(params.get('code_challenge')).toBeNull()
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
it('includes state param in redirect URL', async () => {
|
|
133
|
-
const { req, res } = makeReqRes()
|
|
134
|
-
await runInStore(req, res, async () => {
|
|
135
|
-
await handleOAuthInitiate(req, res, 'google', AUTH_CONFIG)
|
|
136
|
-
})
|
|
137
|
-
const location: string = (res as unknown as { _responseHeaders: Record<string, string> })._responseHeaders['location']
|
|
138
|
-
const params = new URLSearchParams(location.split('?')[1])
|
|
139
|
-
expect(params.get('state')).toBeTruthy()
|
|
140
|
-
expect(params.get('state')!.length).toBeGreaterThan(0)
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
it('stores state + verifier in pkce session', async () => {
|
|
144
|
-
const { req, res } = makeReqRes()
|
|
145
|
-
await runInStore(req, res, async () => {
|
|
146
|
-
await handleOAuthInitiate(req, res, 'google', AUTH_CONFIG)
|
|
147
|
-
})
|
|
148
|
-
expect(mockSession.set).toHaveBeenCalledWith(
|
|
149
|
-
expect.objectContaining({ state: expect.any(String), verifier: expect.any(String), provider: 'google' }),
|
|
150
|
-
)
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
it('returns 404 for an unknown provider', async () => {
|
|
154
|
-
const { req, res } = makeReqRes()
|
|
155
|
-
await runInStore(req, res, async () => {
|
|
156
|
-
await handleOAuthInitiate(req, res, 'unknown-provider', AUTH_CONFIG)
|
|
157
|
-
})
|
|
158
|
-
expect((res as unknown as { statusCode: number }).statusCode).toBe(404)
|
|
159
|
-
})
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
// ─── handleOAuthCallback ──────────────────────────────────────────────────────
|
|
163
|
-
|
|
164
|
-
describe('handleOAuthCallback()', () => {
|
|
165
|
-
const state = 'test-state-value'
|
|
166
|
-
const pkceData = { state, verifier: 'test-verifier', provider: 'google' }
|
|
167
|
-
|
|
168
|
-
beforeEach(() => {
|
|
169
|
-
vi.resetAllMocks()
|
|
170
|
-
_mockSessionData = pkceData
|
|
171
|
-
mockSession.get.mockImplementation(async () => _mockSessionData)
|
|
172
|
-
mockSession.set.mockImplementation(async (d: unknown) => { _mockSessionData = d as Record<string, unknown> })
|
|
173
|
-
mockSession.clear.mockImplementation(async () => { _mockSessionData = null })
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
afterEach(() => {
|
|
177
|
-
delete g['__CER_REQ_STORE__']
|
|
178
|
-
vi.unstubAllGlobals()
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
it('exchanges code for tokens, fetches profile, stores user, and redirects', async () => {
|
|
182
|
-
const googleUser = { id: '123', name: 'Alice', email: 'alice@test.com', picture: 'https://pic.example.com/a.jpg' }
|
|
183
|
-
vi.stubGlobal('fetch', vi.fn()
|
|
184
|
-
.mockResolvedValueOnce({ ok: true, json: async () => ({ access_token: 'tok', token_type: 'Bearer' }) })
|
|
185
|
-
.mockResolvedValueOnce({ ok: true, json: async () => googleUser }),
|
|
186
|
-
)
|
|
187
|
-
|
|
188
|
-
const { req, res } = makeReqRes(`/api/auth/callback/google?code=auth-code&state=${state}`)
|
|
189
|
-
await runInStore(req, res, async () => {
|
|
190
|
-
await handleOAuthCallback(req, res, 'google', AUTH_CONFIG)
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
expect((res as unknown as { statusCode: number }).statusCode).toBe(302)
|
|
194
|
-
expect((res as unknown as { _responseHeaders: Record<string, string> })._responseHeaders['location'])
|
|
195
|
-
.toBe('/dashboard')
|
|
196
|
-
|
|
197
|
-
expect(mockSession.set).toHaveBeenCalledWith(
|
|
198
|
-
expect.objectContaining({ provider: 'google', id: '123', name: 'Alice' }),
|
|
199
|
-
)
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
it('returns 400 when state param is missing', async () => {
|
|
203
|
-
const { req, res } = makeReqRes('/api/auth/callback/google?code=auth-code')
|
|
204
|
-
await runInStore(req, res, async () => {
|
|
205
|
-
await handleOAuthCallback(req, res, 'google', AUTH_CONFIG)
|
|
206
|
-
})
|
|
207
|
-
expect((res as unknown as { statusCode: number }).statusCode).toBe(400)
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
it('returns 400 when state does not match pkce session', async () => {
|
|
211
|
-
const { req, res } = makeReqRes('/api/auth/callback/google?code=auth-code&state=wrong-state')
|
|
212
|
-
await runInStore(req, res, async () => {
|
|
213
|
-
await handleOAuthCallback(req, res, 'google', AUTH_CONFIG)
|
|
214
|
-
})
|
|
215
|
-
expect((res as unknown as { statusCode: number }).statusCode).toBe(400)
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
it('returns 400 when pkce session is absent (expired)', async () => {
|
|
219
|
-
_mockSessionData = null
|
|
220
|
-
|
|
221
|
-
const { req, res } = makeReqRes(`/api/auth/callback/google?code=auth-code&state=${state}`)
|
|
222
|
-
await runInStore(req, res, async () => {
|
|
223
|
-
await handleOAuthCallback(req, res, 'google', AUTH_CONFIG)
|
|
224
|
-
})
|
|
225
|
-
expect((res as unknown as { statusCode: number }).statusCode).toBe(400)
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
it('returns 502 when token exchange fails', async () => {
|
|
229
|
-
vi.stubGlobal('fetch', vi.fn().mockResolvedValueOnce({ ok: false, status: 401, statusText: 'Unauthorized' }))
|
|
230
|
-
|
|
231
|
-
const { req, res } = makeReqRes(`/api/auth/callback/google?code=bad-code&state=${state}`)
|
|
232
|
-
await runInStore(req, res, async () => {
|
|
233
|
-
await handleOAuthCallback(req, res, 'google', AUTH_CONFIG)
|
|
234
|
-
})
|
|
235
|
-
expect((res as unknown as { statusCode: number }).statusCode).toBe(502)
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
it('normalises GitHub profile correctly', async () => {
|
|
239
|
-
const ghPkce = { state, verifier: 'v', provider: 'github' }
|
|
240
|
-
_mockSessionData = ghPkce
|
|
241
|
-
const ghUser = { id: 456, login: 'bob', name: null, email: 'bob@git.com', avatar_url: 'https://avatars.example.com/bob' }
|
|
242
|
-
|
|
243
|
-
vi.stubGlobal('fetch', vi.fn()
|
|
244
|
-
.mockResolvedValueOnce({ ok: true, json: async () => ({ access_token: 'tok', token_type: 'token' }) })
|
|
245
|
-
.mockResolvedValueOnce({ ok: true, json: async () => ghUser }),
|
|
246
|
-
)
|
|
247
|
-
|
|
248
|
-
const { req, res } = makeReqRes(`/api/auth/callback/github?code=gh-code&state=${state}`)
|
|
249
|
-
await runInStore(req, res, async () => {
|
|
250
|
-
await handleOAuthCallback(req, res, 'github', AUTH_CONFIG)
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
expect(mockSession.set).toHaveBeenCalledWith(
|
|
254
|
-
expect.objectContaining({ provider: 'github', id: '456', name: 'bob' }),
|
|
255
|
-
)
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
it('returns 400 when code param is missing', async () => {
|
|
259
|
-
const { req, res } = makeReqRes(`/api/auth/callback/google?state=${state}`)
|
|
260
|
-
await runInStore(req, res, async () => {
|
|
261
|
-
await handleOAuthCallback(req, res, 'google', AUTH_CONFIG)
|
|
262
|
-
})
|
|
263
|
-
expect((res as unknown as { statusCode: number }).statusCode).toBe(400)
|
|
264
|
-
})
|
|
265
|
-
|
|
266
|
-
it('returns 502 when token exchange response contains invalid JSON', async () => {
|
|
267
|
-
vi.stubGlobal('fetch', vi.fn().mockResolvedValueOnce({
|
|
268
|
-
ok: true,
|
|
269
|
-
json: async () => { throw new SyntaxError('Unexpected token') },
|
|
270
|
-
}))
|
|
271
|
-
|
|
272
|
-
const { req, res } = makeReqRes(`/api/auth/callback/google?code=auth-code&state=${state}`)
|
|
273
|
-
await runInStore(req, res, async () => {
|
|
274
|
-
await handleOAuthCallback(req, res, 'google', AUTH_CONFIG)
|
|
275
|
-
})
|
|
276
|
-
expect((res as unknown as { statusCode: number }).statusCode).toBe(502)
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
it('returns 502 when user-info response contains invalid JSON', async () => {
|
|
280
|
-
vi.stubGlobal('fetch', vi.fn()
|
|
281
|
-
.mockResolvedValueOnce({ ok: true, json: async () => ({ access_token: 'tok', token_type: 'Bearer' }) })
|
|
282
|
-
.mockResolvedValueOnce({ ok: true, json: async () => { throw new SyntaxError('Unexpected token') } }),
|
|
283
|
-
)
|
|
284
|
-
|
|
285
|
-
const { req, res } = makeReqRes(`/api/auth/callback/google?code=auth-code&state=${state}`)
|
|
286
|
-
await runInStore(req, res, async () => {
|
|
287
|
-
await handleOAuthCallback(req, res, 'google', AUTH_CONFIG)
|
|
288
|
-
})
|
|
289
|
-
expect((res as unknown as { statusCode: number }).statusCode).toBe(502)
|
|
290
|
-
})
|
|
291
|
-
|
|
292
|
-
it('returns 502 when user-info request fails (network error)', async () => {
|
|
293
|
-
vi.stubGlobal('fetch', vi.fn()
|
|
294
|
-
.mockResolvedValueOnce({ ok: true, json: async () => ({ access_token: 'tok', token_type: 'Bearer' }) })
|
|
295
|
-
.mockRejectedValueOnce(new TypeError('fetch failed')),
|
|
296
|
-
)
|
|
297
|
-
|
|
298
|
-
const { req, res } = makeReqRes(`/api/auth/callback/google?code=auth-code&state=${state}`)
|
|
299
|
-
await runInStore(req, res, async () => {
|
|
300
|
-
await handleOAuthCallback(req, res, 'google', AUTH_CONFIG)
|
|
301
|
-
})
|
|
302
|
-
expect((res as unknown as { statusCode: number }).statusCode).toBe(502)
|
|
303
|
-
})
|
|
304
|
-
|
|
305
|
-
it('returns 404 for unknown provider in callback', async () => {
|
|
306
|
-
const unknownPkce = { state, verifier: 'v', provider: 'unknown-provider' }
|
|
307
|
-
_mockSessionData = unknownPkce
|
|
308
|
-
|
|
309
|
-
const { req, res } = makeReqRes(`/api/auth/callback/unknown-provider?code=code&state=${state}`)
|
|
310
|
-
await runInStore(req, res, async () => {
|
|
311
|
-
await handleOAuthCallback(req, res, 'unknown-provider', AUTH_CONFIG)
|
|
312
|
-
})
|
|
313
|
-
expect((res as unknown as { statusCode: number }).statusCode).toBe(404)
|
|
314
|
-
})
|
|
315
|
-
|
|
316
|
-
it('uses custom scope from provider config', async () => {
|
|
317
|
-
const customConfig: ResolvedAuthConfig = {
|
|
318
|
-
...AUTH_CONFIG,
|
|
319
|
-
providers: {
|
|
320
|
-
google: {
|
|
321
|
-
clientId: 'google-client-id',
|
|
322
|
-
clientSecret: 'google-client-secret',
|
|
323
|
-
scope: ['email'],
|
|
324
|
-
},
|
|
325
|
-
},
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
const { req, res } = makeReqRes('/api/auth/google')
|
|
329
|
-
await runInStore(req, res, async () => {
|
|
330
|
-
await handleOAuthInitiate(req, res, 'google', customConfig)
|
|
331
|
-
})
|
|
332
|
-
const location: string = (res as unknown as { _responseHeaders: Record<string, string> })._responseHeaders['location']
|
|
333
|
-
const params = new URLSearchParams(location.split('?')[1])
|
|
334
|
-
expect(params.get('scope')).toBe('email')
|
|
335
|
-
})
|
|
336
|
-
})
|
|
337
|
-
|
|
338
|
-
// ─── handleOAuthLogout ────────────────────────────────────────────────────────
|
|
339
|
-
|
|
340
|
-
describe('handleOAuthLogout()', () => {
|
|
341
|
-
afterEach(() => {
|
|
342
|
-
delete g['__CER_REQ_STORE__']
|
|
343
|
-
})
|
|
344
|
-
|
|
345
|
-
it('clears auth session and redirects to redirectAfterLogout', async () => {
|
|
346
|
-
_mockSessionData = { provider: 'google', id: '1' }
|
|
347
|
-
mockSession.clear.mockImplementation(async () => { _mockSessionData = null })
|
|
348
|
-
|
|
349
|
-
const { req, res } = makeReqRes('/api/auth/logout')
|
|
350
|
-
await runInStore(req, res, async () => {
|
|
351
|
-
await handleOAuthLogout(req, res, AUTH_CONFIG)
|
|
352
|
-
})
|
|
353
|
-
|
|
354
|
-
expect(mockSession.clear).toHaveBeenCalled()
|
|
355
|
-
expect((res as unknown as { statusCode: number }).statusCode).toBe(302)
|
|
356
|
-
expect((res as unknown as { _responseHeaders: Record<string, string> })._responseHeaders['location']).toBe('/')
|
|
357
|
-
})
|
|
358
|
-
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OAUTH_PROVIDERS constant tests.
|
|
3
|
-
*
|
|
4
|
-
* Verifies that all built-in providers expose the required endpoint fields
|
|
5
|
-
* and that the pkce flag is set correctly.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { describe, it, expect } from 'vitest'
|
|
9
|
-
import { OAUTH_PROVIDERS } from '../../../runtime/oauth/providers.js'
|
|
10
|
-
|
|
11
|
-
describe('OAUTH_PROVIDERS', () => {
|
|
12
|
-
const REQUIRED_FIELDS = ['authorizationUrl', 'tokenUrl', 'userInfoUrl', 'defaultScopes', 'pkce']
|
|
13
|
-
|
|
14
|
-
for (const provider of ['google', 'github', 'discord']) {
|
|
15
|
-
describe(provider, () => {
|
|
16
|
-
it('has all required fields', () => {
|
|
17
|
-
const p = OAUTH_PROVIDERS[provider]
|
|
18
|
-
for (const field of REQUIRED_FIELDS) {
|
|
19
|
-
expect(p).toHaveProperty(field)
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('authorizationUrl is a valid HTTPS URL', () => {
|
|
24
|
-
expect(OAUTH_PROVIDERS[provider].authorizationUrl).toMatch(/^https:\/\//)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('tokenUrl is a valid HTTPS URL', () => {
|
|
28
|
-
expect(OAUTH_PROVIDERS[provider].tokenUrl).toMatch(/^https:\/\//)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
it('userInfoUrl is a valid HTTPS URL', () => {
|
|
32
|
-
expect(OAUTH_PROVIDERS[provider].userInfoUrl).toMatch(/^https:\/\//)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('defaultScopes is a non-empty array', () => {
|
|
36
|
-
expect(Array.isArray(OAUTH_PROVIDERS[provider].defaultScopes)).toBe(true)
|
|
37
|
-
expect(OAUTH_PROVIDERS[provider].defaultScopes.length).toBeGreaterThan(0)
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
it('github pkce is false (GitHub does not support PKCE)', () => {
|
|
43
|
-
expect(OAUTH_PROVIDERS.google.pkce).toBe(true)
|
|
44
|
-
expect(OAUTH_PROVIDERS.github.pkce).toBe(false)
|
|
45
|
-
expect(OAUTH_PROVIDERS.discord.pkce).toBe(true)
|
|
46
|
-
})
|
|
47
|
-
})
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import { defineOAuthProvider } from '../../runtime/oauth/index.js'
|
|
3
|
-
|
|
4
|
-
describe('defineOAuthProvider', () => {
|
|
5
|
-
it('returns the config object unchanged', () => {
|
|
6
|
-
const cfg = { clientId: 'id', clientSecret: 'secret' }
|
|
7
|
-
expect(defineOAuthProvider(cfg)).toBe(cfg)
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('preserves clientId and clientSecret', () => {
|
|
11
|
-
const result = defineOAuthProvider({ clientId: 'my-id', clientSecret: 'my-secret' })
|
|
12
|
-
expect(result.clientId).toBe('my-id')
|
|
13
|
-
expect(result.clientSecret).toBe('my-secret')
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it('preserves optional scope array', () => {
|
|
17
|
-
const result = defineOAuthProvider({
|
|
18
|
-
clientId: 'id',
|
|
19
|
-
clientSecret: 'secret',
|
|
20
|
-
scope: ['read:user', 'user:email'],
|
|
21
|
-
})
|
|
22
|
-
expect(result.scope).toEqual(['read:user', 'user:email'])
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('preserves optional endpoint URLs', () => {
|
|
26
|
-
const result = defineOAuthProvider({
|
|
27
|
-
clientId: 'id',
|
|
28
|
-
clientSecret: 'secret',
|
|
29
|
-
authorizationUrl: 'https://auth.example.com/authorize',
|
|
30
|
-
tokenUrl: 'https://auth.example.com/token',
|
|
31
|
-
userInfoUrl: 'https://auth.example.com/userinfo',
|
|
32
|
-
})
|
|
33
|
-
expect(result.authorizationUrl).toBe('https://auth.example.com/authorize')
|
|
34
|
-
expect(result.tokenUrl).toBe('https://auth.example.com/token')
|
|
35
|
-
expect(result.userInfoUrl).toBe('https://auth.example.com/userinfo')
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('works as a pass-through for TypeScript inference (returns same reference)', () => {
|
|
39
|
-
const input = { clientId: 'cid', clientSecret: 'csecret', scope: ['openid'] }
|
|
40
|
-
const output = defineOAuthProvider(input)
|
|
41
|
-
expect(output).toBe(input)
|
|
42
|
-
})
|
|
43
|
-
})
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useAuth() composable tests.
|
|
3
|
-
*
|
|
4
|
-
* Covers both the server path (AsyncLocalStorage __CER_AUTH_STORE__) and
|
|
5
|
-
* the client hydration path (globalThis.__CER_AUTH_USER__).
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
9
|
-
|
|
10
|
-
// ─── Mock useSession so logout() server-path can be exercised without real crypto ──
|
|
11
|
-
|
|
12
|
-
vi.mock('../../runtime/composables/use-session.js', () => ({
|
|
13
|
-
useSession: vi.fn(() => ({
|
|
14
|
-
get: vi.fn(async () => null),
|
|
15
|
-
set: vi.fn(async () => {}),
|
|
16
|
-
clear: vi.fn(async () => {}),
|
|
17
|
-
})),
|
|
18
|
-
}))
|
|
19
|
-
|
|
20
|
-
import { useAuth } from '../../runtime/composables/use-auth.js'
|
|
21
|
-
import { useSession } from '../../runtime/composables/use-session.js'
|
|
22
|
-
|
|
23
|
-
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
24
|
-
|
|
25
|
-
const g = globalThis as Record<string, unknown>
|
|
26
|
-
|
|
27
|
-
function makeAuthStore(user: unknown) {
|
|
28
|
-
const { AsyncLocalStorage } = require('node:async_hooks')
|
|
29
|
-
const store = new AsyncLocalStorage()
|
|
30
|
-
store.enterWith(user)
|
|
31
|
-
return store
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// ─── Server path ──────────────────────────────────────────────────────────────
|
|
35
|
-
|
|
36
|
-
describe('useAuth() — server path (__CER_AUTH_STORE__)', () => {
|
|
37
|
-
let _orig: unknown
|
|
38
|
-
|
|
39
|
-
beforeEach(() => {
|
|
40
|
-
_orig = g['__CER_AUTH_STORE__']
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
afterEach(() => {
|
|
44
|
-
g['__CER_AUTH_STORE__'] = _orig
|
|
45
|
-
// Ensure window is absent
|
|
46
|
-
if ('window' in g) delete (g as { window?: unknown })['window']
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('returns the user from the ALS store', () => {
|
|
50
|
-
const user = { provider: 'google', id: '1', name: 'Alice' }
|
|
51
|
-
g['__CER_AUTH_STORE__'] = makeAuthStore(user)
|
|
52
|
-
|
|
53
|
-
const { user: u, loggedIn } = useAuth()
|
|
54
|
-
expect(u).toEqual(user)
|
|
55
|
-
expect(loggedIn).toBe(true)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('returns null user when store holds null', () => {
|
|
59
|
-
g['__CER_AUTH_STORE__'] = makeAuthStore(null)
|
|
60
|
-
|
|
61
|
-
const { user, loggedIn } = useAuth()
|
|
62
|
-
expect(user).toBeNull()
|
|
63
|
-
expect(loggedIn).toBe(false)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it('logout() calls useSession().clear() on server', async () => {
|
|
67
|
-
const clearFn = vi.fn(async () => {})
|
|
68
|
-
;(useSession as ReturnType<typeof vi.fn>).mockReturnValueOnce({
|
|
69
|
-
get: vi.fn(async () => null),
|
|
70
|
-
set: vi.fn(async () => {}),
|
|
71
|
-
clear: clearFn,
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
const store = makeAuthStore({ provider: 'github', id: '2' })
|
|
75
|
-
g['__CER_AUTH_STORE__'] = store
|
|
76
|
-
|
|
77
|
-
const auth = useAuth()
|
|
78
|
-
await auth.logout()
|
|
79
|
-
|
|
80
|
-
expect(clearFn).toHaveBeenCalled()
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('logout() sets user to null after clearing session', async () => {
|
|
84
|
-
g['__CER_AUTH_STORE__'] = makeAuthStore({ provider: 'github', id: '2' })
|
|
85
|
-
|
|
86
|
-
const auth = useAuth()
|
|
87
|
-
expect(auth.user).not.toBeNull()
|
|
88
|
-
|
|
89
|
-
await auth.logout()
|
|
90
|
-
expect(auth.user).toBeNull()
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
it('login() is a no-op on the server (no window)', () => {
|
|
94
|
-
g['__CER_AUTH_STORE__'] = makeAuthStore(null)
|
|
95
|
-
// Should not throw
|
|
96
|
-
expect(() => useAuth().login('google')).not.toThrow()
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
it('uses custom sessionKey when provided', async () => {
|
|
100
|
-
const clearFn = vi.fn(async () => {})
|
|
101
|
-
;(useSession as ReturnType<typeof vi.fn>).mockReturnValueOnce({
|
|
102
|
-
get: vi.fn(async () => null),
|
|
103
|
-
set: vi.fn(async () => {}),
|
|
104
|
-
clear: clearFn,
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
g['__CER_AUTH_STORE__'] = makeAuthStore({ provider: 'github', id: '5' })
|
|
108
|
-
|
|
109
|
-
await useAuth('custom-session-key').logout()
|
|
110
|
-
|
|
111
|
-
expect(useSession as ReturnType<typeof vi.fn>).toHaveBeenCalledWith(
|
|
112
|
-
expect.objectContaining({ name: 'custom-session-key' }),
|
|
113
|
-
)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('logout() propagates error when session.clear() rejects', async () => {
|
|
117
|
-
;(useSession as ReturnType<typeof vi.fn>).mockReturnValueOnce({
|
|
118
|
-
get: vi.fn(async () => null),
|
|
119
|
-
set: vi.fn(async () => {}),
|
|
120
|
-
clear: vi.fn(async () => { throw new Error('cookie error') }),
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
g['__CER_AUTH_STORE__'] = makeAuthStore({ provider: 'google', id: '6' })
|
|
124
|
-
|
|
125
|
-
await expect(useAuth().logout()).rejects.toThrow('cookie error')
|
|
126
|
-
})
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
// ─── Client path ──────────────────────────────────────────────────────────────
|
|
130
|
-
|
|
131
|
-
describe('useAuth() — client path (__CER_AUTH_USER__)', () => {
|
|
132
|
-
beforeEach(() => {
|
|
133
|
-
delete g['__CER_AUTH_STORE__']
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
afterEach(() => {
|
|
137
|
-
delete g['__CER_AUTH_USER__']
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
it('reads user from globalThis.__CER_AUTH_USER__', () => {
|
|
141
|
-
const user = { provider: 'discord', id: '3', name: 'Bob' }
|
|
142
|
-
g['__CER_AUTH_USER__'] = user
|
|
143
|
-
|
|
144
|
-
const { user: u, loggedIn } = useAuth()
|
|
145
|
-
expect(u).toEqual(user)
|
|
146
|
-
expect(loggedIn).toBe(true)
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
it('returns null when __CER_AUTH_USER__ is not set', () => {
|
|
150
|
-
const { user, loggedIn } = useAuth()
|
|
151
|
-
expect(user).toBeNull()
|
|
152
|
-
expect(loggedIn).toBe(false)
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
it('login() redirects to /api/auth/:provider on the client', () => {
|
|
156
|
-
let redirectedTo = ''
|
|
157
|
-
;(g as Record<string, unknown>)['window'] = {
|
|
158
|
-
location: {
|
|
159
|
-
get href() { return redirectedTo },
|
|
160
|
-
set href(v: string) { redirectedTo = v },
|
|
161
|
-
},
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
useAuth().login('google')
|
|
165
|
-
expect(redirectedTo).toBe('/api/auth/google')
|
|
166
|
-
|
|
167
|
-
delete (g as Record<string, unknown>)['window']
|
|
168
|
-
})
|
|
169
|
-
})
|