@ingram-tech/nk-auth 0.3.0 → 0.4.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 +6 -1
- package/dist/id.d.ts +32 -0
- package/dist/id.d.ts.map +1 -0
- package/dist/id.js +101 -0
- package/dist/id.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/options.d.ts +1 -11
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +4 -25
- package/dist/options.js.map +1 -1
- package/dist/pool.d.ts +12 -11
- package/dist/pool.d.ts.map +1 -1
- package/dist/pool.js +16 -29
- package/dist/pool.js.map +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ only what you need from focused subpaths.
|
|
|
22
22
|
> [`docs/better-auth-migration.md`](../../docs/better-auth-migration.md) — the
|
|
23
23
|
> RLS bridge, the migration runbook, and the gotchas.
|
|
24
24
|
>
|
|
25
|
-
> **Backend-JWT + org sites** (
|
|
25
|
+
> **Backend-JWT + org sites** (a backend API plus the org plugin): compose `createAuthPool`,
|
|
26
26
|
> `backendJwtOptions({ audience })`, `nkOrganizationDefaults`, and
|
|
27
27
|
> `lastActiveOrganizationHooks(pool)` in your `betterAuth()`; verify backend
|
|
28
28
|
> tokens with `verifyBackendJwt`. Keep app-specific bits (SSO restrictions,
|
|
@@ -96,6 +96,11 @@ export const auth = betterAuth({
|
|
|
96
96
|
baseURL: env.baseURL,
|
|
97
97
|
basePath: authBasePath, // mount at /auth, not the framework default /api/auth
|
|
98
98
|
advanced: { database: { generateId: uuidGenerateId } }, // UUIDv7 ids
|
|
99
|
+
// ^ stored as hyphenated UUIDv7 (uuid columns / Supabase RLS stay valid).
|
|
100
|
+
// To show those same ids as prefixed base58 on the wire/UI — `team_…`,
|
|
101
|
+
// matching the Ingram Cloud API's `agt_`/`smt_` ids — skin them with
|
|
102
|
+
// `toPrefixedId(uuid, "team")` / recover with `fromPrefixedId`. `base58Id`
|
|
103
|
+
// mints a fresh one directly for text-id sites. All from `@ingram-tech/nk-auth`.
|
|
99
104
|
emailAndPassword: {
|
|
100
105
|
enabled: true,
|
|
101
106
|
password: bcryptPassword, // verifies migrated Supabase bcrypt hashes
|
package/dist/id.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Ingram id codec — a UUIDv7 and its base58 skin. Dependency-light on
|
|
3
|
+
* purpose (only `node:crypto`), so a site can import it without pulling the
|
|
4
|
+
* bcrypt / passkey machinery in `./options`: `@ingram-tech/nk-auth/id`.
|
|
5
|
+
*
|
|
6
|
+
* The Python twin lives in cloud.ingram.tech's `v1/core.py` (`new_id`); the
|
|
7
|
+
* byte → string vectors in `id.test.ts` and that repo's `tests/test_ids.py` are
|
|
8
|
+
* kept identical, so a Better-Auth id (stored as a hyphenated UUIDv7 by
|
|
9
|
+
* {@link uuidGenerateId}) and an `agt_`/`smt_` id from the API are the same
|
|
10
|
+
* encoding of the same 16 bytes.
|
|
11
|
+
*
|
|
12
|
+
* The split is deliberate: keep storing the hyphenated UUIDv7 at rest (so
|
|
13
|
+
* Supabase `auth.uid()::uuid` / uuid columns keep working) and use
|
|
14
|
+
* {@link toPrefixedId} to skin it as a prefixed base58 id for the wire / display,
|
|
15
|
+
* {@link fromPrefixedId} to recover it. {@link base58Id} mints a fresh one
|
|
16
|
+
* directly, for text-id sites that want API-style ids natively.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* `advanced.database.generateId` for Better Auth — mints a **UUIDv7** (RFC 9562):
|
|
20
|
+
* a 48-bit Unix-ms timestamp prefix + random tail, version `7`, variant `10`.
|
|
21
|
+
* Keeps ids UUID-shaped (Supabase `auth.uid()::uuid`) while staying time-ordered
|
|
22
|
+
* for index locality. Node/Bun's `randomUUID` is v4-only, so we lay the bytes out
|
|
23
|
+
* by hand.
|
|
24
|
+
*/
|
|
25
|
+
export declare const uuidGenerateId: () => string;
|
|
26
|
+
/** Skin a stored hyphenated UUIDv7 as a prefixed base58 id, e.g. `team_…`. */
|
|
27
|
+
export declare function toPrefixedId(uuid: string, prefix: string): string;
|
|
28
|
+
/** Inverse of {@link toPrefixedId}: recover the hyphenated UUIDv7. */
|
|
29
|
+
export declare function fromPrefixedId(id: string): string;
|
|
30
|
+
/** Mint a fresh prefixed base58 id (UUIDv7 core), for text-id sites / API parity. */
|
|
31
|
+
export declare function base58Id(prefix: string): string;
|
|
32
|
+
//# sourceMappingURL=id.d.ts.map
|
package/dist/id.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,QAAO,MAYjC,CAAC;AAqDF,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAGjD;AAED,qFAAqF;AACrF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/C"}
|
package/dist/id.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* The Ingram id codec — a UUIDv7 and its base58 skin. Dependency-light on
|
|
4
|
+
* purpose (only `node:crypto`), so a site can import it without pulling the
|
|
5
|
+
* bcrypt / passkey machinery in `./options`: `@ingram-tech/nk-auth/id`.
|
|
6
|
+
*
|
|
7
|
+
* The Python twin lives in cloud.ingram.tech's `v1/core.py` (`new_id`); the
|
|
8
|
+
* byte → string vectors in `id.test.ts` and that repo's `tests/test_ids.py` are
|
|
9
|
+
* kept identical, so a Better-Auth id (stored as a hyphenated UUIDv7 by
|
|
10
|
+
* {@link uuidGenerateId}) and an `agt_`/`smt_` id from the API are the same
|
|
11
|
+
* encoding of the same 16 bytes.
|
|
12
|
+
*
|
|
13
|
+
* The split is deliberate: keep storing the hyphenated UUIDv7 at rest (so
|
|
14
|
+
* Supabase `auth.uid()::uuid` / uuid columns keep working) and use
|
|
15
|
+
* {@link toPrefixedId} to skin it as a prefixed base58 id for the wire / display,
|
|
16
|
+
* {@link fromPrefixedId} to recover it. {@link base58Id} mints a fresh one
|
|
17
|
+
* directly, for text-id sites that want API-style ids natively.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* `advanced.database.generateId` for Better Auth — mints a **UUIDv7** (RFC 9562):
|
|
21
|
+
* a 48-bit Unix-ms timestamp prefix + random tail, version `7`, variant `10`.
|
|
22
|
+
* Keeps ids UUID-shaped (Supabase `auth.uid()::uuid`) while staying time-ordered
|
|
23
|
+
* for index locality. Node/Bun's `randomUUID` is v4-only, so we lay the bytes out
|
|
24
|
+
* by hand.
|
|
25
|
+
*/
|
|
26
|
+
export const uuidGenerateId = () => {
|
|
27
|
+
const bytes = randomBytes(16);
|
|
28
|
+
const ts = Date.now();
|
|
29
|
+
bytes[0] = Math.floor(ts / 2 ** 40) & 0xff;
|
|
30
|
+
bytes[1] = Math.floor(ts / 2 ** 32) & 0xff;
|
|
31
|
+
bytes[2] = Math.floor(ts / 2 ** 24) & 0xff;
|
|
32
|
+
bytes[3] = Math.floor(ts / 2 ** 16) & 0xff;
|
|
33
|
+
bytes[4] = Math.floor(ts / 2 ** 8) & 0xff;
|
|
34
|
+
bytes[5] = ts & 0xff;
|
|
35
|
+
bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x70; // version 7
|
|
36
|
+
bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80; // variant 10
|
|
37
|
+
return bytesToUuid(bytes);
|
|
38
|
+
};
|
|
39
|
+
const B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
40
|
+
// ceil(128 / log2(58)): a 16-byte value never needs more than 22 digits. We
|
|
41
|
+
// left-pad to it so every body is uniform width and sorts lexically ==
|
|
42
|
+
// chronologically (UUIDv7's ms-timestamp prefix lives in the high bytes).
|
|
43
|
+
const WIDTH = 22;
|
|
44
|
+
/** Big-endian base58 (Bitcoin alphabet) of 16 bytes, left-padded to `WIDTH`. */
|
|
45
|
+
function encode58(bytes) {
|
|
46
|
+
let n = 0n;
|
|
47
|
+
for (const b of bytes)
|
|
48
|
+
n = (n << 8n) | BigInt(b);
|
|
49
|
+
let out = "";
|
|
50
|
+
while (n > 0n) {
|
|
51
|
+
out = B58.charAt(Number(n % 58n)) + out;
|
|
52
|
+
n /= 58n;
|
|
53
|
+
}
|
|
54
|
+
return out.padStart(WIDTH, B58.charAt(0));
|
|
55
|
+
}
|
|
56
|
+
/** Inverse of {@link encode58}: a base58 body back to 16 bytes. */
|
|
57
|
+
function decode58(body) {
|
|
58
|
+
let n = 0n;
|
|
59
|
+
for (const ch of body) {
|
|
60
|
+
const v = B58.indexOf(ch);
|
|
61
|
+
if (v < 0)
|
|
62
|
+
throw new Error(`invalid base58 char: ${ch}`);
|
|
63
|
+
n = n * 58n + BigInt(v);
|
|
64
|
+
}
|
|
65
|
+
const bytes = new Uint8Array(16);
|
|
66
|
+
for (let i = 15; i >= 0; i--) {
|
|
67
|
+
bytes[i] = Number(n & 0xffn);
|
|
68
|
+
n >>= 8n;
|
|
69
|
+
}
|
|
70
|
+
return bytes;
|
|
71
|
+
}
|
|
72
|
+
/** A hyphenated UUID string → its 16 raw bytes. */
|
|
73
|
+
function uuidToBytes(uuid) {
|
|
74
|
+
const hex = uuid.replace(/-/g, "");
|
|
75
|
+
if (!/^[0-9a-fA-F]{32}$/.test(hex))
|
|
76
|
+
throw new Error(`not a uuid: ${uuid}`);
|
|
77
|
+
const bytes = new Uint8Array(16);
|
|
78
|
+
for (let i = 0; i < 16; i++) {
|
|
79
|
+
bytes[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
80
|
+
}
|
|
81
|
+
return bytes;
|
|
82
|
+
}
|
|
83
|
+
/** 16 raw bytes → a canonical hyphenated UUID string. */
|
|
84
|
+
function bytesToUuid(bytes) {
|
|
85
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
86
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
87
|
+
}
|
|
88
|
+
/** Skin a stored hyphenated UUIDv7 as a prefixed base58 id, e.g. `team_…`. */
|
|
89
|
+
export function toPrefixedId(uuid, prefix) {
|
|
90
|
+
return `${prefix}_${encode58(uuidToBytes(uuid))}`;
|
|
91
|
+
}
|
|
92
|
+
/** Inverse of {@link toPrefixedId}: recover the hyphenated UUIDv7. */
|
|
93
|
+
export function fromPrefixedId(id) {
|
|
94
|
+
const body = id.slice(id.indexOf("_") + 1);
|
|
95
|
+
return bytesToUuid(decode58(body));
|
|
96
|
+
}
|
|
97
|
+
/** Mint a fresh prefixed base58 id (UUIDv7 core), for text-id sites / API parity. */
|
|
98
|
+
export function base58Id(prefix) {
|
|
99
|
+
return toPrefixedId(uuidGenerateId(), prefix);
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=id.js.map
|
package/dist/id.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.js","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAW,EAAE;IAC1C,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;IAC9B,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CA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I,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3C,OAAO,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,QAAQ,CAAC,MAAc;IACtC,OAAO,YAAY,CAAC,cAAc,EAAE,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { type BackendJwtConfig, backendJwtOptions, rlsJwtOptions, verifyBackendJwt, } from "./jwt";
|
|
2
|
+
export { base58Id, fromPrefixedId, toPrefixedId, uuidGenerateId } from "./id";
|
|
2
3
|
export { type AuthEnv, authEnv, isConfigured } from "./keys";
|
|
3
|
-
export { bcryptPassword, makeEmailSenders, makePasskeyOptions, type PasskeyConfig, type SendEmail,
|
|
4
|
+
export { bcryptPassword, makeEmailSenders, makePasskeyOptions, type PasskeyConfig, type SendEmail, } from "./options";
|
|
4
5
|
export { lastActiveOrganizationHooks, lastActiveOrganizationUserField, nkOrganizationDefaults, } from "./organization";
|
|
5
6
|
export { authBasePath } from "./paths";
|
|
6
7
|
export { createAuthPool } from "./pool";
|
|
7
|
-
export { createServerSupabase, type ServerSupabaseConfig
|
|
8
|
+
export { createServerSupabase, type ServerSupabaseConfig } from "./supabase";
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,aAAa,EACb,gBAAgB,GAChB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,aAAa,EACb,gBAAgB,GAChB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC9E,OAAO,EAAE,KAAK,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,GACd,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,2BAA2B,EAC3B,+BAA+B,EAC/B,sBAAsB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
// React. Focused subpaths (./jwt, ./organization, ./pool) let a site import
|
|
4
4
|
// only what it needs (e.g. avoid bcrypt/supabase when it uses neither).
|
|
5
5
|
export { backendJwtOptions, rlsJwtOptions, verifyBackendJwt, } from "./jwt";
|
|
6
|
+
export { base58Id, fromPrefixedId, toPrefixedId, uuidGenerateId } from "./id";
|
|
6
7
|
export { authEnv, isConfigured } from "./keys";
|
|
7
|
-
export { bcryptPassword, makeEmailSenders, makePasskeyOptions,
|
|
8
|
+
export { bcryptPassword, makeEmailSenders, makePasskeyOptions, } from "./options";
|
|
8
9
|
export { lastActiveOrganizationHooks, lastActiveOrganizationUserField, nkOrganizationDefaults, } from "./organization";
|
|
9
10
|
export { authBasePath } from "./paths";
|
|
10
11
|
export { createAuthPool } from "./pool";
|
|
11
|
-
export { createServerSupabase
|
|
12
|
+
export { createServerSupabase } from "./supabase";
|
|
12
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AAExE,OAAO,EAEN,iBAAiB,EACjB,aAAa,EACb,gBAAgB,GAChB,MAAM,OAAO,CAAC;AACf,OAAO,EAAgB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,+EAA+E;AAC/E,4EAA4E;AAC5E,wEAAwE;AAExE,OAAO,EAEN,iBAAiB,EACjB,aAAa,EACb,gBAAgB,GAChB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC9E,OAAO,EAAgB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,kBAAkB,GAGlB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,2BAA2B,EAC3B,+BAA+B,EAC/B,sBAAsB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAA6B,MAAM,YAAY,CAAC"}
|
package/dist/options.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PasskeyOptions } from "@better-auth/passkey";
|
|
2
|
+
export { uuidGenerateId } from "./id";
|
|
2
3
|
/**
|
|
3
4
|
* Portable Better Auth building blocks for Ingram sites.
|
|
4
5
|
*
|
|
@@ -7,10 +8,6 @@ import type { PasskeyOptions } from "@better-auth/passkey";
|
|
|
7
8
|
* call site (where `declaration` is off) and respects the prime directive — the
|
|
8
9
|
* site stays plain Better Auth, we just ship the shared config. JWT + org
|
|
9
10
|
* presets live in `./jwt` and `./organization`. See docs/better-auth-migration.md.
|
|
10
|
-
*
|
|
11
|
-
* `uuidGenerateId` keeps new-user ids UUID-shaped (so Supabase `auth.uid()::uuid`
|
|
12
|
-
* keeps working on RLS sites) — and specifically **UUIDv7**: time-ordered, so ids
|
|
13
|
-
* cluster by creation time for index locality instead of scattering like v4.
|
|
14
11
|
*/
|
|
15
12
|
/**
|
|
16
13
|
* `emailAndPassword.password` config. Verifies with bcrypt so passwords
|
|
@@ -23,13 +20,6 @@ export declare const bcryptPassword: {
|
|
|
23
20
|
password: string;
|
|
24
21
|
}) => Promise<boolean>;
|
|
25
22
|
};
|
|
26
|
-
/**
|
|
27
|
-
* `advanced.database.generateId` — mints a **UUIDv7** (RFC 9562): a 48-bit
|
|
28
|
-
* Unix-ms timestamp prefix + random tail, version `7`, variant `10`. Keeps ids
|
|
29
|
-
* UUID-shaped (Supabase `auth.uid()::uuid`) while staying time-ordered.
|
|
30
|
-
* Node/Bun's `randomUUID` is v4-only, so we lay the bytes out by hand.
|
|
31
|
-
*/
|
|
32
|
-
export declare const uuidGenerateId: () => string;
|
|
33
23
|
export interface PasskeyConfig {
|
|
34
24
|
/** Relying-party id: the registrable domain, e.g. "example.com". */
|
|
35
25
|
rpId: string;
|
package/dist/options.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAEtC;;;;;;;;GAQG;AAEH;;;GAGG;AACH,eAAO,MAAM,cAAc;qBACT,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC;kCAItC;QACF,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;KACjB,KAAG,OAAO,CAAC,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,WAAW,aAAa;IAC7B,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC1B;AAED,iFAAiF;AACjF,eAAO,MAAM,kBAAkB,GAAI,KAAK,aAAa,KAAG,cAItD,CAAC;AAEH,iFAAiF;AACjF,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACZ,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEvB;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,SAAS;wCAI5C;QACF,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;QACxB,GAAG,EAAE,MAAM,CAAC;KACZ,KAAG,OAAO,CAAC,IAAI,CAAC;4CAMd;QACF,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;QACxB,GAAG,EAAE,MAAM,CAAC;KACZ,KAAG,OAAO,CAAC,IAAI,CAAC;CAGhB,CAAC"}
|
package/dist/options.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { randomBytes } from "node:crypto";
|
|
2
1
|
import bcrypt from "bcrypt";
|
|
2
|
+
// `uuidGenerateId` (the `advanced.database.generateId` UUIDv7 generator) and the
|
|
3
|
+
// base58 skin now live in the dependency-light `./id` module; re-exported here so
|
|
4
|
+
// existing `from "@ingram-tech/nk-auth"` imports keep resolving.
|
|
5
|
+
export { uuidGenerateId } from "./id";
|
|
3
6
|
/**
|
|
4
7
|
* Portable Better Auth building blocks for Ingram sites.
|
|
5
8
|
*
|
|
@@ -8,10 +11,6 @@ import bcrypt from "bcrypt";
|
|
|
8
11
|
* call site (where `declaration` is off) and respects the prime directive — the
|
|
9
12
|
* site stays plain Better Auth, we just ship the shared config. JWT + org
|
|
10
13
|
* presets live in `./jwt` and `./organization`. See docs/better-auth-migration.md.
|
|
11
|
-
*
|
|
12
|
-
* `uuidGenerateId` keeps new-user ids UUID-shaped (so Supabase `auth.uid()::uuid`
|
|
13
|
-
* keeps working on RLS sites) — and specifically **UUIDv7**: time-ordered, so ids
|
|
14
|
-
* cluster by creation time for index locality instead of scattering like v4.
|
|
15
14
|
*/
|
|
16
15
|
/**
|
|
17
16
|
* `emailAndPassword.password` config. Verifies with bcrypt so passwords
|
|
@@ -21,26 +20,6 @@ export const bcryptPassword = {
|
|
|
21
20
|
hash: (password) => bcrypt.hash(password, 10),
|
|
22
21
|
verify: ({ hash, password, }) => bcrypt.compare(password, hash),
|
|
23
22
|
};
|
|
24
|
-
/**
|
|
25
|
-
* `advanced.database.generateId` — mints a **UUIDv7** (RFC 9562): a 48-bit
|
|
26
|
-
* Unix-ms timestamp prefix + random tail, version `7`, variant `10`. Keeps ids
|
|
27
|
-
* UUID-shaped (Supabase `auth.uid()::uuid`) while staying time-ordered.
|
|
28
|
-
* Node/Bun's `randomUUID` is v4-only, so we lay the bytes out by hand.
|
|
29
|
-
*/
|
|
30
|
-
export const uuidGenerateId = () => {
|
|
31
|
-
const bytes = randomBytes(16);
|
|
32
|
-
const ts = Date.now();
|
|
33
|
-
bytes[0] = Math.floor(ts / 2 ** 40) & 0xff;
|
|
34
|
-
bytes[1] = Math.floor(ts / 2 ** 32) & 0xff;
|
|
35
|
-
bytes[2] = Math.floor(ts / 2 ** 24) & 0xff;
|
|
36
|
-
bytes[3] = Math.floor(ts / 2 ** 16) & 0xff;
|
|
37
|
-
bytes[4] = Math.floor(ts / 2 ** 8) & 0xff;
|
|
38
|
-
bytes[5] = ts & 0xff;
|
|
39
|
-
bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x70; // version 7
|
|
40
|
-
bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80; // variant 10
|
|
41
|
-
const hex = bytes.toString("hex");
|
|
42
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
43
|
-
};
|
|
44
23
|
/** Build `passkey` plugin options. Use as `passkey(makePasskeyOptions(cfg))`. */
|
|
45
24
|
export const makePasskeyOptions = (cfg) => ({
|
|
46
25
|
rpID: cfg.rpId,
|
package/dist/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,iFAAiF;AACjF,kFAAkF;AAClF,iEAAiE;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAEtC;;;;;;;;GAQG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC7B,IAAI,EAAE,CAAC,QAAgB,EAAmB,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;IACtE,MAAM,EAAE,CAAC,EACR,IAAI,EACJ,QAAQ,GAIR,EAAoB,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC;CACtD,CAAC;AAWF,iFAAiF;AACjF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAkB,EAAkB,EAAE,CAAC,CAAC;IAC1E,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,MAAM,EAAE,GAAG,CAAC,MAAM;IAClB,MAAM,EAAE,GAAG,CAAC,MAAM;CAClB,CAAC,CAAC;AASH;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAe,EAAE,EAAE,CAAC,CAAC;IACrD,iBAAiB,EAAE,KAAK,EAAE,EACzB,IAAI,EACJ,GAAG,GAIH,EAAiB,EAAE;QACnB,MAAM,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAC;IACrE,CAAC;IACD,qBAAqB,EAAE,KAAK,EAAE,EAC7B,IAAI,EACJ,GAAG,GAIH,EAAiB,EAAE;QACnB,MAAM,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC;IACnE,CAAC;CACD,CAAC,CAAC"}
|
package/dist/pool.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { Pool } from "pg";
|
|
1
|
+
import type { Pool } from "pg";
|
|
2
2
|
/**
|
|
3
|
-
* A `pg` Pool for Better Auth's direct database connection
|
|
4
|
-
* for each kind of host:
|
|
3
|
+
* A `pg` Pool for Better Auth's direct database connection.
|
|
5
4
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
5
|
+
* @deprecated Thin alias for `createPool` from `@ingram-tech/nk-db` — the one
|
|
6
|
+
* place pool construction and TLS handling live. Kept so existing call sites
|
|
7
|
+
* (`lib/db.ts` calling `createAuthPool({ connectionString, caCert })`) keep
|
|
8
|
+
* working, and so Better Auth shares the **exact same pool implementation** as
|
|
9
|
+
* app queries — the "one pool per process" rule. Prefer importing `createPool`
|
|
10
|
+
* directly in new code.
|
|
11
|
+
*
|
|
12
|
+
* TLS handling (CA-verified when `caCert` is set; plain-TLS for other managed
|
|
13
|
+
* hosts; no TLS for localhost), and the local `max: 1` cap (for the PGlite
|
|
14
|
+
* socket), all live in `createPool`.
|
|
14
15
|
*/
|
|
15
16
|
export declare const createAuthPool: (config: {
|
|
16
17
|
connectionString: string;
|
package/dist/pool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ;IACtC,gBAAgB,EAAE,MAAM,CAAC;IACzB,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,KAAG,IAID,CAAC"}
|
package/dist/pool.js
CHANGED
|
@@ -1,33 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const isLocal = (connectionString) => connectionString.includes("127.0.0.1") || connectionString.includes("localhost");
|
|
1
|
+
import { createPool } from "@ingram-tech/nk-db";
|
|
3
2
|
/**
|
|
4
|
-
* A `pg` Pool for Better Auth's direct database connection
|
|
5
|
-
* for each kind of host:
|
|
3
|
+
* A `pg` Pool for Better Auth's direct database connection.
|
|
6
4
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
5
|
+
* @deprecated Thin alias for `createPool` from `@ingram-tech/nk-db` — the one
|
|
6
|
+
* place pool construction and TLS handling live. Kept so existing call sites
|
|
7
|
+
* (`lib/db.ts` calling `createAuthPool({ connectionString, caCert })`) keep
|
|
8
|
+
* working, and so Better Auth shares the **exact same pool implementation** as
|
|
9
|
+
* app queries — the "one pool per process" rule. Prefer importing `createPool`
|
|
10
|
+
* directly in new code.
|
|
11
|
+
*
|
|
12
|
+
* TLS handling (CA-verified when `caCert` is set; plain-TLS for other managed
|
|
13
|
+
* hosts; no TLS for localhost), and the local `max: 1` cap (for the PGlite
|
|
14
|
+
* socket), all live in `createPool`.
|
|
15
15
|
*/
|
|
16
|
-
export const createAuthPool = (config) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
ssl: { ca: config.caCert, rejectUnauthorized: true },
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
if (isLocal(config.connectionString)) {
|
|
24
|
-
return new Pool({ connectionString: config.connectionString });
|
|
25
|
-
}
|
|
26
|
-
const url = new URL(config.connectionString);
|
|
27
|
-
url.searchParams.delete("sslmode");
|
|
28
|
-
return new Pool({
|
|
29
|
-
connectionString: url.toString(),
|
|
30
|
-
ssl: { rejectUnauthorized: false },
|
|
31
|
-
});
|
|
32
|
-
};
|
|
16
|
+
export const createAuthPool = (config) => createPool({
|
|
17
|
+
connectionString: config.connectionString,
|
|
18
|
+
caCert: config.caCert,
|
|
19
|
+
});
|
|
33
20
|
//# sourceMappingURL=pool.js.map
|
package/dist/pool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAI9B,EAAQ,EAAE,CACV,UAAU,CAAC;IACV,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;IACzC,MAAM,EAAE,MAAM,CAAC,MAAM;CACrB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingram-tech/nk-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "The Ingram Better Auth foundation: composable presets (org, dual-shape JWT, Supabase RLS bridge, active-org hooks, pg pool) for Next.js sites.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"import": "./dist/index.js"
|
|
23
23
|
},
|
|
24
|
+
"./id": {
|
|
25
|
+
"types": "./dist/id.d.ts",
|
|
26
|
+
"import": "./dist/id.js"
|
|
27
|
+
},
|
|
24
28
|
"./jwt": {
|
|
25
29
|
"types": "./dist/jwt.d.ts",
|
|
26
30
|
"import": "./dist/jwt.js"
|
|
@@ -49,6 +53,7 @@
|
|
|
49
53
|
"test": "vitest run"
|
|
50
54
|
},
|
|
51
55
|
"dependencies": {
|
|
56
|
+
"@ingram-tech/nk-db": "^0.2.0",
|
|
52
57
|
"bcrypt": "^5.1.1",
|
|
53
58
|
"jose": "^6.0.0",
|
|
54
59
|
"zod": "^4.0.0"
|