@ingram-tech/nk-auth 0.19.3 → 0.19.4
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/chain.d.ts +5 -2
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +15 -4
- package/dist/chain.js.map +1 -1
- package/package.json +1 -1
- package/src/chain.ts +17 -6
package/dist/chain.d.ts
CHANGED
|
@@ -32,8 +32,11 @@ export interface AuthChainCheckOptions {
|
|
|
32
32
|
* Returns the runner's status when it is, or `null` when the database has no
|
|
33
33
|
* nk-auth journal table at all: a site that owns Better Auth's tables in its
|
|
34
34
|
* own chain (a squashed baseline) never records this one, and that is not a
|
|
35
|
-
* deployment mistake.
|
|
36
|
-
*
|
|
35
|
+
* deployment mistake. Also `null` when this role cannot read the journal (a
|
|
36
|
+
* least-privilege auth role with no access to the `drizzle` schema): it could
|
|
37
|
+
* not have applied the chain either, so there is nothing to verify through it.
|
|
38
|
+
* Throws {@link AuthChainNotAppliedError} when the journal exists but lags the
|
|
39
|
+
* installed package.
|
|
37
40
|
*
|
|
38
41
|
* `createAuthHelpers` runs this once per process on the first session read
|
|
39
42
|
* when the instance's `database` is a `pg` Pool; call it yourself from
|
package/dist/chain.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAGrF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,QAAO,MAOtC,CAAC;AAEH,wEAAwE;AACxE,eAAO,MAAM,qBAAqB,wBAAwB,CAAC;AAS3D;;;;;;GAMG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IAClD,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,YAAY,OAAO,EAAE,SAAS,MAAM,EAAE,EAMrC;CACD;AAED,MAAM,WAAW,qBAAqB;IACrC,sFAAsF;IACtF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,qDAAqD;IACrD,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAGrF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,QAAO,MAOtC,CAAC;AAEH,wEAAwE;AACxE,eAAO,MAAM,qBAAqB,wBAAwB,CAAC;AAS3D;;;;;;GAMG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IAClD,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,YAAY,OAAO,EAAE,SAAS,MAAM,EAAE,EAMrC;CACD;AAED,MAAM,WAAW,qBAAqB;IACrC,sFAAsF;IACtF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,qDAAqD;IACrD,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,SAC5B,IAAI,YACD,qBAAqB,KAC5B,OAAO,CAAC,eAAe,GAAG,IAAI,CA0BhC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,aAChB,OAAO,YACR,qBAAqB,KAC5B,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAOtB,CAAC"}
|
package/dist/chain.js
CHANGED
|
@@ -36,8 +36,11 @@ export class AuthChainNotAppliedError extends Error {
|
|
|
36
36
|
* Returns the runner's status when it is, or `null` when the database has no
|
|
37
37
|
* nk-auth journal table at all: a site that owns Better Auth's tables in its
|
|
38
38
|
* own chain (a squashed baseline) never records this one, and that is not a
|
|
39
|
-
* deployment mistake.
|
|
40
|
-
*
|
|
39
|
+
* deployment mistake. Also `null` when this role cannot read the journal (a
|
|
40
|
+
* least-privilege auth role with no access to the `drizzle` schema): it could
|
|
41
|
+
* not have applied the chain either, so there is nothing to verify through it.
|
|
42
|
+
* Throws {@link AuthChainNotAppliedError} when the journal exists but lags the
|
|
43
|
+
* installed package.
|
|
41
44
|
*
|
|
42
45
|
* `createAuthHelpers` runs this once per process on the first session read
|
|
43
46
|
* when the instance's `database` is a `pg` Pool; call it yourself from
|
|
@@ -46,8 +49,16 @@ export class AuthChainNotAppliedError extends Error {
|
|
|
46
49
|
export const assertAuthChainApplied = async (pool, options = {}) => {
|
|
47
50
|
const schema = options.migrationsSchema ?? "drizzle";
|
|
48
51
|
const table = options.migrationsTable ?? AUTH_MIGRATIONS_TABLE;
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
// Look the journal up in pg_catalog, which every role can read:
|
|
53
|
+
// `to_regclass` raises "permission denied" instead of returning null when the
|
|
54
|
+
// role lacks USAGE on the schema, and that broke every session read on a
|
|
55
|
+
// site whose auth role has no business in `drizzle`.
|
|
56
|
+
const { rows } = await pool.query(`select has_schema_privilege(n.oid, 'USAGE')
|
|
57
|
+
and has_table_privilege(c.oid, 'SELECT') as readable
|
|
58
|
+
from pg_catalog.pg_class c
|
|
59
|
+
join pg_catalog.pg_namespace n on n.oid = c.relnamespace
|
|
60
|
+
where n.nspname = $1 and c.relname = $2`, [schema, table]);
|
|
61
|
+
if (rows[0]?.readable !== true)
|
|
51
62
|
return null;
|
|
52
63
|
const status = await inspectMigrations({
|
|
53
64
|
pool,
|
package/dist/chain.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAwB,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAA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,EAAE;QACxC,gBAAgB,EAAE,MAAM;QACxB,eAAe,EAAE,KAAK;KACtB,CAAC,CAAC;IACH,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,wBAAwB,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC7B,QAAiB,EACjB,OAAO,GAA0B,EAAE,EACX,EAAE;IAC1B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,IAAI,EAAE,GAAE,CAAC,CAAC;IAC7C,IAAI,OAAkC,CAAC;IACvC,OAAO,GAAG,EAAE;QACX,OAAO,KAAK,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5E,OAAO,OAAO,CAAC;IAChB,CAAC,CAAC;AACH,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/chain.ts
CHANGED
|
@@ -59,8 +59,11 @@ export interface AuthChainCheckOptions {
|
|
|
59
59
|
* Returns the runner's status when it is, or `null` when the database has no
|
|
60
60
|
* nk-auth journal table at all: a site that owns Better Auth's tables in its
|
|
61
61
|
* own chain (a squashed baseline) never records this one, and that is not a
|
|
62
|
-
* deployment mistake.
|
|
63
|
-
*
|
|
62
|
+
* deployment mistake. Also `null` when this role cannot read the journal (a
|
|
63
|
+
* least-privilege auth role with no access to the `drizzle` schema): it could
|
|
64
|
+
* not have applied the chain either, so there is nothing to verify through it.
|
|
65
|
+
* Throws {@link AuthChainNotAppliedError} when the journal exists but lags the
|
|
66
|
+
* installed package.
|
|
64
67
|
*
|
|
65
68
|
* `createAuthHelpers` runs this once per process on the first session read
|
|
66
69
|
* when the instance's `database` is a `pg` Pool; call it yourself from
|
|
@@ -72,11 +75,19 @@ export const assertAuthChainApplied = async (
|
|
|
72
75
|
): Promise<MigrationStatus | null> => {
|
|
73
76
|
const schema = options.migrationsSchema ?? "drizzle";
|
|
74
77
|
const table = options.migrationsTable ?? AUTH_MIGRATIONS_TABLE;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
// Look the journal up in pg_catalog, which every role can read:
|
|
79
|
+
// `to_regclass` raises "permission denied" instead of returning null when the
|
|
80
|
+
// role lacks USAGE on the schema, and that broke every session read on a
|
|
81
|
+
// site whose auth role has no business in `drizzle`.
|
|
82
|
+
const { rows } = await pool.query<{ readable: boolean }>(
|
|
83
|
+
`select has_schema_privilege(n.oid, 'USAGE')
|
|
84
|
+
and has_table_privilege(c.oid, 'SELECT') as readable
|
|
85
|
+
from pg_catalog.pg_class c
|
|
86
|
+
join pg_catalog.pg_namespace n on n.oid = c.relnamespace
|
|
87
|
+
where n.nspname = $1 and c.relname = $2`,
|
|
88
|
+
[schema, table],
|
|
78
89
|
);
|
|
79
|
-
if (rows[0]?.
|
|
90
|
+
if (rows[0]?.readable !== true) return null;
|
|
80
91
|
const status = await inspectMigrations({
|
|
81
92
|
pool,
|
|
82
93
|
migrationsFolder: authMigrationsFolder(),
|