@ingram-tech/nk-dev 0.16.1 → 0.17.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 +8 -1
- package/lib/auth-version.js +72 -0
- package/lib/doctor.js +7 -1
- package/package.json +4 -4
package/guide.md
CHANGED
|
@@ -170,7 +170,14 @@ tool instead). One-off single-file edits: just edit the file.
|
|
|
170
170
|
## What nextkit provides (reach for these)
|
|
171
171
|
|
|
172
172
|
- `@ingram-tech/nk-email` — Cloudflare email: `sendEmail`, `fromAddress`
|
|
173
|
-
- `@ingram-tech/nk-auth` — Better Auth foundation
|
|
173
|
+
- `@ingram-tech/nk-auth` — Better Auth foundation.
|
|
174
|
+
**`better-auth` and `@better-auth/*` move only with nk-auth**, pinned to the
|
|
175
|
+
exact version its `peerDependencies` names (never a range; `nk doctor` fails
|
|
176
|
+
either): a Better Auth version that changes a table ships as a delta in
|
|
177
|
+
nk-auth's migration chain, and the order on every site is bump, `db:migrate`
|
|
178
|
+
against the target database, then deploy. `createAuthHelpers` refuses to
|
|
179
|
+
serve a session while the recorded chain lags the installed package.
|
|
180
|
+
Presets: 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
|
|
174
181
|
- `@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`
|
|
175
182
|
- `@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
|
|
176
183
|
- `@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
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
// Better Auth moves only with nk-auth: a version that changes a table ships as
|
|
5
|
+
// a delta in nk-auth's migration chain, proven against that version's
|
|
6
|
+
// `getAuthTables()` by nk-auth's own test. A site that bumps `better-auth` on
|
|
7
|
+
// its own reopens the gap (1.7.0 added a column the chain lacked; 1.7.3 then
|
|
8
|
+
// rejected the constraint the chain had added), so the site must declare the
|
|
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"];
|
|
12
|
+
|
|
13
|
+
const readJson = (file) => {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
16
|
+
} catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** The exact version nk-auth was released against, or null when not installed. */
|
|
22
|
+
function nkAuthPeer(cwd, pkg) {
|
|
23
|
+
const candidates = [
|
|
24
|
+
resolve(cwd, "node_modules/@ingram-tech/nk-auth/package.json"),
|
|
25
|
+
resolve(cwd, "../../node_modules/@ingram-tech/nk-auth/package.json"),
|
|
26
|
+
];
|
|
27
|
+
const file = candidates.find((c) => existsSync(c));
|
|
28
|
+
const manifest = file ? readJson(file) : null;
|
|
29
|
+
const range = manifest?.peerDependencies?.[pkg];
|
|
30
|
+
return typeof range === "string" ? range : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const isExact = (range) => /^\d+\.\d+\.\d+(-[\w.]+)?$/.test(range);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Findings for a site that depends on both nk-auth and a Better Auth package:
|
|
37
|
+
* the site's declared version must be exactly what nk-auth pins. A caret or
|
|
38
|
+
* tilde range is flagged even when it currently resolves to the right version.
|
|
39
|
+
*/
|
|
40
|
+
export function authVersionFindings(cwd) {
|
|
41
|
+
const out = [];
|
|
42
|
+
const pkg = readJson(resolve(cwd, "package.json"));
|
|
43
|
+
if (!pkg) return out;
|
|
44
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
45
|
+
if (!deps["@ingram-tech/nk-auth"]) return out;
|
|
46
|
+
|
|
47
|
+
for (const name of AUTH_PACKAGES) {
|
|
48
|
+
const declared = deps[name];
|
|
49
|
+
if (typeof declared !== "string") continue;
|
|
50
|
+
const wanted = nkAuthPeer(cwd, name);
|
|
51
|
+
if (wanted === null || !isExact(wanted)) continue;
|
|
52
|
+
if (declared === wanted) continue;
|
|
53
|
+
const why = isExact(declared)
|
|
54
|
+
? `\`${name}\` is pinned to ${declared} but the installed nk-auth is released against ${wanted}`
|
|
55
|
+
: `\`${name}\` is declared as "${declared}" — a range; nk-auth is released against exactly ${wanted}`;
|
|
56
|
+
out.push({
|
|
57
|
+
id: `auth:version:${name}`,
|
|
58
|
+
level: "error",
|
|
59
|
+
message: `${why}. Better Auth moves only with nk-auth (its chain carries the schema each version needs): pin "${wanted}", run db:migrate against the target database, then deploy.`,
|
|
60
|
+
fix: (dir) => {
|
|
61
|
+
const file = resolve(dir, "package.json");
|
|
62
|
+
const j = readJson(file);
|
|
63
|
+
for (const field of ["dependencies", "devDependencies"]) {
|
|
64
|
+
if (j[field]?.[name] !== undefined) j[field][name] = wanted;
|
|
65
|
+
}
|
|
66
|
+
writeFileSync(file, `${JSON.stringify(j, null, "\t")}\n`);
|
|
67
|
+
return `pinned \`${name}\` → "${wanted}"`;
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
package/lib/doctor.js
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, readFileSync, readdirSync, rmSync, writeFileSync } from "no
|
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { authNextFindings } from "./auth-next.js";
|
|
4
4
|
import { authShadowFindings } from "./auth-shadow.js";
|
|
5
|
+
import { authVersionFindings } from "./auth-version.js";
|
|
5
6
|
import { SUPERSEDED_DEPS } from "./drift.js";
|
|
6
7
|
import {
|
|
7
8
|
SEAL_FILE,
|
|
@@ -334,6 +335,10 @@ export function findings(cwd) {
|
|
|
334
335
|
// need to preserve `next`.
|
|
335
336
|
out.push(...authNextFindings(cwd));
|
|
336
337
|
|
|
338
|
+
// 13. Better Auth is pinned to the exact version the installed nk-auth was
|
|
339
|
+
// released against — its chain carries the schema that version needs.
|
|
340
|
+
out.push(...authVersionFindings(cwd));
|
|
341
|
+
|
|
337
342
|
return out;
|
|
338
343
|
}
|
|
339
344
|
|
|
@@ -409,7 +414,8 @@ function migrationFindings(cwd) {
|
|
|
409
414
|
* ignores, forbidden schema-applying drizzle-kit scripts, Prettier leftovers,
|
|
410
415
|
* a missing or thin `ci` script, an unsealed or unmodelled-DDL-carrying migration chain, a
|
|
411
416
|
* page under app/auth/ shadowing a Better Auth endpoint, nk-auth guards bound
|
|
412
|
-
* without the proxy header that preserves `next
|
|
417
|
+
* without the proxy header that preserves `next`, better-auth declared at a
|
|
418
|
+
* version or range other than the exact one nk-auth pins).
|
|
413
419
|
* With `--fix`, apply every auto-fixable finding, then remind
|
|
414
420
|
* to reinstall.
|
|
415
421
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingram-tech/nk-dev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.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",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"@testing-library/jest-dom": "^7.0.1",
|
|
51
51
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
52
52
|
"jsdom": "^30.0.1",
|
|
53
|
-
"knip": "^6.
|
|
54
|
-
"oxfmt": "^0.
|
|
55
|
-
"oxlint": "^1.
|
|
53
|
+
"knip": "^6.35.1",
|
|
54
|
+
"oxfmt": "^0.67.0",
|
|
55
|
+
"oxlint": "^1.82.0",
|
|
56
56
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
57
57
|
"vitest": "^5.0.0"
|
|
58
58
|
},
|