@ingram-tech/nk-dev 0.22.0 → 0.24.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/lib/auth-next.js CHANGED
@@ -58,3 +58,42 @@ export function authNextFindings(cwd) {
58
58
  },
59
59
  ];
60
60
  }
61
+
62
+ /** Whether a source renews the session: `renewSession(…)`, or a
63
+ * `createAuthMiddleware({ … })` call given `auth`. */
64
+ function renews(src) {
65
+ if (/\brenewSession\s*\(/.test(src)) return true;
66
+ for (const match of src.matchAll(/\bcreateAuthMiddleware\s*\(/g)) {
67
+ const call = src.slice(match.index, match.index + 1000);
68
+ const end = call.indexOf("})");
69
+ if (/\bauth\b\s*[,:}\n]/.test(end === -1 ? call : call.slice(0, end)))
70
+ return true;
71
+ }
72
+ return false;
73
+ }
74
+
75
+ /**
76
+ * The "helpers bound, session never renewed" finding, or nothing.
77
+ *
78
+ * nk-auth's server guards read the session without refreshing it, because a
79
+ * server component cannot set the cookie a refresh re-issues. Something that
80
+ * can must do it, or every sign-in ends `session.expiresIn` after it began
81
+ * however active the person is: aidefencesummit.eu signed its users out weekly
82
+ * for a month before anyone noticed. The proxy does it, once per `updateAge`.
83
+ */
84
+ export function authRenewalFindings(cwd) {
85
+ let boundIn = null;
86
+ for (const file of sourceFiles(cwd)) {
87
+ const src = readFileSync(resolve(cwd, file), "utf8");
88
+ if (!boundIn && /\bcreateAuthHelpers\s*\(/.test(src)) boundIn = file;
89
+ if (renews(src)) return [];
90
+ }
91
+ if (!boundIn) return [];
92
+ return [
93
+ {
94
+ id: "auth:session-unrenewed",
95
+ level: "error",
96
+ message: `\`${boundIn}\` binds createAuthHelpers, but nothing renews the session, so every sign-in ends \`session.expiresIn\` after it began however active the person is. Pass \`auth\` to createAuthMiddleware, or call renewSession(request, response, auth) from "@ingram-tech/nk-auth/middleware" in your proxy.`,
97
+ },
98
+ ];
99
+ }
@@ -7,8 +7,10 @@ import { resolve } from "node:path";
7
7
  // its own reopens the gap (1.7.0 added a column the chain lacked; 1.7.3 then
8
8
  // rejected the constraint the chain had added), so the site must declare the
9
9
  // exact version nk-auth's peerDependencies names — not a range, which
10
- // `bun update` would silently walk past the next time.
11
- const AUTH_PACKAGES = ["better-auth", "@better-auth/passkey"];
10
+ // `bun update` would silently walk past the next time. Every `@better-auth/*`
11
+ // package moves with it: they peer on each other at the exact same version.
12
+ const isAuthPackage = (name) =>
13
+ name === "better-auth" || name.startsWith("@better-auth/");
12
14
 
13
15
  const readJson = (file) => {
14
16
  try {
@@ -44,9 +46,8 @@ export function authVersionFindings(cwd) {
44
46
  const deps = { ...pkg.dependencies, ...pkg.devDependencies };
45
47
  if (!deps["@ingram-tech/nk-auth"]) return out;
46
48
 
47
- for (const name of AUTH_PACKAGES) {
48
- const declared = deps[name];
49
- if (typeof declared !== "string") continue;
49
+ for (const [name, declared] of Object.entries(deps)) {
50
+ if (!isAuthPackage(name) || typeof declared !== "string") continue;
50
51
  const wanted = nkAuthPeer(cwd, name);
51
52
  if (wanted === null || !isExact(wanted)) continue;
52
53
  if (declared === wanted) continue;
package/lib/doctor.js CHANGED
@@ -2,7 +2,7 @@ import { existsSync, readFileSync, readdirSync, rmSync, writeFileSync } from "no
2
2
  import { dirname, relative, resolve, sep } from "node:path";
3
3
  import { checkAgentGuideImport, ensureGuideImport } from "./agent-guide.js";
4
4
  import { appDirFindings } from "./app-dir.js";
5
- import { authNextFindings } from "./auth-next.js";
5
+ import { authNextFindings, authRenewalFindings } from "./auth-next.js";
6
6
  import { authShadowFindings } from "./auth-shadow.js";
7
7
  import { authVersionFindings } from "./auth-version.js";
8
8
  import { ogImageFindings } from "./og-image.js";
@@ -403,6 +403,7 @@ export function findings(cwd) {
403
403
  // 12. If nk-auth's server guards are bound, something sets the header they
404
404
  // need to preserve `next`.
405
405
  out.push(...authNextFindings(cwd));
406
+ out.push(...authRenewalFindings(cwd));
406
407
 
407
408
  // 13. Better Auth is pinned to the exact version the installed nk-auth was
408
409
  // released against — its chain carries the schema that version needs.
@@ -498,7 +499,8 @@ export function exitCodeFor(results) {
498
499
  * ignores, forbidden schema-applying drizzle-kit scripts, Prettier leftovers,
499
500
  * a missing or thin `ci` script, an unsealed or unmodelled-DDL-carrying migration chain, a
500
501
  * page under app/auth/ shadowing a Better Auth endpoint, nk-auth guards bound
501
- * without the proxy header that preserves `next`, better-auth declared at a
502
+ * without the proxy header that preserves `next` or the proxy renewal that keeps
503
+ * a session alive, better-auth declared at a
502
504
  * version or range other than the exact one nk-auth pins).
503
505
  * With `--fix`, apply every auto-fixable finding, then remind
504
506
  * to reinstall.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ingram-tech/nk-dev",
3
- "version": "0.22.0",
3
+ "version": "0.24.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",