@ingram-tech/nk-dev 0.13.1 → 0.14.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/guide.md +1 -1
- package/lib/auth-next.js +60 -0
- package/lib/doctor.js +7 -1
- package/package.json +1 -1
package/guide.md
CHANGED
|
@@ -150,7 +150,7 @@ tool instead). One-off single-file edits: just edit the file.
|
|
|
150
150
|
## What nextkit provides (reach for these)
|
|
151
151
|
|
|
152
152
|
- `@ingram-tech/nk-email` — Cloudflare email: `sendEmail`, `fromAddress`
|
|
153
|
-
- `@ingram-tech/nk-auth` — Better Auth foundation: presets you spread into your own `betterAuth()` (mounts at `/auth` via `authBasePath`; org / JWT / passkey / pool / client helpers). Don't hand-roll session reads or auth middleware — bind `createAuthHelpers` (`getUser` / `requireUser` / `redirectIfAuthenticated`, from `@ingram-tech/nk-auth/server`) and gate routes with the loop-safe `createAuthMiddleware`
|
|
153
|
+
- `@ingram-tech/nk-auth` — Better Auth foundation: presets you spread into your own `betterAuth()` (mounts at `/auth` via `authBasePath`; org / JWT / passkey / pool / client helpers). Don't hand-roll session reads or auth middleware — bind `createAuthHelpers` (`getUser` / `requireUser` / `redirectIfAuthenticated`, from `@ingram-tech/nk-auth/server`) and gate routes with the loop-safe `createAuthMiddleware`. A site with its own proxy sets the `next`-preserving header with `withAuthPathHeader(request, requestHeaders)` instead (and `clearStaleSession` for the stale-cookie handshake); a site wrapping the guards redirects to `await signInTarget()` rather than the bare sign-in path
|
|
154
154
|
- `@ingram-tech/nk-db` — Postgres data layer: `createPool` (one TLS-aware pool) + `createQueries` (raw SQL) + `createDb` (Drizzle), the PGlite dev/test harness at `@ingram-tech/nk-db/pglite`, the prefixed-id codec (the standalone `id758` package) at `@ingram-tech/nk-db/id`, and the drift-aware migration runner at `@ingram-tech/nk-db/migrate`
|
|
155
155
|
- `@ingram-tech/nk-api` — the standard HTTP API seam (Hono + `@hono/zod-openapi`): one `{ error, details? }` envelope, `createApiApp` / `createRouter`, auth + multi-tenant resource-scope middleware, pagination helpers, and an emitted OpenAPI/Swagger doc. Reach for it instead of hand-rolling route handlers
|
|
156
156
|
- `@ingram-tech/nk-billing` — Stripe primitives: subscriptions, a Stripe-side wallet, and an optional Postgres credit ledger behind the `/credits` subpath. Prices resolve at runtime by Stripe `lookup_key` — **never hardcode a price id**, so test and live share one code path
|
package/lib/auth-next.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join, relative, resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
// `next` preservation in nk-auth is split across two layers: a proxy sets the
|
|
5
|
+
// `x-nk-auth-path` request header (via `createAuthMiddleware` or
|
|
6
|
+
// `withAuthPathHeader`), and `createAuthHelpers`' guards read it to build
|
|
7
|
+
// `?next=` when they redirect to sign-in. A site that binds the helpers but
|
|
8
|
+
// never sets the header loses `next` with no error: every "sign in to see this
|
|
9
|
+
// page" lands on the default page. The runtime warns once outside production;
|
|
10
|
+
// this check catches it before the site is even run. Textual, like the
|
|
11
|
+
// endpoint-shadow check: we grep the site's sources, never execute them.
|
|
12
|
+
|
|
13
|
+
const SOURCE_DIRS = ["src", "app", "lib", "proxy.ts", "middleware.ts"];
|
|
14
|
+
const SOURCE_FILES = /\.(ts|tsx|js|jsx|mjs)$/;
|
|
15
|
+
const SKIP_DIRS = new Set(["node_modules", ".next", "dist", "build"]);
|
|
16
|
+
|
|
17
|
+
/** Every source file under the site's app-code roots, relative to `cwd`. */
|
|
18
|
+
function sourceFiles(cwd) {
|
|
19
|
+
const out = [];
|
|
20
|
+
const walk = (dir) => {
|
|
21
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
22
|
+
if (entry.isDirectory()) {
|
|
23
|
+
if (!SKIP_DIRS.has(entry.name) && !entry.name.startsWith("."))
|
|
24
|
+
walk(join(dir, entry.name));
|
|
25
|
+
} else if (SOURCE_FILES.test(entry.name) && !/\.test\./.test(entry.name)) {
|
|
26
|
+
out.push(relative(cwd, join(dir, entry.name)));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
for (const root of SOURCE_DIRS) {
|
|
31
|
+
const full = resolve(cwd, root);
|
|
32
|
+
if (!existsSync(full)) continue;
|
|
33
|
+
if (SOURCE_FILES.test(root)) out.push(root);
|
|
34
|
+
else walk(full);
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The "helpers bound, header never set" finding, or nothing. Silent on sites
|
|
41
|
+
* without `createAuthHelpers`, since they have no guard to lose `next` from.
|
|
42
|
+
*/
|
|
43
|
+
export function authNextFindings(cwd) {
|
|
44
|
+
let boundIn = null;
|
|
45
|
+
let wired = false;
|
|
46
|
+
for (const file of sourceFiles(cwd)) {
|
|
47
|
+
const src = readFileSync(resolve(cwd, file), "utf8");
|
|
48
|
+
if (!boundIn && /\bcreateAuthHelpers\s*\(/.test(src)) boundIn = file;
|
|
49
|
+
if (/\b(createAuthMiddleware|withAuthPathHeader)\s*\(/.test(src)) wired = true;
|
|
50
|
+
if (boundIn && wired) return [];
|
|
51
|
+
}
|
|
52
|
+
if (!boundIn) return [];
|
|
53
|
+
return [
|
|
54
|
+
{
|
|
55
|
+
id: "auth:next-unwired",
|
|
56
|
+
level: "warn",
|
|
57
|
+
message: `\`${boundIn}\` binds createAuthHelpers, but nothing sets the x-nk-auth-path header — its guards redirect to the bare sign-in path and \`next\` is lost. Mount createAuthMiddleware, or call withAuthPathHeader(request, requestHeaders) from "@ingram-tech/nk-auth/middleware" in your proxy.`,
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
}
|
package/lib/doctor.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
+
import { authNextFindings } from "./auth-next.js";
|
|
3
4
|
import { authShadowFindings } from "./auth-shadow.js";
|
|
4
5
|
import { SUPERSEDED_DEPS } from "./drift.js";
|
|
5
6
|
import {
|
|
@@ -312,6 +313,10 @@ export function findings(cwd) {
|
|
|
312
313
|
// 11. No page/route under app/auth/ shadows a Better Auth endpoint.
|
|
313
314
|
out.push(...authShadowFindings(cwd));
|
|
314
315
|
|
|
316
|
+
// 12. If nk-auth's server guards are bound, something sets the header they
|
|
317
|
+
// need to preserve `next`.
|
|
318
|
+
out.push(...authNextFindings(cwd));
|
|
319
|
+
|
|
315
320
|
return out;
|
|
316
321
|
}
|
|
317
322
|
|
|
@@ -386,7 +391,8 @@ function migrationFindings(cwd) {
|
|
|
386
391
|
* dependencies, oxlint/tsconfig extends, the CLAUDE.md guide import, stale knip
|
|
387
392
|
* ignores, forbidden schema-applying drizzle-kit scripts, Prettier leftovers,
|
|
388
393
|
* a missing or thin `ci` script, an unsealed or unmodelled-DDL-carrying migration chain, a
|
|
389
|
-
* page under app/auth/ shadowing a Better Auth endpoint
|
|
394
|
+
* page under app/auth/ shadowing a Better Auth endpoint, nk-auth guards bound
|
|
395
|
+
* without the proxy header that preserves `next`).
|
|
390
396
|
* With `--fix`, apply every auto-fixable finding, then remind
|
|
391
397
|
* to reinstall.
|
|
392
398
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingram-tech/nk-dev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "The nextkit dev toolchain in one package: the `nk` CLI plus shared oxlint/oxfmt, TypeScript, and Vitest config, the format-on-commit hook, and the AI agent guide. `nk init` scaffolds a site to use it.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|