@ingram-tech/nk-auth 0.7.1 → 0.7.2

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/dist/id.d.ts CHANGED
@@ -1,32 +1,2 @@
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;
1
+ export { base58Id, fromPrefixedId, toPrefixedId, uuidGenerateId, } from "@ingram-tech/nk-db/id";
32
2
  //# sourceMappingURL=id.d.ts.map
package/dist/id.d.ts.map CHANGED
@@ -1 +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"}
1
+ {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,cAAc,GACd,MAAM,uBAAuB,CAAC"}
package/dist/id.js CHANGED
@@ -1,101 +1,7 @@
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
- }
1
+ // The Ingram id codec moved to `@ingram-tech/nk-db/id` — the lowest package in
2
+ // the graph — so a site can mint ids without pulling this auth slice. This
3
+ // re-export keeps `@ingram-tech/nk-auth/id` (and Better Auth's
4
+ // `advanced.database.generateId`, wired in `./options`) working unchanged. For
5
+ // the typed prefix registry (`createIdRegistry`), import from `@ingram-tech/nk-db/id`.
6
+ export { base58Id, fromPrefixedId, toPrefixedId, uuidGenerateId, } from "@ingram-tech/nk-db/id";
101
7
  //# sourceMappingURL=id.js.map
package/dist/id.js.map CHANGED
@@ -1 +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,CAAC;IACtB,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;IAC1C,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG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AAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;AAC5G,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,MAAc;IACxD,OAAO,GAAG,MAAM,IAAI,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;AACnD,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,cAAc,CAAC,EAAU;IACxC,MAAM,IAAI,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"}
1
+ {"version":3,"file":"id.js","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,2EAA2E;AAC3E,+DAA+D;AAC/D,+EAA+E;AAC/E,uFAAuF;AACvF,OAAO,EACN,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,cAAc,GACd,MAAM,uBAAuB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ingram-tech/nk-auth",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
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",
@@ -61,7 +61,7 @@
61
61
  "test": "vitest run"
62
62
  },
63
63
  "dependencies": {
64
- "@ingram-tech/nk-db": "^0.4.0",
64
+ "@ingram-tech/nk-db": "^0.5.0",
65
65
  "bcrypt": "^6.0.0",
66
66
  "jose": "^6.0.0",
67
67
  "zod": "^4.0.0"
@@ -93,7 +93,7 @@
93
93
  },
94
94
  "devDependencies": {
95
95
  "@better-auth/passkey": "^1.6.0",
96
- "@ingram-tech/typescript-config": "0.1.0",
96
+ "@ingram-tech/typescript-config": "workspace:*",
97
97
  "@supabase/supabase-js": "^2.45.0",
98
98
  "@types/bcrypt": "^6.0.0",
99
99
  "@types/node": "^25.0.0",