Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ jobs:
@tanstack/react-router@1.132.0 @tanstack/react-start@1.169.0 \
react-router@7.0.0 next@16.0.0 expo-router@5.0.2 \
expo-secure-store@14.2.0 react-native@0.79.0 effect@4.1.0 \
@monarcode/effetch@0.1.0-rc.4
@monarcode/effetch@0.1.0

# The API snapshot holds for the lockfile's peers, whose types some
# declarations are inferred from.
- name: Build and test
env:
SESSION_KIT_API_SNAPSHOT: "off"
run: pnpm run build && pnpm test && pnpm run test:types

examples:
Expand Down Expand Up @@ -121,6 +125,59 @@ jobs:
EXPO_OFFLINE: 1
EXPO_NO_TELEMETRY: 1

# The packed package as an app installs it, outside the workspace: its
# types under the oldest and newest TypeScript, and a sign-in on the
# Node.js versions the other jobs don't run (scripts/compat.sh).
compatibility:
name: ${{ matrix.name }}
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
- name: typescript 5.4 (oldest supported)
mode: typescript
target: "5.4"
- name: typescript 7
mode: typescript
target: "7"
- name: node.js 20
mode: runtime
node: 20
- name: node.js 22
mode: runtime
node: 22
steps:
- name: Check out repository
uses: actions/checkout@v7

- name: Set up pnpm
uses: pnpm/action-setup@v6
with:
version: 10.12.1

- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: 24
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build the package
run: pnpm run build

- name: Set up Node.js ${{ matrix.node }}
if: matrix.node
uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node }}

- name: Check the installed package
run: bash scripts/compat.sh ${{ matrix.mode }} ${{ matrix.target }}

site:
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
62 changes: 53 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_dispatch:
inputs:
version:
description: Alpha or release candidate version already committed in package.json (without v)
description: Version already committed in package.json, without v (0.1.0, 0.1.0-rc.0, 0.1.0-alpha.3)
required: true
type: string

Expand All @@ -22,6 +22,8 @@ jobs:
prepare:
runs-on: ubuntu-latest
timeout-minutes: 15
outputs:
dist_tag: ${{ steps.release.outputs.dist_tag }}
steps:
- name: Require main
env:
Expand All @@ -41,6 +43,7 @@ jobs:
node-version: 24
package-manager-cache: false
- name: Validate version and release notes
id: release
env:
RELEASE_VERSION: ${{ inputs.version }}
run: |
Expand All @@ -49,6 +52,8 @@ jobs:
echo "The release tag already exists."
exit 1
fi
DIST_TAG=$(jq -er .distTag "$RUNNER_TEMP/release/release.json")
echo "dist_tag=$DIST_TAG" >> "$GITHUB_OUTPUT"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build and test
Expand All @@ -68,7 +73,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
contents: read
id-token: write
steps:
- name: Set up Node.js
Expand All @@ -87,25 +92,64 @@ jobs:
- name: Publish to npm
env:
RELEASE_VERSION: ${{ inputs.version }}
run: npm publish "$RUNNER_TEMP/release/monarcode-session-kit-$RELEASE_VERSION.tgz" --tag latest --access public --ignore-scripts
- name: Create GitHub prerelease and tag
run: |
DIST_TAG=$(jq -er .distTag "$RUNNER_TEMP/release/release.json")
npm publish "$RUNNER_TEMP/release/monarcode-session-kit-$RELEASE_VERSION.tgz" --tag "$DIST_TAG" --access public --ignore-scripts

# Jobs of their own after publishing, so a failure can be rerun without
# publishing again.
github-release:
needs: publish
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
steps:
- name: Download verified release artifact
uses: actions/download-artifact@v8
with:
name: session-kit-release
path: ${{ runner.temp }}/release
- name: Create GitHub release and tag
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RELEASE_VERSION: ${{ inputs.version }}
RELEASE_COMMIT: ${{ github.sha }}
run: |
PRERELEASE=$(jq -r '.prerelease | if type == "boolean" then tostring else error("release.json has no prerelease flag") end' "$RUNNER_TEMP/release/release.json")
if [ "$PRERELEASE" = true ]; then
KIND=(--prerelease --latest=false)
else
KIND=(--latest)
fi
gh release create "v$RELEASE_VERSION" \
--target "$RELEASE_COMMIT" \
--title "v$RELEASE_VERSION" \
--prerelease --latest=false \
"${KIND[@]}" \
--notes-file "$RUNNER_TEMP/release/release-notes.md"
# Cloudflare Pages deploys the `site` branch as the live docs, so the
# docs change with the release that publishes their API.

# Cloudflare Pages deploys the `site` branch as the live docs, so they
# change with the release `npm install` gets: one published to `latest`.
# A release to `next` is previewed on `main`'s deploy instead. Forced,
# because a docs fix cherry-picked onto `site` between releases has been
# merged to `main` first, so a release made after it includes it. That
# also means a rerun after a newer release would move the docs back.
docs-site:
needs: [prepare, publish]
if: needs.prepare.outputs.dist_tag == 'latest'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
steps:
- name: Move the docs site to the release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_COMMIT: ${{ github.sha }}
run: |
gh api -X PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/site" \
-f sha="$RELEASE_COMMIT" -F force=true
if ! gh api -X PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/site" \
-f sha="$RELEASE_COMMIT" -F force=true; then
echo "::error::The package is published, but the docs site wasn't moved. Move it with: git push --force origin $RELEASE_COMMIT:refs/heads/site. A release that changes workflow files always fails here. Otherwise, rerunning this job can work, but not after a newer release."
exit 1
fi
24 changes: 18 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Consumers import from the root and from subpaths:
decisions ("Decisions made", "Open decisions"). Read it before any work,
and add each new decision there.
- `.stash/` also holds API drafts for work in progress (for example
`alpha6-lock-api.md`).
`alpha6-lock-api.md`), and `releasing.md`, how a release is published.
- `.stash/` is gitignored and lives on the maintainer's machine. Never commit
it, and never link to it from the README, the docs or the code. If it's
missing, ask for it.
Expand Down Expand Up @@ -61,11 +61,14 @@ Consumers import from the root and from subpaths:
8. **Ask before changing a settled decision** (`.stash/roadmap.md`,
"Decisions made"). If the code shows a decision can't work, stop and
explain why rather than working around it.
9. **No compatibility shims during alpha.** Make clean breaking changes and
note each one in `CHANGELOG.md`. From `0.1.0-rc.0` the public API is
frozen: no renames, removals or changed signatures of anything a subpath
exports (functions, types, options, `AuthErrorCode`s). Additive changes
only, and only with the maintainer's agreement.
9. **0.1.x keeps the versioning promise** (Compatibility, "Versioning"): no
renames, removals or changed signatures of anything a subpath exports
(functions, types, options, `AuthErrorCode`s); no change to the format of
the saved session, the session cookie or the session route; and no
dropped support for a peer version, a TypeScript version or a runtime.
Changes are additive only, and only with the maintainer's agreement. A
breaking change waits for 0.2.0: make it cleanly, without compatibility
shims, and note it in `CHANGELOG.md`.
10. **CI never calls dummyjson.com.** Examples may use it; tests mock it.

## Code style
Expand Down Expand Up @@ -163,6 +166,15 @@ developers, not for us. Every comment ships: keep it short, plain and true.
NodeNext and Bundler resolution. Use `// @ts-expect-error` with a reason.
- Type tests also run with `exactOptionalPropertyTypes` off, as most apps
have it.
- `tests/api.test.ts` compares the published declarations, without
comments, with `tests/public-api.snapshot`: the subpaths, what they
export, and every declaration and import their types reach. A JSDoc edit
leaves it alone, and so does a change to internal declarations. When the
API changes on purpose, run `pnpm run api:update` and check its diff: in
0.1.x it may only add (rule 9). A public declaration that moves to another
file shows as removed and added. CI skips it on the oldest peers
(`SESSION_KIT_API_SNAPSHOT=off`), since some declarations are inferred
from a peer's types.
- The site's pages live in `site/content/docs/(latest)/`. A `ts` or `tsx`
block with `title="path"` is an example, and each page's examples are
type-checked as one small app by `scripts/check-docs.mjs`, together with
Expand Down
54 changes: 51 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,54 @@
# Changelog

## Unreleased
## 0.1.0

The first stable release. From here, an update within 0.1.x doesn't break
code written for 0.1.0, apart from the one exception that
[Versioning](https://session-kit.monarcode.dev/docs/reference/compatibility#versioning)
lists, which follows Effect's unstable HTTP modules. The changes since
0.1.0-rc.3:

### Changed

- The documentation site moved to https://session-kit.monarcode.dev. The old
address, https://session-kit.pages.dev, still serves it.
- Stable versions are published to npm's `latest` tag. Once 0.1.0 is out,
prereleases are published to `next`, so `npm install @monarcode/session-kit`
keeps getting the stable version, and the docs site keeps showing its
docs.
- **Breaking for effetch users:** the `@monarcode/effetch` peer range is
`^0.1.0`, up from `^0.1.0-rc.4`, now that effetch 0.1.0 is stable.
`./effetch` works as before. If your app is on an effetch release
candidate, upgrade it to 0.1.0, which effetch-query 0.1.0 needs too.
- CI now installs the packed package in an app of its own and runs it on
Node.js 20 and 22, and compiles its types with TypeScript 5.4 (the oldest
supported) and 7. It also compares the published API with a snapshot, so
a 0.1.x update can't change it by accident.
[Compatibility](https://session-kit.monarcode.dev/docs/reference/compatibility#what-ci-tests)
lists what CI covers.

### Fixed

- **`yield* Auth` and `Auth.use` give your registered client.** In an app
that registers its client, the `Auth` service from `./effect` was typed as
a client with an `unknown` user, so a session read through it had to be
cast. The static Effects, such as `Auth.session`, were already typed
correctly. Apps that don't register a client are unaffected. On the
server, the service is still the request's session, not your browser
client, so use only `Auth`'s Effects there.

### Docs

- Session kit has a versioning policy, on the
[Compatibility](https://session-kit.monarcode.dev/docs/reference/compatibility#versioning)
page and in the README. An update within 0.1.x doesn't break code written
for 0.1.0: the API, the format of saved sessions, the session cookie and
the session route, and the supported peers, TypeScript versions and
runtimes stay as they are, and breaking changes wait for 0.2.0. An update
can add an `AuthErrorCode` for something new. The exception follows
Effect, which marks its HTTP modules unstable: when they change, a 0.1.x
update can change the types `/effetch` gets from them, or raise its oldest
`effect`. The release-candidate notes are gone.
- A link to any page of the docs site shows its own preview image, with the
page's title, description and place in the docs. Each page names its
canonical URL on the new domain and links to its Markdown version.
Expand All @@ -18,6 +58,14 @@
- Docs pages are served at the URLs the site links to, without a trailing
slash, so following a link no longer redirects. A URL with a trailing
slash still works: it redirects to the one without.
- A page's Markdown copy, and `llms-full.txt`, no longer repeat a type's
heading and description above its table of members.
- Session kit has a security policy, in
[`SECURITY.md`](https://github.com/monarcode/session-kit/blob/main/SECURITY.md):
report a vulnerability privately, from the repository's Security tab. The
Security page links to it.
- The `docs/` folder is gone. Its files only pointed to the docs site's
pages, which have everything they had.

## 0.1.0-rc.3

Expand Down Expand Up @@ -655,7 +703,7 @@ later `0.1` releases only add to it.
`Auth.updateUser` (which also takes an Effect that fetches the user) and
`Auth.changes`, a `Stream` of the state. They fail with `AuthFailure`, a
tagged error carrying the `AuthErrorCode` as `code`; `INVALID_OPTIONS` is
a defect. The [Effect guide](./docs/effect.md) walks through it.
a defect. The [Effect guide](https://session-kit.monarcode.dev/docs/effect) walks through it.
- `@monarcode/session-kit/effetch` adds `sessionBearer({ baseUrl })`, a
plugin for `@monarcode/effetch` (an optional peer dependency) with
`createAuthFetch`'s behaviour: it sends the access token only to
Expand Down Expand Up @@ -762,7 +810,7 @@ later `0.1` releases only add to it.
`unavailable` render prop, is exported from `/react-router` and `/expo`.
- Optional peer dependencies for Expo SDK 53 and later: `expo-router`,
`expo-secure-store`, `expo-file-system`, and `react-native`.
- An [Expo Router guide](./docs/expo.md) and an
- An [Expo Router guide](https://session-kit.monarcode.dev/docs/setups/expo) and an
[`expo-router` example app](./examples/expo-router) for iOS and Android.

### Fixed
Expand Down
16 changes: 13 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ example:
storage that settles every operation late, removals last, to catch ordering
bugs. `pnpm run build:examples` builds the package and every example app.

`bash scripts/compat.sh typescript 5.4` and `bash scripts/compat.sh runtime`
check the packed package as an app installs it, with a TypeScript version
or the Node.js on your `PATH`. CI runs them with TypeScript 5.4 and 7, and
on Node.js 20 and 22.

The tests also compare the published API with `tests/public-api.snapshot`,
so a change to an export's types fails them. When the change is intended,
run `pnpm run api:update`, and check in its diff that it only adds to the
API: within 0.1.x, nothing may break code written for 0.1.0.

Tests are TypeScript files that Node runs directly. Behavior tests are split
by area and share the browser mocks in `tests/helpers.ts`. React tests mount
real React DOM, TanStack Router, and React Router in jsdom, and server tests
Expand All @@ -59,9 +69,9 @@ pnpm --dir site run dev
also catches MDX syntax errors and type errors in Twoslash blocks, which
`check` doesn't build.

The live site shows the newest release. Older release lines are kept as
snapshots in `site/content/docs/<line>/`, made by `scripts/snapshot-docs.mjs`.
[RELEASING.md](./RELEASING.md) covers both.
The live site shows the release on npm's `latest` tag. Older release lines
are kept as snapshots in `site/content/docs/<line>/`, made by
`scripts/snapshot-docs.mjs`.

## Try a local build

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ server with TanStack Start, Next.js, and React Router, and comes with an
[Effect](https://effect.website) service and an
[effetch](https://github.com/monarcode/effetch) plugin.

> **Release candidate.** The API is frozen for 0.1, and later 0.1 releases
> only add to it. See the [release notes](./CHANGELOG.md).
> **Versioning.** An update within 0.1.x doesn't break code written for
> 0.1.0, and keeps restoring the sessions your users saved. Breaking changes
> wait for 0.2.0, with notes in the [changelog](./CHANGELOG.md).
> [Versioning](https://session-kit.monarcode.dev/docs/reference/compatibility#versioning)
> lists what an update can change.

**Documentation: [session-kit.monarcode.dev](https://session-kit.monarcode.dev)**

Expand All @@ -48,9 +51,6 @@ or newer (Effect asks for 5.9), and
[Compatibility](https://session-kit.monarcode.dev/docs/reference/compatibility)
lists the supported versions.

Release candidates are published to the `latest` tag, so pin an exact version
and read the [release notes](./CHANGELOG.md) before upgrading.

## Quick start

Your backend keeps its sign-in and refresh endpoints. Session kit takes the
Expand Down
Loading
Loading