@cubicecho/server-kit 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/_agents/docs/05-graphql.md +3 -2
- package/dist/graphql/index.d.ts +1 -0
- package/dist/graphql/index.js +1 -0
- package/dist/graphql/introspection.d.ts +28 -0
- package/dist/graphql/introspection.js +71 -0
- package/llms.txt +2 -0
- package/package.json +4 -3
- package/skill/SKILL.md +84 -0
- package/skill/adopting.md +58 -0
- package/skill/auth.md +359 -0
- package/skill/boot.md +326 -0
- package/skill/database.md +103 -0
- package/skill/defaults.md +72 -0
- package/skill/graphql.md +153 -0
- package/skill/mcp.md +87 -0
- package/skill/sso.md +187 -0
- package/skill/testing.md +133 -0
package/README.md
CHANGED
|
@@ -33,10 +33,21 @@ try {
|
|
|
33
33
|
|
|
34
34
|
It waits for Postgres, creates the database when it is missing, and refuses a server older than 18, with a message that says what to do.
|
|
35
35
|
|
|
36
|
+
## The agent skill
|
|
37
|
+
|
|
38
|
+
How a server is built on the kit, written for an agent, is the Markdown in
|
|
39
|
+
[`skill/`](https://github.com/cubicecho/server-kit/tree/main/skill): `SKILL.md`, which routes, and one
|
|
40
|
+
file per job (boot, tables and ids, auth, SSO, errors and limits, the MCP door, defaults, tests,
|
|
41
|
+
adopting the kit). It ships in the package, so `node_modules/@cubicecho/server-kit/skill/` always
|
|
42
|
+
matches the installed version. Put the directory wherever your agent reads skills and keep it whole,
|
|
43
|
+
because the files link each other by relative path. No file is over 25 KB, so a skills server can hand
|
|
44
|
+
each one over whole.
|
|
45
|
+
|
|
36
46
|
## Documentation
|
|
37
47
|
|
|
38
48
|
- [llms.txt](https://cdn.jsdelivr.net/npm/@cubicecho/server-kit/llms.txt)
|
|
39
49
|
- [Pages](https://github.com/cubicecho/server-kit/tree/main/_agents/docs)
|
|
50
|
+
- [The skill](https://github.com/cubicecho/server-kit/blob/main/skill/SKILL.md)
|
|
40
51
|
- [Changelog](https://github.com/cubicecho/server-kit/blob/main/CHANGELOG.md)
|
|
41
52
|
|
|
42
53
|
## License
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
`@cubicecho/server-kit/graphql` has what every Yoga 6 server shares: operation limits, coded errors, input validation and a logger that never prints a request's variables.
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
|
-
import { graphqlLogger, REQUEST_ID, useOperationLimits } from '@cubicecho/server-kit/graphql';
|
|
6
|
+
import { graphqlLogger, REQUEST_ID, useIntrospectionGate, useOperationLimits } from '@cubicecho/server-kit/graphql';
|
|
7
7
|
import { createYoga } from 'graphql-yoga';
|
|
8
8
|
|
|
9
9
|
const yoga = createYoga({
|
|
@@ -11,11 +11,12 @@ const yoga = createYoga({
|
|
|
11
11
|
graphqlEndpoint: '/graphql',
|
|
12
12
|
logging: graphqlLogger,
|
|
13
13
|
requestId: REQUEST_ID,
|
|
14
|
-
plugins: [useOperationLimits()],
|
|
14
|
+
plugins: [useOperationLimits(), useIntrospectionGate({ allow: (request) => isPerson(request) })],
|
|
15
15
|
});
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
- `useOperationLimits({ maxCost: 15_000 })` replaces a bound of `OPERATION_LIMIT_DEFAULTS`. It holds subscriptions to them too.
|
|
19
|
+
- `useIntrospectionGate({ allow })` refuses `__schema` and `__type` to every request `allow(request, serverContext)` does not let in, and takes graphql-js's "Did you mean" hints off their errors (`suggestions: true` keeps them). `allow` may be async and is asked only for a document that could introspect. Without it, nobody introspects. Add it in production only. `__typename` is everyone's.
|
|
19
20
|
- Give `buildSchema` the same page sizes: `limits: { defaultLimit: OPERATION_LIMIT_DEFAULTS.defaultPageSize, maxLimit: OPERATION_LIMIT_DEFAULTS.maxPageSize }`.
|
|
20
21
|
- `badInput`, `notFound`, `forbidden`, `conflict`, `unauthenticated` and `rateLimited` build the errors a client reads, by `ErrorCode`. Anything else thrown is masked and logged.
|
|
21
22
|
- `parseOrThrow(schema, value)` takes a zod 4 schema and throws `BAD_USER_INPUT` with its first issue.
|
package/dist/graphql/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { OPERATION_LIMIT_DEFAULTS, type OperationLimitSettings } from './defaults.ts';
|
|
2
2
|
export { badInput, conflict, ErrorCode, errorMessage, forbidden, notFound, rateLimited, requireAuth, tooComplex, unauthenticated, } from './errors.ts';
|
|
3
|
+
export { type IntrospectionGateOptions, useIntrospectionGate } from './introspection.ts';
|
|
3
4
|
export { graphqlLogger, REQUEST_ID } from './logger.ts';
|
|
4
5
|
export { assertWithinLimits, type Operation, useOperationLimits } from './operation-limits.ts';
|
|
5
6
|
export { type Parser, parseOrThrow } from './validation.ts';
|
package/dist/graphql/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { OPERATION_LIMIT_DEFAULTS } from './defaults.js';
|
|
2
2
|
export { badInput, conflict, ErrorCode, errorMessage, forbidden, notFound, rateLimited, requireAuth, tooComplex, unauthenticated, } from './errors.js';
|
|
3
|
+
export { useIntrospectionGate } from './introspection.js';
|
|
3
4
|
export { graphqlLogger, REQUEST_ID } from './logger.js';
|
|
4
5
|
export { assertWithinLimits, useOperationLimits } from './operation-limits.js';
|
|
5
6
|
export { parseOrThrow } from './validation.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Plugin, PromiseOrValue } from 'graphql-yoga';
|
|
2
|
+
/** What a gate is given to decide who may introspect. */
|
|
3
|
+
export interface IntrospectionGateOptions<TServerContext> {
|
|
4
|
+
/**
|
|
5
|
+
* Whether this request may introspect. Asked only for a document that could, and once per request.
|
|
6
|
+
* Leave it out and nobody may. Anything it throws fails the request, so return false for a caller it refuses.
|
|
7
|
+
*/
|
|
8
|
+
allow?: (request: Request, serverContext: TServerContext) => PromiseOrValue<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* Whether a request not let in still reads graphql-js's "Did you mean" hints, which name fields. Off by default.
|
|
11
|
+
* Only a document that could introspect is let in, so with it off a typo gets no hint from anyone.
|
|
12
|
+
*/
|
|
13
|
+
suggestions?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The Yoga plugin that refuses introspection to everyone `allow` does not let in, so a production server does not
|
|
17
|
+
* hand its schema to whoever asks.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam TServerContext - What the server hands Yoga, such as Express's `req`.
|
|
20
|
+
* @param [options] - Who may introspect, and whether a refused caller reads hints.
|
|
21
|
+
* @returns The plugin, for `createYoga({ plugins })`.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Validation is synchronous and deciding may not be, so `allow` is asked while the request's parameters are read.
|
|
25
|
+
* It fails closed: every request not let in is refused, including one with no query text (a persisted operation) or
|
|
26
|
+
* one that never had its parameters read (a WebSocket). `__typename` is everyone's.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useIntrospectionGate<TServerContext extends object = Record<string, unknown>>(options?: IntrospectionGateOptions<TServerContext>): Plugin<object, TServerContext>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { GraphQLError, NoSchemaIntrospectionCustomRule } from 'graphql';
|
|
2
|
+
/** A document that could introspect. A field name can't be escaped, so this text is in every one that does. */
|
|
3
|
+
const INTROSPECTION = /\b__(?:schema|type)\b/;
|
|
4
|
+
/** graphql-js's hint, always the end of its message. */
|
|
5
|
+
const SUGGESTION = / Did you mean .*\?$/s;
|
|
6
|
+
/**
|
|
7
|
+
* Takes the hint off a validation error, keeping where it points.
|
|
8
|
+
*
|
|
9
|
+
* @param error - A validation error.
|
|
10
|
+
* @returns The error, or a copy without its hint.
|
|
11
|
+
*/
|
|
12
|
+
function withoutSuggestion(error) {
|
|
13
|
+
if (error instanceof GraphQLError === false) {
|
|
14
|
+
return error;
|
|
15
|
+
}
|
|
16
|
+
const message = error.message.replace(SUGGESTION, '');
|
|
17
|
+
if (message === error.message) {
|
|
18
|
+
return error;
|
|
19
|
+
}
|
|
20
|
+
return new GraphQLError(message, {
|
|
21
|
+
nodes: error.nodes,
|
|
22
|
+
source: error.source,
|
|
23
|
+
positions: error.positions,
|
|
24
|
+
path: error.path,
|
|
25
|
+
originalError: error.originalError,
|
|
26
|
+
extensions: error.extensions,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The Yoga plugin that refuses introspection to everyone `allow` does not let in, so a production server does not
|
|
31
|
+
* hand its schema to whoever asks.
|
|
32
|
+
*
|
|
33
|
+
* @typeParam TServerContext - What the server hands Yoga, such as Express's `req`.
|
|
34
|
+
* @param [options] - Who may introspect, and whether a refused caller reads hints.
|
|
35
|
+
* @returns The plugin, for `createYoga({ plugins })`.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* Validation is synchronous and deciding may not be, so `allow` is asked while the request's parameters are read.
|
|
39
|
+
* It fails closed: every request not let in is refused, including one with no query text (a persisted operation) or
|
|
40
|
+
* one that never had its parameters read (a WebSocket). `__typename` is everyone's.
|
|
41
|
+
*/
|
|
42
|
+
export function useIntrospectionGate(options = {}) {
|
|
43
|
+
const { allow, suggestions = false } = options;
|
|
44
|
+
const isLetIn = new WeakSet();
|
|
45
|
+
return {
|
|
46
|
+
onParams: async ({ params, request, context }) => {
|
|
47
|
+
if (allow === undefined || INTROSPECTION.test(params.query ?? '') === false) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (await allow(request, context)) {
|
|
51
|
+
isLetIn.add(request);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
onValidate: ({ context, addValidationRule }) => {
|
|
55
|
+
// Yoga keys its validation cache on the rules, so a person's cached answer is never a refused caller's.
|
|
56
|
+
const request = context.request;
|
|
57
|
+
if (request !== undefined && isLetIn.has(request)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
addValidationRule(NoSchemaIntrospectionCustomRule);
|
|
61
|
+
if (suggestions) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
return ({ result, setResult }) => {
|
|
65
|
+
if (result.length > 0) {
|
|
66
|
+
setResult(result.map(withoutSuggestion));
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
package/llms.txt
CHANGED
|
@@ -102,6 +102,8 @@ Requires Node >=22. Peer dependencies: `@better-auth/sso` >=1.7.28 <1.8.0 (optio
|
|
|
102
102
|
- `requireAuth`: Reads the signed-in user's id.
|
|
103
103
|
- `tooComplex`: Builds the refusal of an operation that asks for more than one may.
|
|
104
104
|
- `unauthenticated`: Builds the signed-out refusal.
|
|
105
|
+
- `IntrospectionGateOptions` (type): What a gate is given to decide who may introspect.
|
|
106
|
+
- `useIntrospectionGate`: The Yoga plugin that refuses introspection to everyone `allow` does not let in, so a production server does not hand its schema to whoever asks.
|
|
105
107
|
- `graphqlLogger`: Yoga's logger with the `[graphql]` tag: warnings and errors, each with its request's id.
|
|
106
108
|
- `REQUEST_ID`: Yoga's `requestId` option: each request gets an id of ours, never one the caller chose.
|
|
107
109
|
- `assertWithinLimits`: Holds an operation to the limits.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubicecho/server-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "The server code every cubicecho GraphQL backend shares: database boot, id columns and the checks that keep a schema to the standard.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Benjamin Van Treese",
|
|
@@ -59,7 +59,8 @@
|
|
|
59
59
|
"files": [
|
|
60
60
|
"dist",
|
|
61
61
|
"llms.txt",
|
|
62
|
-
"_agents/docs"
|
|
62
|
+
"_agents/docs",
|
|
63
|
+
"skill"
|
|
63
64
|
],
|
|
64
65
|
"publishConfig": {
|
|
65
66
|
"access": "public"
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"check:biome": "biome check --write .",
|
|
72
73
|
"check:types": "tsc --noEmit",
|
|
73
74
|
"llms": "agent-docs llms",
|
|
74
|
-
"docs:check": "agent-docs check",
|
|
75
|
+
"docs:check": "node scripts/check-skill-files.mjs && agent-docs check",
|
|
75
76
|
"test": "vitest run"
|
|
76
77
|
},
|
|
77
78
|
"peerDependencies": {
|
package/skill/SKILL.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cubicecho-server-kit
|
|
3
|
+
description: How to build, update or review a cubicecho GraphQL server on @cubicecho/server-kit, the shared server code and the one set of versions — which kit entry does which job (/db prepareDatabase and connectionOptions, /columns id() moment() timestamps() singleton(), /auth authPreset signInPlugins setup gate device links throttle, /graphql ErrorCode errors parseOrThrow useOperationLimits useIntrospectionGate graphqlLogger, /http stopOnSignals with its cutOff step checkHealth createStaticHandler mountAuthRedirects, /lock holdPostgresLock, /mcp toolOptions contextFromRequest, /testing checkSchemaConventions checkPostgresVersion checkMcpBudget), how an app wires each one into createApp and index.ts, UUIDv7 ids on Postgres 18, better-auth with OIDC sign-in and provider pairing by Dynamic Client Registration, the defaults groups the kit owns, and moving an existing server onto the kit. Load it whenever you touch a cubicecho backend's boot, database, auth, SSO, errors, limits, MCP door or tests, or the kit itself.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# cubicecho server kit
|
|
7
|
+
|
|
8
|
+
Every cubicecho GraphQL server is built on `@cubicecho/server-kit`. The kit is functions the server calls, not a framework: the server keeps its own `createApp`, schema, auth instance and boot order, and calls the kit for everything two servers would otherwise both write. This skill is how a server uses it.
|
|
9
|
+
|
|
10
|
+
**Load these first**, from the same skills server:
|
|
11
|
+
|
|
12
|
+
- `cubicecho_typescript` and `coding-standards`: the TypeScript, tooling and readability rules. This skill repeats neither.
|
|
13
|
+
- `cubicecho-backend`: what a server is built of that the kit has no part in — the app and service archetypes and their folders, the drizzle-graphql schema and its hooks, Drizzle conventions, realtime, casl permissions, Docker, CI and release, and the PGlite test harness. It is on the skills server as `cubicecho-backend` (`cubicecho/skills/backend/` on the NAS for now). When this skill says "the `cubicecho-backend` skill's X.md", that is where to look.
|
|
14
|
+
|
|
15
|
+
The kit's API reference ships in the package: `node_modules/@cubicecho/server-kit/llms.txt` and `_agents/docs/`. This skill says how the pieces are wired into a server and why; the reference says what each function takes.
|
|
16
|
+
|
|
17
|
+
## Which file for which job
|
|
18
|
+
|
|
19
|
+
| Task | Entry | Load |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `index.ts` and `createApp`: boot order, `prepareDatabase`, `/healthz`, the static handler, the body cap, the Yoga handler, shutdown and its `cutOff` step | `/db`, `/http`, `/graphql` | [boot.md](boot.md) |
|
|
22
|
+
| One process per database: `holdPostgresLock`, for a server that keeps what it serves in memory | `/lock` | [boot.md](boot.md), "One process per database" |
|
|
23
|
+
| Tables: `id()`, `moment()`, `timestamps()`, `singleton()`, which rows get an id, the better-auth tables, `connectionOptions`, Postgres 18 | `/columns`, `/db` | [database.md](database.md) |
|
|
24
|
+
| Sign-in: `authPreset`, `signInPlugins`, sessions, setting up a new instance, device links and recovery, better-auth served as GraphQL, the throttle, API keys, the auth secret | `/auth` | [auth.md](auth.md) |
|
|
25
|
+
| OIDC sign-in and pairing a provider from a setup URL, who may pair, `mountAuthRedirects` | `/auth`, `/http` | [sso.md](sso.md), after auth.md |
|
|
26
|
+
| Errors a client reads, `ErrorCode`, masking and the logger, zod with `parseOrThrow`, page size, depth and cost, who may introspect | `/graphql` | [graphql.md](graphql.md) |
|
|
27
|
+
| The `/mcp` door: `toolOptions`, `contextFromRequest`, `MCP_DEFAULTS`, budgets | `/mcp` | [mcp.md](mcp.md) |
|
|
28
|
+
| A limit, timeout, size or lifetime: the kit's `<CONCEPT>_DEFAULTS` groups and the server's own | all | [defaults.md](defaults.md) |
|
|
29
|
+
| The tests the kit registers, and the tests that hold what a server wires | `/testing` | [testing.md](testing.md) |
|
|
30
|
+
| Putting an existing server on the kit, upgrading the kit, or changing the kit | — | [adopting.md](adopting.md) |
|
|
31
|
+
|
|
32
|
+
A new server needs the `cubicecho-backend` skill's archetype file, then boot, database, auth, sso, graphql, defaults and testing here.
|
|
33
|
+
|
|
34
|
+
## Versions
|
|
35
|
+
|
|
36
|
+
One set for every server. The kit has the singletons as peers, so npm refuses a server outside these ranges. What only one entry needs is an optional peer that the server installs itself: `postgres` for `/db`; `better-auth`, `@better-auth/sso` and `@cubicecho/better-auth-oidc-pairing` for `/auth`; `@cubicecho/graphql-mcp` for `/mcp`.
|
|
37
|
+
|
|
38
|
+
| Package | Version |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `@cubicecho/server-kit` | ^0.9 |
|
|
41
|
+
| Node | 26 |
|
|
42
|
+
| Postgres / PGlite (tests) | 18 or later / ^0.5 |
|
|
43
|
+
| `drizzle-orm`, `drizzle-kit` | `1.0.0-rc.5`, exact |
|
|
44
|
+
| `@vantreeseba/drizzle-graphql` | ^19 |
|
|
45
|
+
| `postgres` | ^4 (^3.4 is still accepted; it ends the process when a connection drops mid-transaction) |
|
|
46
|
+
| `graphql` | 16 |
|
|
47
|
+
| `graphql-yoga` | ^6 |
|
|
48
|
+
| `express` | 5 |
|
|
49
|
+
| `better-auth`, `@better-auth/sso`, `@better-auth/api-key` | ^1.7.28 |
|
|
50
|
+
| `@cubicecho/better-auth-oidc-pairing` | ^1.1 |
|
|
51
|
+
| `@cubicecho/graphql-better-auth` | ^1.1 |
|
|
52
|
+
| `@cubicecho/graphql-mcp` (with `/mcp`) | ^3.1 |
|
|
53
|
+
| `zod` | 4 |
|
|
54
|
+
| `nodemailer` (an optional dependency) | ^10 |
|
|
55
|
+
| `vitest` | 5 |
|
|
56
|
+
| `typescript` | 7 |
|
|
57
|
+
|
|
58
|
+
- **A version changes here first, then in the kit's peers, then in each server.** A server doesn't move a singleton on its own, and never installs with `--legacy-peer-deps`, which drops packages better-auth needs.
|
|
59
|
+
- **Adopting any part of the kit means the whole set.** See adopting.md.
|
|
60
|
+
- `graphql` 17 and PGlite 0.6 are out and have not been tried. Don't move to either in passing.
|
|
61
|
+
|
|
62
|
+
## What the kit holds a server to
|
|
63
|
+
|
|
64
|
+
Each rule is stated once here; the file it names has the detail and the code.
|
|
65
|
+
|
|
66
|
+
- **Code two servers need is in the kit, and a server never copies it.** Where a server needs the kit to do more, change the kit (adopting.md, "Changing the kit"). Something only one server needs stays in that server.
|
|
67
|
+
- **Boot prepares Postgres before it migrates.** `prepareDatabase` waits with capped backoff, creates a missing database, and refuses a server older than 18 or missing an extension, before anything is changed. A `DatabaseBootError` is printed as a sentence; anything else keeps its stack. See boot.md.
|
|
68
|
+
- **Build the app, don't run it.** `createApp(deps)` returns the Express app with no listen and no side effects. index.ts is boot only, and ends in `stopOnSignals(server, { after: closeDatabase })`, with `cutOff` ending any SSE streams. See boot.md.
|
|
69
|
+
- **A server that keeps state in memory holds the database lock.** It takes `holdPostgresLock` before migrating, and stops at once when the lock is lost. See boot.md.
|
|
70
|
+
- **Every entity has a UUIDv7 `id()`**, from Postgres's `uuidv7()`. A join table and derived data go without. A secret is never an id. `checkSchemaConventions` holds it. See database.md.
|
|
71
|
+
- **People sign in with a link or a provider, never a password**, through `authPreset` and `signInPlugins`, with sessions in Postgres. better-auth's endpoints are served as GraphQL; its REST routes are not mounted. See auth.md.
|
|
72
|
+
- **A new instance is set up in the app, with a code**: `SETUP_CODE`, or one the server makes up and logs once; `OPEN_SETUP=true` opts out for 15 minutes after a start. Every server also has device links and a recovery command. No link is ever logged. See auth.md.
|
|
73
|
+
- **Sign-in is throttled by the kit.** Every sign-in operation calls `throttle(ctx, flow, email?)` first. `ctx.ip` is only right when `TRUST_PROXY` is. See auth.md.
|
|
74
|
+
- **OIDC sign-in, with pairing from the app, is on by default.** Leaving it out is `oidc: false` with a reason. See sso.md.
|
|
75
|
+
- **Codes everywhere.** A failure a client reads is a coded `GraphQLError` from the kit's helpers, a member of `ErrorCode`; everything else is masked by Yoga and logged by `graphqlLogger`. Rows the caller doesn't own are `NOT_FOUND`, never `FORBIDDEN`. Caught values are read with `errorMessage(error)`. See graphql.md.
|
|
76
|
+
- **Every query is bounded**: `limits` and `complexity: true` in buildSchema, `useOperationLimits()` on every Yoga, and the `HTTP_DEFAULTS.bodyLimit` cap on `/graphql` and `/mcp`. See graphql.md and boot.md.
|
|
77
|
+
- **Only who `allow` lets in introspects in production**: `useIntrospectionGate` on every Yoga, a person or nobody, never an app's key. See graphql.md.
|
|
78
|
+
- **Tunables live in `defaults.ts`.** A group the kit owns is overridden where the thing is built, never copied. See defaults.md.
|
|
79
|
+
- **`/healthz` is `{ ok, version }`**, 503 when Postgres doesn't answer, and never says why. See boot.md.
|
|
80
|
+
- **The kit's checks run in every server's tests**: `checkSchemaConventions`, `checkPostgresVersion`, and `checkMcpBudget` where there is `/mcp`. See testing.md.
|
|
81
|
+
|
|
82
|
+
## Before you finish
|
|
83
|
+
|
|
84
|
+
The TS skill's `npm run check && npm test`. A schema change also needs `npm run db:generate` and the migration committed. A change to the kit itself also needs its page in `_agents/docs/` and the file here that uses it.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Adopting, upgrading and changing the kit
|
|
2
|
+
|
|
3
|
+
How an existing server moves onto `@cubicecho/server-kit`, how a server takes a new kit release, and when the kit itself should change.
|
|
4
|
+
|
|
5
|
+
## Putting an existing server on the kit
|
|
6
|
+
|
|
7
|
+
**Adopting any part of the kit means the whole set of versions** (SKILL.md, "Versions"), because the kit's peers refuse anything else. So the upgrades are the first commits, each on its own:
|
|
8
|
+
|
|
9
|
+
1. **Drizzle rc.5 and drizzle-graphql 19**, if the server is behind. From rc.4 and drizzle-graphql 13 this is a PR of its own, and breaking for clients:
|
|
10
|
+
- change every pin at once (root `overrides`, root dependency, the db and server packages), then run `npx drizzle-kit up` in `db/`. It rewrites the `snapshot.json` files, never `migration.sql`, and `db:generate` should then say "No schema changes".
|
|
11
|
+
- `not()` is typed `SQL | undefined`: where a function must return `SQL`, write `not(x) ?? <fail-closed SQL>`, never a cast.
|
|
12
|
+
- Date columns and their filters are the `Date` scalar, so a hand-written field that takes a day takes `Date` too; a bad day is refused as `DRIZZLE_INVALID_INPUT_VALUE`.
|
|
13
|
+
- Scalars come from `@vantreeseba/drizzle-graphql`, not graphql-scalars (the `cubicecho-backend` skill's schema.md).
|
|
14
|
+
2. **Yoga 6.** It breaks a hand-written logger, which `graphqlLogger` replaces (graphql.md).
|
|
15
|
+
3. **Vitest 5**, with Storybook 10.6.9 and `@vitest/browser-*` 5 beside it where the app has them.
|
|
16
|
+
4. **better-auth ^1.7.28**, `@better-auth/sso` and `@cubicecho/better-auth-oidc-pairing`, all three even with `oidc: false`.
|
|
17
|
+
|
|
18
|
+
Check with `npm ls` that each has one copy. Never `--legacy-peer-deps`.
|
|
19
|
+
|
|
20
|
+
Then replace the server's own copies, one concern per commit, with only that concern changing:
|
|
21
|
+
|
|
22
|
+
| The server has its own | Replace with | Then |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| shutdown, health, static, OIDC redirect modules | `/http`: `stopOnSignals`, `checkHealth`, `createStaticHandler`, `mountAuthRedirects` | delete them (boot.md) |
|
|
25
|
+
| a hand-written Yoga logger, an `x-request-id` handler | `graphqlLogger`, `REQUEST_ID` | |
|
|
26
|
+
| error helpers, an error-code list, `(error as Error).message` | `ErrorCode` and the helpers, `errorMessage` | graphql.md |
|
|
27
|
+
| depth or cost plugins | `useOperationLimits()`, and `limits` with `complexity: true` in buildSchema | graphql.md |
|
|
28
|
+
| an introspection plugin, `NoSchemaIntrospectionCustomRule` | `useIntrospectionGate({ allow })` | graphql.md |
|
|
29
|
+
| `rate-limit.ts`, `throttle.ts` | `createRateLimiter`, `throttle` | auth.md |
|
|
30
|
+
| better-auth options written out | `authPreset`, `signInPlugins` | auth.md, then sso.md |
|
|
31
|
+
| a connection-retry loop, `ssl` logic | `prepareDatabase`, `connectionOptions` | boot.md, in the Postgres 18 release |
|
|
32
|
+
| hand-written id and timestamp columns | `id()`, `moment()`, `timestamps()` | database.md, in the Postgres 18 release |
|
|
33
|
+
| `contextFromRequest`-like code for `/mcp`, its own budgets | `contextFromRequest`, `toolOptions`, `checkMcpBudget` | mcp.md |
|
|
34
|
+
| copies of the kit's defaults groups | overrides where the thing is built | defaults.md |
|
|
35
|
+
|
|
36
|
+
**The Postgres 18 release goes last and is announced as breaking**: the move to 18, `prepareDatabase`, `id()` as the default, and the two schema tests together (database.md). `prepareDatabase` stops every instance still on 17, so it is never adopted before.
|
|
37
|
+
|
|
38
|
+
Where the server diverges from the rest of the standard (layout, tenancy, deploy), the order is in the `cubicecho-backend` skill's app.md, "Bringing an existing app up to standard".
|
|
39
|
+
|
|
40
|
+
`notes` and `eunomia` are not on the kit yet. Their servers are too far behind to adopt it piece by piece, so leave them unless the task is their rewrite.
|
|
41
|
+
|
|
42
|
+
## Taking a new kit release
|
|
43
|
+
|
|
44
|
+
- Read the kit's `CHANGELOG.md`. A minor before 1.0 may break; the entry says what to change.
|
|
45
|
+
- Bump `@cubicecho/server-kit` in every package that depends on it (in an app, the db and server workspaces), and any peer whose range moved, in one commit.
|
|
46
|
+
- Re-read the kit page (`node_modules/@cubicecho/server-kit/_agents/docs/`) of each entry the release touched, and this skill's file for it.
|
|
47
|
+
|
|
48
|
+
## Changing the kit
|
|
49
|
+
|
|
50
|
+
**Code two servers need is in the kit, and a server never copies it.** When a server needs the kit to do more, change the kit rather than wrapping it or copying it in. Something only one server needs stays in that server, and a setting every server overrides does not belong in the kit.
|
|
51
|
+
|
|
52
|
+
The kit's own rules are in its `AGENTS.md`. The ones a server author meets:
|
|
53
|
+
|
|
54
|
+
- One entry per folder, and an entry imports only its own peers, so a server that skips `/mcp` never installs graphql-mcp.
|
|
55
|
+
- No `process.env`, no `process.exit` but in `stopOnSignals`, and no logging but through a `log` parameter: the server decides all three.
|
|
56
|
+
- A failure an operator can fix is a `DatabaseBootError` whose message says how, and never holds a credential.
|
|
57
|
+
- A new dependency or peer, a change to a peer range, or a higher `MIN_POSTGRES_MAJOR` is asked about first.
|
|
58
|
+
- An API change updates its page in `_agents/docs/` and the file of this skill that uses it.
|