Stone.jsDocs
Paradigm

Essentials

Cookies

Cookies are read from the incoming event and written on the outgoing response, both through a small, uniform API. As with everything else, your handler works with values, not with raw header strings.

#Reading cookies

app/Session.tsts
show (event: IncomingHttpEvent) {
  const theme = event.cookies.get('theme', 'light')   // name, default
  const seen = event.cookies.has('seen')
  return { theme, seen }
}

#Setting cookies

Set a cookie on a response, with the options a cookie should have in production: an expiry, httpOnly, secure, and a sameSite policy.

app/Session.tsts
import { jsonHttpResponse } from '@stone-js/http-core'

const response = jsonHttpResponse({ ok: true })
response.setCookie('theme', 'dark', {
  maxAge: 60 * 60 * 24 * 365,   // one year, in seconds
  httpOnly: true,
  secure: true,
  sameSite: 'lax'
})
return response
OptionTypeDefaultDescription
maxAgenumber·Lifetime in seconds.
expiresDate·Absolute expiry (alternative to maxAge).
httpOnlybooleanfalseHide the cookie from client-side JavaScript.
securebooleanfalseSend only over HTTPS.
sameSite'strict' | 'lax' | 'none''lax'Cross-site sending policy.
pathstring'/'The paths the cookie applies to.
domainstring·The host the cookie is scoped to.

Stone.js

Your app exists in every runtime. Until you run it.

An open-source project by Stone Foundation
Created by Mr. Stone (Evens Pierre)