alepha@docs:~/docs/packages/alepha/server$
cat cookies.md
1 min read
Last commit:

#Alepha - Server Cookies

#Installation

Part of the alepha package. Import from alepha/server/cookies.

npm install alepha

#Overview

Provides HTTP cookie management capabilities for server requests and responses with type-safe cookie primitives.

The server-cookies module enables declarative cookie handling using the $cookie primitive on class properties. It offers automatic cookie parsing, secure cookie configuration, and seamless integration with server routes for managing user sessions, preferences, and authentication tokens.

#API Reference

#Primitives

Primitives are functions that define and configure various aspects of your application. They follow the convention of starting with $ and return configured primitive instances.

For more details, see the Primitives documentation.

#$cookie()

Creates a browser-side cookie primitive for client-side cookie management.

Browser-specific version of $cookie that uses document.cookie API. Supports type-safe cookie operations with schema validation but excludes encryption/signing (use server-side $cookie for secure operations).

Note: This is the browser version - encryption, signing, and compression are not supported.

ts
 1class ClientCookies { 2  preferences = $cookie({ 3    name: "user-prefs", 4    schema: t.object({ theme: t.text(), language: t.text() }), 5    ttl: [30, "days"] 6  }); 7  8  savePreferences() { 9    this.preferences.set({ theme: "dark", language: "en" });10  }11 12  getPreferences() {13    return this.preferences.get() ?? { theme: "light", language: "en" };14  }15}

#$cookie()

Declares a type-safe, configurable HTTP cookie. This primitive provides methods to get, set, and delete the cookie within the server request/response cycle.

On This Page
No headings found...
ready
mainTypeScript
UTF-8packages_alepha_server_cookies.md