Skip to content

feat(kit): add /kit export with addControlledCookie helper#323

Open
BlueBazze wants to merge 7 commits into
dargmuesli:mainfrom
BlueBazze:main
Open

feat(kit): add /kit export with addControlledCookie helper#323
BlueBazze wants to merge 7 commits into
dargmuesli:mainfrom
BlueBazze:main

Conversation

@BlueBazze
Copy link
Copy Markdown
Contributor

@BlueBazze BlueBazze commented Apr 15, 2026

📚 Description

Adds a @dargmuesli/nuxt-cookie-control/kit subpath export exposing addControlledCookie, providing other Nuxt modules to helpers to register cookies with cookie-control programmatically during setup.

import {
  addControlledCookie,
  CookieType,
} from "@dargmuesli/nuxt-cookie-control/kit";

export default defineNuxtModule({
  setup() {
    if (hasNuxtModule("@dargmuesli/nuxt-cookie-control")) {
      addControlledCookie({ id: "my-cookie", name: "My Cookie" });
      addControlledCookie(
        { id: "session", name: "Session" },
        CookieType.NECESSARY,
      );
    }
  },
});

Use case for this could be modules like nuxt-auth-utils defining the session cookie if cookie-control is present.

📝 Checklist

  • The PR's title follows the Conventional Commit format

Note

  • Code was initially written by ai, then redone by me.
  • The build.config.ts can be wrapped in the in the defineBuildConfig but pnpm requires the explicit dependency to be declared, i didnt want to introduce dependencies for this. That is your decision if and when needed.
  • I havent tested this in a real scenario only as a local module in playground.

Copilot AI review requested due to automatic review settings April 15, 2026 10:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new @dargmuesli/nuxt-cookie-control/kit subpath export intended for other Nuxt modules to programmatically register cookies into this module’s configuration during module setup.

Changes:

  • Introduces src/kit.ts with an addControlledCookie helper and re-exports of CookieType/Cookie.
  • Exposes the new ./kit entry via package.json exports + typesVersions.
  • Adds module-builder config and a playground module to demonstrate usage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/kit.ts Adds addControlledCookie helper to mutate nuxt.options.cookieControl.cookies programmatically.
playground/modules/auth.ts Adds a playground module example that uses the new kit entry.
package.json Adds ./kit subpath export and TS type resolution for it.
build.config.ts Configures module-builder entries to produce the new kit build output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/kit.ts
Comment thread build.config.ts Outdated
Comment thread playground/modules/auth.ts Outdated
BlueBazze and others added 3 commits April 15, 2026 12:45
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
dargmuesli
dargmuesli previously approved these changes Apr 15, 2026
Copy link
Copy Markdown
Owner

@dargmuesli dargmuesli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM 💚
Just some prettier lint logs remaining

@BlueBazze
Copy link
Copy Markdown
Contributor Author

Great, so it sounds like you are on board with this feature.
Today i tried a real integration with this.

The module order was important, even though moduleOptions was only added to runtime config in the modules:done hook.

Since other modules modified the nuxt options, these options were not being passed into cookie-control moduleOptions, but rather they lived in nuxt.options.cookieControl.

  1. The /kit could start using hooks instead of nuxt options.
  2. cookie-control could drop moduleOptions and reference nuxt.options directly
  3. The modules:done hook could dedupe arrays in the options before assigning the merged product to runtime config.

I actually thought moduleOptions was a proxy to the unctx context from the options.

Anyway, hooks will most likely become unnecessary. Since in modules:done when referencing nuxt.options you get the options updated by other modules. For now i have pushed a dedupe of the cookie arrays which work good enough for this feature. Then it is up to you if you want to replace moduleOptions with nuxt.options in the module setup. Which would also expose the options set in setup to the user in the options viewer devtools.

You can see my "test" on https://github.com/BlueBazze/cookie-control-kit-test

Copy link
Copy Markdown
Owner

@dargmuesli dargmuesli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sorry, I forgot to hit submit on this review

Comment thread src/kit.ts
* addControlledCookie({ id: 'analytics', name: 'Analytics' }, CookieType.OPTIONAL)
* ```
*/
export const addControlledCookie = (
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe name this

Suggested change
export const addControlledCookie = (
export const addCookieControl = (

I prefer "hierarchical" naming. Imagine someone typing addCook and seeing addCookie and addCookieControl (if those were to exist; both related to cookies).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants