diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 000ca82a..574dc79f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -451,24 +451,20 @@ jobs: severity: 'CRITICAL' # Credentials preflight (workflow_dispatch only). Proves, without - # publishing, what the tag run will need: an npm identity that can publish - # in the @checkgate scope, parseable pub.dev credentials, and a PyPI trusted - # publisher matching this workflow and environment. Prints no secret. + # publishing, what the tag run will need from npm and pub.dev: an npm + # identity with read-write access in the @checkgate scope and parseable + # pub.dev credentials. Prints no secret. # - # The PyPI check exchanges this job's OIDC token for a short-lived upload - # token (discarded unused), exactly as publish-pypi will. If the publisher - # is still *pending* (project not yet on PyPI), that exchange creates the - # empty project `checkgate` under the account that registered it. + # PyPI cannot be checked here: the `pypi` environment only admits version + # tags, and the trusted publisher is bound to that environment. Instead, + # publish-pypi runs first in the tag run and every other publish job needs + # it, so a PyPI failure stops the release before anything is published. preflight-credentials: name: Preflight — publishing credentials if: github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest - environment: - name: pypi - url: https://pypi.org/project/checkgate/ permissions: contents: read - id-token: write steps: - uses: actions/setup-node@v5 with: @@ -521,22 +517,6 @@ jobs: console.log("pub.dev credentials: refresh token present"); });' - - name: PyPI — trusted publisher accepts this workflow - run: | - set -euo pipefail - AUD="$(curl -fsS https://pypi.org/_/oidc/audience | node -p 'JSON.parse(require("fs").readFileSync(0)).audience')" - OIDC="$(curl -fsS -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=$AUD" | node -p 'JSON.parse(require("fs").readFileSync(0)).value')" - echo "::add-mask::$OIDC" - RESP="$(curl -sS -X POST https://pypi.org/_/oidc/mint-token -H 'Content-Type: application/json' -d "{\"token\":\"$OIDC\"}")" - printf '%s' "$RESP" | node -e ' - const r = JSON.parse(require("fs").readFileSync(0)); - if (r.success && r.token) { console.log("PyPI trusted publishing: accepted (upload token minted and discarded)"); process.exit(0); } - console.error("Error: PyPI refused the trusted-publishing exchange:"); - console.error(JSON.stringify({ message: r.message, errors: (r.errors || []).map((e) => e.code + ": " + e.description) }, null, 2)); - process.exit(1); - ' - echo "PyPI project page: $(curl -s -o /dev/null -w '%{http_code}' https://pypi.org/pypi/checkgate/json)" - # =========================================================================== # PHASE 2 — PUBLISH. Every job below waits for *all* of phase 1. # =========================================================================== @@ -544,7 +524,7 @@ jobs: publish-node: name: Publish — @checkgate/node if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker] + needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker, publish-pypi] runs-on: ubuntu-latest permissions: contents: read @@ -614,7 +594,7 @@ jobs: publish-web: name: Publish — @checkgate/web if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker] + needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker, publish-pypi] runs-on: ubuntu-latest permissions: contents: read @@ -661,7 +641,7 @@ jobs: publish-cli: name: Publish — @checkgate/cli if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker] + needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker, publish-pypi] runs-on: ubuntu-latest permissions: contents: read @@ -689,7 +669,7 @@ jobs: publish-edge: name: Publish — @checkgate/edge if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker] + needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker, publish-pypi] runs-on: ubuntu-latest permissions: contents: read @@ -717,7 +697,7 @@ jobs: publish-ssr: name: Publish — @checkgate/ssr if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker] + needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker, publish-pypi] runs-on: ubuntu-latest permissions: contents: read @@ -745,7 +725,7 @@ jobs: publish-openfeature: name: Publish — @checkgate/openfeature-provider if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker] + needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker, publish-pypi] runs-on: ubuntu-latest permissions: contents: read @@ -773,7 +753,7 @@ jobs: publish-node-integrations: name: Publish — @checkgate/node-integrations if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker] + needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker, publish-pypi] runs-on: ubuntu-latest permissions: contents: read @@ -801,7 +781,7 @@ jobs: publish-mcp-server: name: Publish — @checkgate/mcp-server if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker] + needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker, publish-pypi] runs-on: ubuntu-latest permissions: contents: read @@ -829,7 +809,7 @@ jobs: publish-react-native: name: Publish — @checkgate/react-native if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker] + needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker, publish-pypi] runs-on: ubuntu-latest permissions: contents: read @@ -861,7 +841,7 @@ jobs: publish-flutter: name: Publish — checkgate_flutter (pub.dev) if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker] + needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker, publish-pypi] runs-on: ubuntu-latest permissions: id-token: write @@ -902,7 +882,7 @@ jobs: publish-docker: name: Publish — Docker image if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker] + needs: [verify-js, build-native, build-web, verify-flutter, verify-python, build-docker, publish-pypi] runs-on: ubuntu-latest permissions: contents: read @@ -954,6 +934,8 @@ jobs: run: | cosign sign --yes ${{ env.IMAGE_NAME }}@${{ steps.build-push.outputs.digest }} + # Runs before every other publish job (they all need it): it is the one + # credential the dispatch preflight cannot check (see preflight-credentials). # PyPI trusted publishing (OIDC): no stored token. Needs, once, on PyPI: a # publisher for project `checkgate`, owner checkgate-sh, repository # checkgate, workflow release.yml, environment `pypi`. The action attaches diff --git a/README.md b/README.md index bb4d4c43..fae3d41d 100644 --- a/README.md +++ b/README.md @@ -32,12 +32,9 @@ request. One Server-Sent Events connection per SDK delivers changes as they happ reconnects, a polling fallback and the last known flags if the server is unreachable. You run the server, PostgreSQL and Redis on your own infrastructure. -> [!NOTE] -> **0.2.0 is in development and not yet released.** The latest release is -> [v0.1.31](https://github.com/checkgate-sh/checkgate/releases/latest). Items marked -> *0.2.0* below are in this source tree but not yet published to npm, PyPI or the container -> registry. Upgrading an existing server to 0.2.0 has -> [rules to read first](docs/operations/upgrading-to-0-2-0.md) (two migrations, no rolling upgrade; back up the database first). +> [!IMPORTANT] +> Upgrading a 0.1.31 server to 0.2.0? Read [Upgrading to 0.2.0](docs/operations/upgrading-to-0-2-0.md) +> first: two database migrations, no rolling upgrade, back up the database before you start. ## How it works @@ -106,20 +103,20 @@ client.isEnabled('new-checkout', 'user-123', { plan: 'pro' }) // local: no netwo | Runtime | Package | Status | |---|---|---| -| Node.js | [`@checkgate/node`](docs/sdks/nodejs.md) (NAPI) | npm 0.1.31 | -| Browser | [`@checkgate/web`](docs/sdks/web.md) (WebAssembly) | npm 0.1.31 | -| React Native | [`@checkgate/react-native`](docs/sdks/react-native.md) (JSI) | npm 0.1.31 · Android build verified in CI; iOS not certified | -| Flutter | [`checkgate_flutter`](docs/sdks/flutter.md) (FFI) | pub.dev 0.1.31 · bundles no engine: you build and link it | -| Python | [`checkgate`](docs/sdks/python.md) (PyO3) | *0.2.0* · build from source; **not on PyPI yet** | -| OpenFeature | [`@checkgate/openfeature-provider`](docs/sdks/openfeature.md) (Node.js server) | *0.2.0* · not yet on npm | -| Express · Fastify · NestJS | [`@checkgate/node-integrations`](docs/sdks/node-frameworks.md) | *0.2.0* · not yet on npm | -| SSR / edge | [`@checkgate/ssr`](docs/ecosystem/ssr.md), [`@checkgate/edge`](docs/ecosystem/edge.md) | npm 0.1.31 | -| Typed flags | [`@checkgate/cli`](docs/ecosystem/cli.md) | npm 0.1.31 | -| AI agents | [`@checkgate/mcp-server`](docs/ecosystem/mcp.md) | *0.2.0* · not yet on npm · read-only by default; can propose, never apply or approve | +| Node.js | [`@checkgate/node`](docs/sdks/nodejs.md) (NAPI) | npm 0.2.0 | +| Browser | [`@checkgate/web`](docs/sdks/web.md) (WebAssembly) | npm 0.2.0 | +| React Native | [`@checkgate/react-native`](docs/sdks/react-native.md) (JSI) | npm 0.2.0 · Android build verified in CI; iOS not certified | +| Flutter | [`checkgate_flutter`](docs/sdks/flutter.md) (FFI) | pub.dev 0.2.0 · bundles no engine: you build and link it | +| Python | [`checkgate`](docs/sdks/python.md) (PyO3) | PyPI 0.2.0 · new in 0.2.0; CPython 3.11+ | +| OpenFeature | [`@checkgate/openfeature-provider`](docs/sdks/openfeature.md) (Node.js server) | npm 0.2.0 · new in 0.2.0 | +| Express · Fastify · NestJS | [`@checkgate/node-integrations`](docs/sdks/node-frameworks.md) | npm 0.2.0 · new in 0.2.0 | +| SSR / edge | [`@checkgate/ssr`](docs/ecosystem/ssr.md), [`@checkgate/edge`](docs/ecosystem/edge.md) | npm 0.2.0 | +| Typed flags | [`@checkgate/cli`](docs/ecosystem/cli.md) | npm 0.2.0 | +| AI agents | [`@checkgate/mcp-server`](docs/ecosystem/mcp.md) | npm 0.2.0 · new in 0.2.0 · read-only by default; can propose, never apply or approve | | Infrastructure as code | [Terraform / OpenTofu provider](docs/ecosystem/terraform.md), [Kubernetes operator](docs/ecosystem/kubernetes.md) | build from source | Every SDK runs the same evaluation engine and checks the same shared test vectors. Also new in -*0.2.0*: the [evaluation playground](docs/guide/playground.md) (what an SDK would answer for a user, +0.2.0: the [evaluation playground](docs/guide/playground.md) (what an SDK would answer for a user, and why) and [SDK diagnostics](docs/operations/sdk-diagnostics.md). Which packages your stack needs: [Which SDK do I need?](docs/sdks/index.md) diff --git a/docs/.vitepress/data/release.ts b/docs/.vitepress/data/release.ts index ac31d551..3e0b12d0 100644 --- a/docs/.vitepress/data/release.ts +++ b/docs/.vitepress/data/release.ts @@ -1,16 +1,16 @@ // Release status for the docs site, in one place. // // Pages never hard-code "unreleased" or "not on npm": they use , -// and , which read this file. When 0.2.0 is -// published, set `latest` to '0.2.0', `next` to null, and update each -// package's `registry` to what the registries actually serve (check with -// `npm view`, PyPI and pub.dev; never assume a publish succeeded). +// and , which read this file. For a release, set +// `latest` to its version, `next` to null (or the version in development), +// and each package's `registry` to what the registries serve (check with +// `npm view`, PyPI and pub.dev after publishing). export const release = { /** Newest version published to npm, pub.dev, ghcr.io and GitHub Releases. */ - latest: '0.1.31', + latest: '0.2.0', /** The version in development on `dev`, or null when nothing is pending. */ - next: '0.2.0' as string | null, + next: null as string | null, repo: 'https://github.com/checkgate-sh/checkgate', } @@ -50,34 +50,34 @@ export interface Package { export const packages: Package[] = [ { id: 'node', name: '@checkgate/node', platform: 'Node.js', binding: 'NAPI', doc: '/sdks/nodejs', since: '0.1.0', - registry: { kind: 'npm', version: '0.1.31' }, install: 'npm install @checkgate/node', group: 'sdk', - limits: 'Node.js runtime only (not edge runtimes). getDetails(), getHealth() and onStatusChange() arrive in 0.2.0.' }, + registry: { kind: 'npm', version: '0.2.0' }, install: 'npm install @checkgate/node', group: 'sdk', + limits: 'Node.js runtime only (not edge runtimes). getDetails(), getHealth() and onStatusChange() since 0.2.0.' }, { id: 'python', name: 'checkgate', platform: 'Python', binding: 'PyO3', doc: '/sdks/python', since: '0.2.0', - registry: { kind: 'source', note: 'Not on PyPI yet: build from the repository (needs Rust). Do not install a package named checkgate from PyPI until the project announces it.' }, + registry: { kind: 'pypi', version: '0.2.0' }, install: 'pip install checkgate', group: 'sdk', limits: 'CPython 3.11+. No impression reporting or track() yet.' }, { id: 'web', name: '@checkgate/web', platform: 'Browser', binding: 'WebAssembly', doc: '/sdks/web', since: '0.1.0', - registry: { kind: 'npm', version: '0.1.31' }, install: 'npm install @checkgate/web', group: 'sdk' }, + registry: { kind: 'npm', version: '0.2.0' }, install: 'npm install @checkgate/web', group: 'sdk' }, { id: 'react-native', name: '@checkgate/react-native', platform: 'React Native', binding: 'JSI', doc: '/sdks/react-native', since: '0.1.0', - registry: { kind: 'npm', version: '0.1.31' }, install: 'npm install @checkgate/react-native', group: 'sdk', + registry: { kind: 'npm', version: '0.2.0' }, install: 'npm install @checkgate/react-native', group: 'sdk', limits: 'Android native build verified in CI; iOS not certified. Builds the Rust engine in your app build.' }, { id: 'flutter', name: 'checkgate_flutter', platform: 'Flutter', binding: 'Dart FFI', doc: '/sdks/flutter', since: '0.1.0', - registry: { kind: 'pub', version: '0.1.31' }, install: 'flutter pub add checkgate_flutter', group: 'sdk', + registry: { kind: 'pub', version: '0.2.0' }, install: 'flutter pub add checkgate_flutter', group: 'sdk', limits: 'Bundles no compiled engine: you build and link the Rust engine yourself.' }, { id: 'openfeature', name: '@checkgate/openfeature-provider', platform: 'OpenFeature (Node.js server)', binding: 'over @checkgate/node', doc: '/sdks/openfeature', since: '0.2.0', - registry: { kind: 'unpublished', note: 'Publishes to npm with 0.2.0; it needs @checkgate/node 0.2.' }, + registry: { kind: 'npm', version: '0.2.0' }, install: 'npm install @checkgate/openfeature-provider @openfeature/server-sdk', group: 'framework' }, { id: 'node-integrations', name: '@checkgate/node-integrations', platform: 'Express · Fastify · NestJS', binding: 'over @checkgate/node', doc: '/sdks/node-frameworks', since: '0.2.0', - registry: { kind: 'unpublished', note: 'Publishes to npm with 0.2.0.' }, + registry: { kind: 'npm', version: '0.2.0' }, install: 'npm install @checkgate/node @checkgate/node-integrations', group: 'framework', limits: 'Node.js 22.12+; Express 5, Fastify 5, NestJS 12.' }, { id: 'ssr', name: '@checkgate/ssr', platform: 'SSR / bootstrap', binding: 'with @checkgate/web', doc: '/ecosystem/ssr', since: '0.1.0', - registry: { kind: 'npm', version: '0.1.31' }, install: 'npm install @checkgate/web @checkgate/ssr', group: 'framework' }, + registry: { kind: 'npm', version: '0.2.0' }, install: 'npm install @checkgate/web @checkgate/ssr', group: 'framework' }, { id: 'edge', name: '@checkgate/edge', platform: 'Edge runtimes', binding: 'with @checkgate/web', doc: '/ecosystem/edge', since: '0.1.0', - registry: { kind: 'npm', version: '0.1.31' }, install: 'npm install @checkgate/edge @checkgate/web', group: 'framework' }, + registry: { kind: 'npm', version: '0.2.0' }, install: 'npm install @checkgate/edge @checkgate/web', group: 'framework' }, { id: 'cli', name: '@checkgate/cli', platform: 'Typed flag accessors', binding: 'dev dependency', doc: '/ecosystem/cli', since: '0.1.0', - registry: { kind: 'npm', version: '0.1.31' }, install: 'npm install -D @checkgate/cli', group: 'tooling' }, + registry: { kind: 'npm', version: '0.2.0' }, install: 'npm install -D @checkgate/cli', group: 'tooling' }, { id: 'mcp', name: '@checkgate/mcp-server', platform: 'AI agents (MCP)', binding: 'stdio', doc: '/ecosystem/mcp', since: '0.2.0', - registry: { kind: 'unpublished', note: 'Publishes to npm with 0.2.0; needs a 0.2.0 server.' }, group: 'tooling', + registry: { kind: 'npm', version: '0.2.0' }, install: 'npx -y @checkgate/mcp-server@0.2.0', group: 'tooling', limits: 'Read-only by default; can propose changes, never create, apply or approve.' }, { id: 'terraform', name: 'terraform-provider-checkgate', platform: 'Terraform / OpenTofu', binding: 'Go', doc: '/ecosystem/terraform', since: '0.1.0', registry: { kind: 'source', note: 'Not on the Terraform Registry: build from source.' }, group: 'tooling' }, diff --git a/docs/ecosystem/mcp.md b/docs/ecosystem/mcp.md index ad7c7223..a9bf281e 100644 --- a/docs/ecosystem/mcp.md +++ b/docs/ecosystem/mcp.md @@ -78,9 +78,9 @@ your email. Someone else must approve them. ## 2. Configure your MCP client -The package needs Node.js 22 or later (CI tests it on 22). Until it is published to npm, run it from a checkout of the -repository (`cd integrations/mcp-server && npm ci`) and point `command`/`args` at -`integrations/mcp-server/bin/checkgate-mcp.js`. +The client starts the server with `npx`, so there is nothing to install beforehand. It needs +Node.js 20 or later (CI tests it on 22). To run it from a checkout instead, use `node` with +`integrations/mcp-server/bin/checkgate-mcp.js` as `command`/`args` after `npm ci` in that directory. **Claude Desktop** (`claude_desktop_config.json`): @@ -88,8 +88,8 @@ repository (`cd integrations/mcp-server && npm ci`) and point `command`/`args` a { "mcpServers": { "checkgate": { - "command": "node", - "args": ["/path/to/checkgate/integrations/mcp-server/bin/checkgate-mcp.js"], + "command": "npx", + "args": ["-y", "@checkgate/mcp-server@0.2.0"], "env": { "CHECKGATE_URL": "https://flags.example.com", "CHECKGATE_TOKEN": "pat_your_propose_token", @@ -107,7 +107,7 @@ claude mcp add --transport stdio checkgate \ --env CHECKGATE_URL=https://flags.example.com \ --env CHECKGATE_TOKEN=pat_your_propose_token \ --env CHECKGATE_MCP_WRITE=1 \ - -- node /path/to/checkgate/integrations/mcp-server/bin/checkgate-mcp.js + -- npx -y @checkgate/mcp-server@0.2.0 ``` Leave out `CHECKGATE_MCP_WRITE` for a read-only assistant. diff --git a/docs/ecosystem/ssr.md b/docs/ecosystem/ssr.md index bfdaba53..612a7658 100644 --- a/docs/ecosystem/ssr.md +++ b/docs/ecosystem/ssr.md @@ -27,32 +27,23 @@ npm install @checkgate/ssr @checkgate/edge @checkgate/web ### 1. Server — build the payload -```ts -// lib/checkgate-server.ts +```js +// lib/checkgate-server.js import { CheckgateEdge } from '@checkgate/edge' import { buildBootstrap } from '@checkgate/ssr' import { createWasmCore } from '@checkgate/web/core' -let edge: CheckgateEdge | null = null +let edge = null -export async function getBootstrap(userKey: string, keys: string[]) { - if (!edge) { - edge = new CheckgateEdge({ - serverUrl: process.env.CHECKGATE_URL!, - sdkKey: process.env.CHECKGATE_SDK_KEY!, - core: await createWasmCore(), - ttlSeconds: 30, - }) - } - await edge.ensureFresh() - // buildBootstrap re-loads the snapshot into a core and resolves `keys` for the - // user; pass the same snapshot the edge client is holding. - return buildBootstrap({ +export async function getBootstrap(userKey, attributes, keys) { + edge ??= new CheckgateEdge({ + serverUrl: process.env.CHECKGATE_URL, + sdkKey: process.env.CHECKGATE_SDK_KEY, core: await createWasmCore(), - snapshot: edge.snapshotFlags(), - userKey, - keys, + ttlSeconds: 30, }) + await edge.ensureFresh() + return buildBootstrap({ core: await createWasmCore(), snapshot: edge.snapshotFlags(), userKey, attributes, keys }) } ``` @@ -63,15 +54,15 @@ render and the first client render then read the same values (no hydration mismatch). Keep the user's attributes next to it so the live client evaluates with the same inputs as the server. -```tsx -// app/layout.tsx (Server Component) -import { getBootstrap } from '@/lib/checkgate-server' +```jsx +// app/layout.jsx (Server Component) +import { getBootstrap } from '../lib/checkgate-server' import { FlagsProvider } from './flags-provider' export default async function RootLayout({ children }) { - const userKey = /* cookie/session id */ 'anonymous' - const attributes = { plan: 'free' } // the same attributes passed to buildBootstrap - const payload = await getBootstrap(userKey, ['new-homepage', 'checkout-color']) + const userKey = 'anonymous' // from your session or cookie + const attributes = { plan: 'free' } // the same attributes for server and client + const payload = await getBootstrap(userKey, attributes, ['new-homepage', 'checkout-color']) return ( @@ -90,25 +81,25 @@ Outside React (or with a streaming template), embed it instead with One `CheckgateWeb` client for the whole app, seeded from the same payload: -```tsx +```jsx +// app/flags-provider.jsx 'use client' import { createContext, useContext, useEffect, useMemo, useState } from 'react' import { BootstrapValues } from '@checkgate/ssr' import { CheckgateWeb } from '@checkgate/web' -type Read = (key: string) => boolean -const FlagsContext = createContext(() => false) +const FlagsContext = createContext(() => false) export function FlagsProvider({ payload, attributes = {}, children }) { const initial = useMemo(() => new BootstrapValues(payload), [payload]) - const [client, setClient] = useState(null) + const [client, setClient] = useState(null) const [, setVersion] = useState(0) useEffect(() => { const live = new CheckgateWeb({ - serverUrl: process.env.NEXT_PUBLIC_CHECKGATE_URL!, - sdkKey: process.env.NEXT_PUBLIC_CHECKGATE_SDK_KEY!, - bootstrap: payload, // live-ready without waiting for SSE + serverUrl: process.env.NEXT_PUBLIC_CHECKGATE_URL, + sdkKey: process.env.NEXT_PUBLIC_CHECKGATE_SDK_KEY, + bootstrap: payload, }) const off = live.onChange(() => setVersion((v) => v + 1)) live.connect().then(() => setClient(live)).catch(() => {}) @@ -116,14 +107,12 @@ export function FlagsProvider({ payload, attributes = {}, children }) { }, [payload]) // Server-resolved values until the live client is ready, then live ones. - const read: Read = (key) => - client && initial.userKey - ? client.isEnabled(key, initial.userKey, attributes) - : initial.isEnabled(key) + const read = (key) => + client && initial.userKey ? client.isEnabled(key, initial.userKey, attributes) : initial.isEnabled(key) return {children} } -export const useFlag = (key: string) => useContext(FlagsContext)(key) +export const useFlag = (key) => useContext(FlagsContext)(key) ``` **Remix / SvelteKit** follow the same three steps — build the payload in the `loader` / `+page.server`, inject the script into the document template, and read it in a client component or store. diff --git a/docs/guide/quickstart.md b/docs/guide/quickstart.md index d39dd771..e1c318bf 100644 --- a/docs/guide/quickstart.md +++ b/docs/guide/quickstart.md @@ -52,19 +52,19 @@ node --env-file=../.env index.mjs **Python** -The Python package is not on PyPI yet, so build it from this checkout (needs Rust). Use a Python -3.11+ interpreter: if `python3 --version` prints an older one, write `python3.11` (or newer) -instead of `python3` below. +Use a Python 3.11+ interpreter: if `python3 --version` prints an older one, write `python3.11` +(or newer) instead of `python3` below. ```bash -cd sdks/python -python3 -m venv .venv && .venv/bin/pip install "maturin>=1.9.4,<2" -VIRTUAL_ENV=$PWD/.venv .venv/bin/maturin develop --release -cd ../../quickstart/python +cd quickstart/python +python3 -m venv .venv && .venv/bin/pip install "checkgate==0.2.0" set -a && . ../.env && set +a -../../sdks/python/.venv/bin/python main.py +.venv/bin/python main.py ``` +To run against SDK changes in this checkout instead, build the package from source (needs Rust): +see [Python SDK: build from source](/sdks/python#build-from-source). + Both print the flag for two users (`new-checkout: user-pro=true user-free=false`; Python writes `True`/`False`): the flag is evaluated in your process by the Checkgate engine, with no network call per evaluation. @@ -99,7 +99,7 @@ restart. With a 0.2.0 server , open **Playground** in the sid | Setup fails with `HTTP 409` or `403` | The instance was already set up. `./quickstart/start.sh --down` starts over. | | The SDK logs `rejected the SDK key (HTTP 401)` | `CHECKGATE_SDK_KEY` is missing or from an older run: re-run with `--seed` after `--down`, or create a key in project settings. | | The SDK keeps logging `reconnecting` | The server is not reachable at `http://localhost:$CHECKGATE_PORT`; check `docker compose -f quickstart/compose.yml ps`. | -| `pip install checkgate` finds nothing, or something unexpected | The Python package is **not on PyPI yet** — do not install a `checkgate` package from PyPI until the project announces it. Build it from the checkout: `cd sdks/python && python3 -m venv .venv && .venv/bin/pip install maturin && .venv/bin/maturin develop --release`, then run `main.py` with `sdks/python/.venv/bin/python`. | +| `pip install checkgate` finds no matching distribution | No wheel for your platform or Python: wheels are for CPython 3.11+ on Linux (glibc) x86_64/aarch64, macOS x86_64/arm64 and Windows x86_64. Elsewhere (for example Alpine/musl), [build from source](/sdks/python#build-from-source). | ## What the script does not do diff --git a/docs/index.md b/docs/index.md index 3ac599bd..ead16dff 100644 --- a/docs/index.md +++ b/docs/index.md @@ -71,7 +71,7 @@ const enabled = client.isEnabled('new-checkout', 'user-123', { plan: 'pro' })