@cubicecho/server-kit 0.1.0 → 0.3.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/LICENSE +0 -0
- package/README.md +0 -0
- package/_agents/docs/01-database.md +0 -0
- package/_agents/docs/02-columns.md +0 -0
- package/_agents/docs/03-testing.md +0 -0
- package/_agents/docs/04-auth.md +54 -0
- package/_agents/docs/05-graphql.md +24 -0
- package/_agents/docs/common-mistakes.md +0 -0
- package/dist/auth/defaults.d.ts +31 -0
- package/dist/auth/defaults.js +18 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.js +4 -0
- package/dist/auth/plugins.d.ts +1270 -0
- package/dist/auth/plugins.js +39 -0
- package/dist/auth/preset.d.ts +53 -0
- package/dist/auth/preset.js +21 -0
- package/dist/auth/rate-limit.d.ts +32 -0
- package/dist/auth/rate-limit.js +60 -0
- package/dist/columns/index.d.ts +0 -0
- package/dist/columns/index.js +0 -0
- package/dist/consts.d.ts +0 -0
- package/dist/consts.js +0 -0
- package/dist/db/connection.d.ts +0 -0
- package/dist/db/connection.js +0 -0
- package/dist/db/create.d.ts +0 -0
- package/dist/db/create.js +0 -0
- package/dist/db/defaults.d.ts +0 -0
- package/dist/db/defaults.js +0 -0
- package/dist/db/errors.d.ts +0 -0
- package/dist/db/errors.js +0 -0
- package/dist/db/index.d.ts +0 -0
- package/dist/db/index.js +0 -0
- package/dist/db/prepare.d.ts +0 -0
- package/dist/db/prepare.js +0 -0
- package/dist/db/ssl.d.ts +0 -0
- package/dist/db/ssl.js +0 -0
- package/dist/db/version.d.ts +0 -0
- package/dist/db/version.js +0 -0
- package/dist/db/wait.d.ts +0 -0
- package/dist/db/wait.js +0 -0
- package/dist/graphql/defaults.d.ts +17 -0
- package/dist/graphql/defaults.js +10 -0
- package/dist/graphql/errors.d.ts +59 -0
- package/dist/graphql/errors.js +82 -0
- package/dist/graphql/index.d.ts +5 -0
- package/dist/graphql/index.js +5 -0
- package/dist/graphql/logger.d.ts +13 -0
- package/dist/graphql/logger.js +38 -0
- package/dist/graphql/operation-limits.d.ts +25 -0
- package/dist/graphql/operation-limits.js +88 -0
- package/dist/graphql/validation.d.ts +28 -0
- package/dist/graphql/validation.js +19 -0
- package/dist/testing/index.d.ts +0 -0
- package/dist/testing/index.js +0 -0
- package/dist/testing/postgres-problems.d.ts +0 -0
- package/dist/testing/postgres-problems.js +0 -0
- package/dist/testing/schema-problems.d.ts +0 -0
- package/dist/testing/schema-problems.js +0 -0
- package/llms.txt +45 -1
- package/package.json +27 -3
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { badInput } from './errors.js';
|
|
2
|
+
/** What the caller reads when a schema refuses a value and says nothing of its own. */
|
|
3
|
+
const INVALID = 'That input is not valid.';
|
|
4
|
+
/**
|
|
5
|
+
* Parses with zod, turning a failure into BAD_USER_INPUT.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam Output - What the schema parses to.
|
|
8
|
+
* @param schema - The zod schema.
|
|
9
|
+
* @param value - Untrusted input.
|
|
10
|
+
* @returns The parsed value.
|
|
11
|
+
* @throws BAD_USER_INPUT with the first issue's message.
|
|
12
|
+
*/
|
|
13
|
+
export function parseOrThrow(schema, value) {
|
|
14
|
+
const result = schema.safeParse(value);
|
|
15
|
+
if (result.success === false) {
|
|
16
|
+
throw badInput(result.error.issues[0]?.message ?? INVALID);
|
|
17
|
+
}
|
|
18
|
+
return result.data;
|
|
19
|
+
}
|
package/dist/testing/index.d.ts
CHANGED
|
File without changes
|
package/dist/testing/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/llms.txt
CHANGED
|
@@ -4,15 +4,37 @@
|
|
|
4
4
|
|
|
5
5
|
Agent-facing docs for @cubicecho/server-kit: one task or concept per page, then what each package.json "exports" entry exports. Generated from _agents/docs/ and the doc comments in src/ by @cubicecho/agent-docs; edit those, not this file.
|
|
6
6
|
|
|
7
|
-
Requires Node >=22. Peer dependencies: `@electric-sql/pglite` ^0.5.0 (optional), `drizzle-orm` 1.0.0-rc.5, `postgres` ^3.4.0, `vitest` ^5.0.0 (optional).
|
|
7
|
+
Requires Node >=22. Peer dependencies: `@better-auth/sso` >=1.7.28 <1.8.0, `@electric-sql/pglite` ^0.5.0 (optional), `better-auth` >=1.7.28 <1.8.0, `drizzle-orm` 1.0.0-rc.5, `graphql` ^16.0.0, `graphql-yoga` ^6.0.0, `postgres` ^3.4.0, `vitest` ^5.0.0 (optional).
|
|
8
8
|
|
|
9
9
|
## Docs
|
|
10
10
|
|
|
11
11
|
- [Database boot](_agents/docs/01-database.md): `@cubicecho/server-kit/db` makes a Postgres database ready to migrate: it waits for the server, creates the database when it is missing, and refuses a server the app cannot run on.
|
|
12
12
|
- [Columns](_agents/docs/02-columns.md): `@cubicecho/server-kit/columns` has the Drizzle columns that keep a table to the conventions: a UUIDv7 id, moments with a time zone, and a table limited to one row.
|
|
13
13
|
- [Test checks](_agents/docs/03-testing.md): `@cubicecho/server-kit/testing` registers Vitest tests that hold an app to the backend standard: its tables, and the Postgres it runs.
|
|
14
|
+
- [Auth preset](_agents/docs/04-auth.md): `@cubicecho/server-kit/auth` has the better-auth options and sign-in plugins every server shares: sessions in Postgres, bearer tokens, emailed links, and OIDC with pairing. The app still calls `betterAuth`, so it adds its own plugins and hooks and keeps exact types.
|
|
15
|
+
- [GraphQL](_agents/docs/05-graphql.md): `@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.
|
|
14
16
|
- [Common mistakes](_agents/docs/common-mistakes.md): What goes wrong when the kit is wired up slightly differently, and the fix for each.
|
|
15
17
|
|
|
18
|
+
## Exports: @cubicecho/server-kit/auth
|
|
19
|
+
|
|
20
|
+
- `AUTH_DEFAULTS`: What `authPreset` and `signInPlugins` use when the app overrides nothing.
|
|
21
|
+
- `AUTH_PATHS`: Where those pages are when the app overrides nothing.
|
|
22
|
+
- `AuthPaths` (type): The app's pages a sign-in passes through, as paths under `appUrl`.
|
|
23
|
+
- `AuthSettings` (type): Session and link lifetimes.
|
|
24
|
+
- `RATE_LIMIT_DEFAULTS`: What `createRateLimiter` uses when the app overrides nothing.
|
|
25
|
+
- `RateLimitSettings` (type): The sign-in throttle.
|
|
26
|
+
- `MagicLink` (type): What delivering one sign-in link is given.
|
|
27
|
+
- `SignInOptions` (type): What an app gives `signInPlugins`.
|
|
28
|
+
- `sendsMagicLinks`: Whether an instance emails sign-in links.
|
|
29
|
+
- `signInPlugins`: How people sign in: bearer sessions, OIDC with pairing, and emailed links.
|
|
30
|
+
- `AuthPresetOptions` (type): What an app gives the preset.
|
|
31
|
+
- `AuthTables` (type): The tables better-auth keeps, by its own model names.
|
|
32
|
+
- `authPreset`: The better-auth options every server shares.
|
|
33
|
+
- `createRateLimiter`: Builds a limiter that holds its counts in this process.
|
|
34
|
+
- `RateLimiter` (type): Sliding-window counter, in process.
|
|
35
|
+
- `ThrottleContext` (type): What throttling needs of a request's context.
|
|
36
|
+
- `throttle`: Counts one sign-in attempt, by the caller's address and by the account when the step names one.
|
|
37
|
+
|
|
16
38
|
## Exports: @cubicecho/server-kit/columns
|
|
17
39
|
|
|
18
40
|
- `id`: The primary key of an entity: a UUIDv7, made by the database.
|
|
@@ -42,6 +64,28 @@ Requires Node >=22. Peer dependencies: `@electric-sql/pglite` ^0.5.0 (optional),
|
|
|
42
64
|
- `Queryable` (type): Anything that can run a query: the Drizzle client on postgres-js, pg or PGlite.
|
|
43
65
|
- `waitForDatabase`: Waits until Postgres answers a query.
|
|
44
66
|
|
|
67
|
+
## Exports: @cubicecho/server-kit/graphql
|
|
68
|
+
|
|
69
|
+
- `OPERATION_LIMIT_DEFAULTS`: What `useOperationLimits` and an app's `buildSchema` use when the app overrides nothing.
|
|
70
|
+
- `OperationLimitSettings` (type): Bounds on one GraphQL operation.
|
|
71
|
+
- `badInput`: Arguments the caller can fix.
|
|
72
|
+
- `conflict`: The request is fine, but the instance is in a state that refuses it.
|
|
73
|
+
- `ErrorCode`: The `extensions.code` values clients branch on.
|
|
74
|
+
- `errorMessage`: Reads the message of any caught value.
|
|
75
|
+
- `forbidden`: This kind of caller may never do this.
|
|
76
|
+
- `notFound`: Missing, or someone else's.
|
|
77
|
+
- `rateLimited`: Builds the rate-limit refusal.
|
|
78
|
+
- `requireAuth`: Reads the signed-in user's id.
|
|
79
|
+
- `tooComplex`: Builds the refusal of an operation that asks for more than one may.
|
|
80
|
+
- `unauthenticated`: Builds the signed-out refusal.
|
|
81
|
+
- `graphqlLogger`: Yoga's logger with the `[graphql]` tag: warnings and errors, each with its request's id.
|
|
82
|
+
- `REQUEST_ID`: Yoga's `requestId` option: each request gets an id of ours, never one the caller chose.
|
|
83
|
+
- `assertWithinLimits`: Holds an operation to the limits.
|
|
84
|
+
- `Operation` (type): One request's operation, as pricing needs it.
|
|
85
|
+
- `useOperationLimits`: The Yoga plugin that holds every operation, subscriptions included, to the limits before it runs.
|
|
86
|
+
- `Parser` (type): A zod schema, by the one method used here.
|
|
87
|
+
- `parseOrThrow`: Parses with zod, turning a failure into BAD_USER_INPUT.
|
|
88
|
+
|
|
45
89
|
## Exports: @cubicecho/server-kit/testing
|
|
46
90
|
|
|
47
91
|
- `PostgresFiles` (type): Where a repo says which Postgres it runs.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubicecho/server-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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",
|
|
@@ -23,6 +23,10 @@
|
|
|
23
23
|
"server"
|
|
24
24
|
],
|
|
25
25
|
"exports": {
|
|
26
|
+
"./auth": {
|
|
27
|
+
"types": "./dist/auth/index.d.ts",
|
|
28
|
+
"import": "./dist/auth/index.js"
|
|
29
|
+
},
|
|
26
30
|
"./columns": {
|
|
27
31
|
"types": "./dist/columns/index.d.ts",
|
|
28
32
|
"import": "./dist/columns/index.js"
|
|
@@ -31,6 +35,10 @@
|
|
|
31
35
|
"types": "./dist/db/index.d.ts",
|
|
32
36
|
"import": "./dist/db/index.js"
|
|
33
37
|
},
|
|
38
|
+
"./graphql": {
|
|
39
|
+
"types": "./dist/graphql/index.d.ts",
|
|
40
|
+
"import": "./dist/graphql/index.js"
|
|
41
|
+
},
|
|
34
42
|
"./testing": {
|
|
35
43
|
"types": "./dist/testing/index.d.ts",
|
|
36
44
|
"import": "./dist/testing/index.js"
|
|
@@ -45,7 +53,7 @@
|
|
|
45
53
|
"access": "public"
|
|
46
54
|
},
|
|
47
55
|
"scripts": {
|
|
48
|
-
"build": "tsc -p tsconfig.build.json",
|
|
56
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
49
57
|
"prepack": "npm run build && agent-docs llms",
|
|
50
58
|
"check": "npm run check:biome && npm run check:types",
|
|
51
59
|
"check:biome": "biome check --write .",
|
|
@@ -55,8 +63,12 @@
|
|
|
55
63
|
"test": "vitest run"
|
|
56
64
|
},
|
|
57
65
|
"peerDependencies": {
|
|
66
|
+
"@better-auth/sso": ">=1.7.28 <1.8.0",
|
|
58
67
|
"@electric-sql/pglite": "^0.5.0",
|
|
68
|
+
"better-auth": ">=1.7.28 <1.8.0",
|
|
59
69
|
"drizzle-orm": "1.0.0-rc.5",
|
|
70
|
+
"graphql": "^16.0.0",
|
|
71
|
+
"graphql-yoga": "^6.0.0",
|
|
60
72
|
"postgres": "^3.4.0",
|
|
61
73
|
"vitest": "^5.0.0"
|
|
62
74
|
},
|
|
@@ -69,6 +81,7 @@
|
|
|
69
81
|
}
|
|
70
82
|
},
|
|
71
83
|
"devDependencies": {
|
|
84
|
+
"@better-auth/sso": "^1.7.28",
|
|
72
85
|
"@biomejs/biome": "^2.6.2",
|
|
73
86
|
"@cubicecho/agent-docs": "^0.2.0",
|
|
74
87
|
"@electric-sql/pglite": "^0.5.17",
|
|
@@ -79,11 +92,22 @@
|
|
|
79
92
|
"@semantic-release/npm": "^13.2.0",
|
|
80
93
|
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
81
94
|
"@types/node": "^24.19.4",
|
|
95
|
+
"better-auth": "^1.7.28",
|
|
82
96
|
"drizzle-kit": "^1.0.0-rc.5",
|
|
83
97
|
"drizzle-orm": "^1.0.0-rc.5",
|
|
98
|
+
"express": "^5.3.0",
|
|
99
|
+
"graphql": "^16.15.0",
|
|
100
|
+
"graphql-yoga": "^6.1.1",
|
|
84
101
|
"postgres": "^3.4.10",
|
|
85
102
|
"semantic-release": "^25.0.9",
|
|
86
103
|
"typescript": "^7.0.2",
|
|
87
|
-
"vitest": "^5.1.2"
|
|
104
|
+
"vitest": "^5.1.2",
|
|
105
|
+
"zod": "^4.6.7"
|
|
106
|
+
},
|
|
107
|
+
"dependencies": {
|
|
108
|
+
"@cubicecho/better-auth-oidc-pairing": "^1.1.0",
|
|
109
|
+
"@escape.tech/graphql-armor-max-aliases": "^2.6.3",
|
|
110
|
+
"@escape.tech/graphql-armor-max-depth": "^2.4.3",
|
|
111
|
+
"graphql-query-complexity": "^2.0.0"
|
|
88
112
|
}
|
|
89
113
|
}
|