@smplcty/auth 0.6.3 → 1.0.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.
Files changed (93) hide show
  1. package/README.md +198 -223
  2. package/dist/create-session.d.ts +10 -9
  3. package/dist/create-session.d.ts.map +1 -1
  4. package/dist/create-session.js +18 -23
  5. package/dist/create-session.js.map +1 -1
  6. package/dist/dev-otp.d.ts.map +1 -1
  7. package/dist/dev-otp.js +4 -10
  8. package/dist/dev-otp.js.map +1 -1
  9. package/dist/errors.d.ts +19 -4
  10. package/dist/errors.d.ts.map +1 -1
  11. package/dist/errors.js +23 -5
  12. package/dist/errors.js.map +1 -1
  13. package/dist/find-user-by-communication-method.d.ts.map +1 -1
  14. package/dist/find-user-by-communication-method.js +8 -1
  15. package/dist/find-user-by-communication-method.js.map +1 -1
  16. package/dist/get-user-role-names.d.ts.map +1 -1
  17. package/dist/get-user-role-names.js +2 -0
  18. package/dist/get-user-role-names.js.map +1 -1
  19. package/dist/index.d.ts +10 -6
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +13 -7
  22. package/dist/index.js.map +1 -1
  23. package/dist/internal/hash-token.d.ts +16 -0
  24. package/dist/internal/hash-token.d.ts.map +1 -0
  25. package/dist/internal/hash-token.js +21 -0
  26. package/dist/internal/hash-token.js.map +1 -0
  27. package/dist/methods/errors.d.ts +37 -0
  28. package/dist/methods/errors.d.ts.map +1 -0
  29. package/dist/methods/errors.js +48 -0
  30. package/dist/methods/errors.js.map +1 -0
  31. package/dist/methods/oidc/index.d.ts +65 -0
  32. package/dist/methods/oidc/index.d.ts.map +1 -0
  33. package/dist/methods/oidc/index.js +76 -0
  34. package/dist/methods/oidc/index.js.map +1 -0
  35. package/dist/methods/router.d.ts +39 -0
  36. package/dist/methods/router.d.ts.map +1 -0
  37. package/dist/methods/router.js +153 -0
  38. package/dist/methods/router.js.map +1 -0
  39. package/dist/methods/twilio/index.d.ts +44 -0
  40. package/dist/methods/twilio/index.d.ts.map +1 -0
  41. package/dist/methods/twilio/index.js +77 -0
  42. package/dist/methods/twilio/index.js.map +1 -0
  43. package/dist/methods/types.d.ts +124 -0
  44. package/dist/methods/types.d.ts.map +1 -0
  45. package/dist/methods/types.js +2 -0
  46. package/dist/methods/types.js.map +1 -0
  47. package/dist/revoke-session.d.ts +20 -15
  48. package/dist/revoke-session.d.ts.map +1 -1
  49. package/dist/revoke-session.js +66 -20
  50. package/dist/revoke-session.js.map +1 -1
  51. package/dist/scope/flat-tenant.d.ts +36 -0
  52. package/dist/scope/flat-tenant.d.ts.map +1 -0
  53. package/dist/scope/flat-tenant.js +60 -0
  54. package/dist/scope/flat-tenant.js.map +1 -0
  55. package/dist/set-helpers.d.ts +44 -53
  56. package/dist/set-helpers.d.ts.map +1 -1
  57. package/dist/set-helpers.js +67 -74
  58. package/dist/set-helpers.js.map +1 -1
  59. package/dist/touch-session.d.ts +13 -0
  60. package/dist/touch-session.d.ts.map +1 -0
  61. package/dist/touch-session.js +28 -0
  62. package/dist/touch-session.js.map +1 -0
  63. package/dist/types.d.ts +59 -18
  64. package/dist/types.d.ts.map +1 -1
  65. package/dist/validate-session.d.ts +15 -14
  66. package/dist/validate-session.d.ts.map +1 -1
  67. package/dist/validate-session.js +28 -27
  68. package/dist/validate-session.js.map +1 -1
  69. package/dist/with-service-context.d.ts +15 -12
  70. package/dist/with-service-context.d.ts.map +1 -1
  71. package/dist/with-service-context.js +34 -39
  72. package/dist/with-service-context.js.map +1 -1
  73. package/dist/with-session.d.ts +22 -16
  74. package/dist/with-session.d.ts.map +1 -1
  75. package/dist/with-session.js +67 -66
  76. package/dist/with-session.js.map +1 -1
  77. package/package.json +53 -4
  78. package/schema/functions/current_user_id.yaml +18 -0
  79. package/schema/functions/resolve_session.yaml +42 -23
  80. package/schema/post/0001-backfill-audit-by.sql +15 -0
  81. package/schema/tables/auth_domains.yaml +43 -0
  82. package/schema/tables/communication_channels.yaml +5 -1
  83. package/schema/tables/dev_otp_enrollments.yaml +1 -0
  84. package/schema/tables/roles.yaml +43 -7
  85. package/schema/tables/sessions.yaml +10 -0
  86. package/schema/tables/tenants.yaml +24 -1
  87. package/schema/tables/user_communication_methods.yaml +5 -1
  88. package/schema/tables/user_roles.yaml +1 -0
  89. package/schema/tables/users.yaml +27 -0
  90. package/dist/with-transaction.d.ts +0 -31
  91. package/dist/with-transaction.d.ts.map +0 -1
  92. package/dist/with-transaction.js +0 -49
  93. package/dist/with-transaction.js.map +0 -1
@@ -1,22 +1,27 @@
1
1
  import type { Queryable } from './types.js';
2
2
  /**
3
- * Revoke a session by setting its `expires_at` to now.
3
+ * Revoke a single session by its raw token (force sign-off of that one
4
+ * session). Idempotent — revoking an unknown or already-expired session is
5
+ * not an error. The row is preserved for audit.
4
6
  *
5
- * The session row is preserved for audit — you can distinguish
6
- * "explicitly revoked" (expires_at close to created_at) from
7
- * "expired naturally" (expires_at = created_at + ttl). The
8
- * `session_authorization()` RLS function already checks
9
- * `expires_at > now()`, so the session is locked out immediately.
10
- *
11
- * Idempotent: revoking a non-existent or already-expired session
12
- * is not an error.
7
+ * @throws {InvalidInputError} If `token` is not a non-empty string.
8
+ */
9
+ export declare function revokeSession(db: Queryable, token: string): Promise<void>;
10
+ /**
11
+ * Revoke every active session belonging to a user (force sign-off
12
+ * everywhere). Use on password reset, account lockout, or a
13
+ * role/privilege change that should drop existing sessions.
13
14
  *
14
- * @example
15
- * ```ts
16
- * await revokeSession(db, sessionId);
17
- * ```
15
+ * @throws {InvalidInputError} If `userId` is not a positive integer.
16
+ */
17
+ export declare function revokeUserSessions(db: Queryable, userId: number): Promise<void>;
18
+ /**
19
+ * Revoke every active session of every user explicitly in a tenant
20
+ * (tenant-wide sign-off). Membership is resolved from `user_roles.tenant_id`
21
+ * — wildcard members (NULL tenant) are intentionally **not** signed out,
22
+ * since they belong to no single tenant.
18
23
  *
19
- * @throws {InvalidInputError} If `sessionId` is not a non-empty string.
24
+ * @throws {InvalidInputError} If `tenantId` is not a positive integer.
20
25
  */
21
- export declare function revokeSession(db: Queryable, sessionId: string): Promise<void>;
26
+ export declare function revokeTenantSessions(db: Queryable, tenantId: number): Promise<void>;
22
27
  //# sourceMappingURL=revoke-session.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"revoke-session.d.ts","sourceRoot":"","sources":["../src/revoke-session.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAS5C;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,aAAa,CACjC,EAAE,EAAE,SAAS,EACb,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAKf"}
1
+ {"version":3,"file":"revoke-session.d.ts","sourceRoot":"","sources":["../src/revoke-session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAyC5C;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK/E;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKrF;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKzF"}
@@ -1,33 +1,79 @@
1
1
  import { InvalidInputError } from './errors.js';
2
- const EXPIRE_SESSION = `
2
+ import { hashToken } from './internal/hash-token.js';
3
+ // Soft-revoke: set expires_at = now() so the row survives for audit but
4
+ // the session is locked out immediately (withSession/validateSession both
5
+ // reject expires_at <= now()). Guarded so we don't move an already-past
6
+ // expiry around.
7
+ const EXPIRE_BY_HASH = `
3
8
  UPDATE sessions
4
9
  SET expires_at = now()
5
10
  WHERE session_id = $1
6
- AND (expires_at IS NULL OR expires_at > now())
11
+ AND expires_at > now()
12
+ `;
13
+ const EXPIRE_BY_USER = `
14
+ UPDATE sessions s
15
+ SET expires_at = now()
16
+ FROM user_communication_methods ucm
17
+ WHERE ucm.user_communication_method_id = s.user_communication_method_id
18
+ AND ucm.user_id = $1
19
+ AND s.expires_at > now()
20
+ `;
21
+ // Tenant-wide sign-off. Membership IS user_roles.tenant_id (the contract;
22
+ // there is no user_tenants table), so the library resolves "users in
23
+ // tenant X" itself and fans out. The match is tenant_id = $1, NOT
24
+ // tenant_id IS NULL: wildcard members (NULL = all-tenants global admins /
25
+ // service principals) are not members of any one tenant and must not be
26
+ // signed out by a single tenant's sign-off.
27
+ const EXPIRE_BY_TENANT = `
28
+ UPDATE sessions s
29
+ SET expires_at = now()
30
+ FROM user_communication_methods ucm
31
+ WHERE ucm.user_communication_method_id = s.user_communication_method_id
32
+ AND s.expires_at > now()
33
+ AND ucm.user_id IN (
34
+ SELECT DISTINCT ur.user_id
35
+ FROM user_roles ur
36
+ WHERE ur.tenant_id = $1
37
+ )
7
38
  `;
8
39
  /**
9
- * Revoke a session by setting its `expires_at` to now.
40
+ * Revoke a single session by its raw token (force sign-off of that one
41
+ * session). Idempotent — revoking an unknown or already-expired session is
42
+ * not an error. The row is preserved for audit.
10
43
  *
11
- * The session row is preserved for audit — you can distinguish
12
- * "explicitly revoked" (expires_at close to created_at) from
13
- * "expired naturally" (expires_at = created_at + ttl). The
14
- * `session_authorization()` RLS function already checks
15
- * `expires_at > now()`, so the session is locked out immediately.
16
- *
17
- * Idempotent: revoking a non-existent or already-expired session
18
- * is not an error.
44
+ * @throws {InvalidInputError} If `token` is not a non-empty string.
45
+ */
46
+ export async function revokeSession(db, token) {
47
+ if (typeof token !== 'string' || token.length === 0) {
48
+ throw new InvalidInputError('token must be a non-empty string');
49
+ }
50
+ await db.query(EXPIRE_BY_HASH, [hashToken(token)]);
51
+ }
52
+ /**
53
+ * Revoke every active session belonging to a user (force sign-off
54
+ * everywhere). Use on password reset, account lockout, or a
55
+ * role/privilege change that should drop existing sessions.
19
56
  *
20
- * @example
21
- * ```ts
22
- * await revokeSession(db, sessionId);
23
- * ```
57
+ * @throws {InvalidInputError} If `userId` is not a positive integer.
58
+ */
59
+ export async function revokeUserSessions(db, userId) {
60
+ if (!Number.isInteger(userId) || userId <= 0) {
61
+ throw new InvalidInputError('userId must be a positive integer');
62
+ }
63
+ await db.query(EXPIRE_BY_USER, [userId]);
64
+ }
65
+ /**
66
+ * Revoke every active session of every user explicitly in a tenant
67
+ * (tenant-wide sign-off). Membership is resolved from `user_roles.tenant_id`
68
+ * — wildcard members (NULL tenant) are intentionally **not** signed out,
69
+ * since they belong to no single tenant.
24
70
  *
25
- * @throws {InvalidInputError} If `sessionId` is not a non-empty string.
71
+ * @throws {InvalidInputError} If `tenantId` is not a positive integer.
26
72
  */
27
- export async function revokeSession(db, sessionId) {
28
- if (typeof sessionId !== 'string' || sessionId.length === 0) {
29
- throw new InvalidInputError('sessionId must be a non-empty string');
73
+ export async function revokeTenantSessions(db, tenantId) {
74
+ if (!Number.isInteger(tenantId) || tenantId <= 0) {
75
+ throw new InvalidInputError('tenantId must be a positive integer');
30
76
  }
31
- await db.query(EXPIRE_SESSION, [sessionId]);
77
+ await db.query(EXPIRE_BY_TENANT, [tenantId]);
32
78
  }
33
79
  //# sourceMappingURL=revoke-session.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"revoke-session.js","sourceRoot":"","sources":["../src/revoke-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,cAAc,GAAG;;;;;CAKtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,EAAa,EACb,SAAiB;IAEjB,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,iBAAiB,C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CAAC;AAC3C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,EAAa,EAAE,QAAgB;IACxE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,iBAAiB,CAAC,qCAAqC,CAAC,CAAC;IACrE,CAAC;IACD,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { ScopeHook } from '../types.js';
2
+ /**
3
+ * The flat-tenant scope GUCs. Set by the {@link flatTenantScope} preset;
4
+ * **not** part of the core identity contract. Reference them in RLS
5
+ * policies if you adopt the preset.
6
+ *
7
+ * - `app.tenant_ids` — comma-separated tenant ids the user belongs to.
8
+ * - `app.all_tenants` — `'true'` when the user has a wildcard
9
+ * (`tenant_id IS NULL`) membership; such users see every tenant.
10
+ */
11
+ export declare const FLAT_TENANT_GUC: {
12
+ readonly tenantIds: "app.tenant_ids";
13
+ readonly allTenants: "app.all_tenants";
14
+ };
15
+ /**
16
+ * A ready-made scope hook implementing the flat `tenant_ids` /
17
+ * `all_tenants` model (the 0.6.x behavior), now opt-in rather than baked
18
+ * into the core.
19
+ *
20
+ * Adopt it for simple multi-tenant apps that don't need a custom scope:
21
+ *
22
+ * ```ts
23
+ * import { withSession } from '@smplcty/auth';
24
+ * import { flatTenantScope } from '@smplcty/auth/flat-tenant';
25
+ *
26
+ * const scope = flatTenantScope();
27
+ * await withSession(pool, { token }, fn, { scope });
28
+ * ```
29
+ *
30
+ * It sets `app.tenant_ids` and `app.all_tenants` from the user's
31
+ * `user_roles` rows. Your RLS policies read those GUCs to filter by
32
+ * tenant. Apps with a richer intra-tenant model (producer/region/plant,
33
+ * rep hierarchy, …) ship their own scope hook instead.
34
+ */
35
+ export declare function flatTenantScope(): ScopeHook;
36
+ //# sourceMappingURL=flat-tenant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flat-tenant.d.ts","sourceRoot":"","sources":["../../src/scope/flat-tenant.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,aAAa,CAAC;AAE9D;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe;;;CAGlB,CAAC;AAyBX;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,IAAI,SAAS,CAS3C"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The flat-tenant scope GUCs. Set by the {@link flatTenantScope} preset;
3
+ * **not** part of the core identity contract. Reference them in RLS
4
+ * policies if you adopt the preset.
5
+ *
6
+ * - `app.tenant_ids` — comma-separated tenant ids the user belongs to.
7
+ * - `app.all_tenants` — `'true'` when the user has a wildcard
8
+ * (`tenant_id IS NULL`) membership; such users see every tenant.
9
+ */
10
+ export const FLAT_TENANT_GUC = {
11
+ tenantIds: 'app.tenant_ids',
12
+ allTenants: 'app.all_tenants',
13
+ };
14
+ const SET_CONFIG = 'SELECT set_config($1, $2, true)';
15
+ // Resolve the user's tenant membership from user_roles. tenant_id IS NULL
16
+ // is a wildcard (all tenants); concrete ids are the explicit memberships.
17
+ // Runs as the request user — an RLS policy keyed on current_user_id()
18
+ // (already set by withSession) lets the user read their own rows.
19
+ const SELECT_TENANTS = `
20
+ SELECT
21
+ COALESCE(
22
+ array_agg(DISTINCT tenant_id) FILTER (WHERE tenant_id IS NOT NULL),
23
+ '{}'::integer[]
24
+ ) AS tenant_ids,
25
+ COALESCE(bool_or(tenant_id IS NULL), false) AS all_tenants
26
+ FROM user_roles
27
+ WHERE user_id = $1
28
+ AND deleted_at IS NULL
29
+ `;
30
+ /**
31
+ * A ready-made scope hook implementing the flat `tenant_ids` /
32
+ * `all_tenants` model (the 0.6.x behavior), now opt-in rather than baked
33
+ * into the core.
34
+ *
35
+ * Adopt it for simple multi-tenant apps that don't need a custom scope:
36
+ *
37
+ * ```ts
38
+ * import { withSession } from '@smplcty/auth';
39
+ * import { flatTenantScope } from '@smplcty/auth/flat-tenant';
40
+ *
41
+ * const scope = flatTenantScope();
42
+ * await withSession(pool, { token }, fn, { scope });
43
+ * ```
44
+ *
45
+ * It sets `app.tenant_ids` and `app.all_tenants` from the user's
46
+ * `user_roles` rows. Your RLS policies read those GUCs to filter by
47
+ * tenant. Apps with a richer intra-tenant model (producer/region/plant,
48
+ * rep hierarchy, …) ship their own scope hook instead.
49
+ */
50
+ export function flatTenantScope() {
51
+ return async (client, identity) => {
52
+ const { rows } = await client.query(SELECT_TENANTS, [identity.userId]);
53
+ const row = rows[0];
54
+ const tenantIds = row?.tenant_ids ?? [];
55
+ const allTenants = row?.all_tenants ?? false;
56
+ await client.query(SET_CONFIG, [FLAT_TENANT_GUC.tenantIds, tenantIds.join(',')]);
57
+ await client.query(SET_CONFIG, [FLAT_TENANT_GUC.allTenants, allTenants ? 'true' : 'false']);
58
+ };
59
+ }
60
+ //# sourceMappingURL=flat-tenant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flat-tenant.js","sourceRoot":"","sources":["../../src/scope/flat-tenant.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,gBAAgB;IAC3B,UAAU,EAAE,iBAAiB;CACrB,CAAC;AAEX,MAAM,UAAU,GAAG,iCAAiC,CAAC;AAErD,0EAA0E;AAC1E,0EAA0E;AAC1E,sEAAsE;AACtE,kEAAkE;AAClE,MAAM,cAAc,GAAG;;;;;;;;;;CAUtB,CAAC;AAOF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,KAAK,EAAE,MAAkB,EAAE,QAAyB,EAAiB,EAAE;QAC5E,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,CAAY,cAAc,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QAClF,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,MAAM,SAAS,GAAG,GAAG,EAAE,UAAU,IAAI,EAAE,CAAC;QACxC,MAAM,UAAU,GAAG,GAAG,EAAE,WAAW,IAAI,KAAK,CAAC;QAC7C,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,eAAe,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACjF,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9F,CAAC,CAAC;AACJ,CAAC"}
@@ -1,78 +1,69 @@
1
1
  import type { PoolClient } from 'pg';
2
2
  /**
3
- * The four GUC variable names this library uses. Re-exported here in
4
- * case consumers need them in custom RLS policies.
3
+ * The identity GUC contract — the only GUCs `@smplcty/auth` sets. All are
4
+ * transaction-local (`set_config(name, value, true)`), so they're
5
+ * discarded automatically on COMMIT/ROLLBACK; cross-request leakage is
6
+ * impossible. Re-exported so consumers can reference them in RLS policies.
7
+ *
8
+ * Scope GUCs (tenant ids, plant/region scope, visible rep ids, …) are
9
+ * **not** here — intra-tenant scope is app-owned (set via the scope hook).
10
+ *
11
+ * - `app.actor_id` — the acting user (human or service). Powers
12
+ * `current_user_id()` and audit attribution.
13
+ * - `app.session_id` — the session hash, for correlation/audit.
14
+ * - `app.active_role` — the chosen mode/persona role for the request.
15
+ * - `app.privileges` — comma-separated privilege names the user holds.
5
16
  */
6
- export declare const SESSION_VAR_NAMES: {
17
+ export declare const IDENTITY_GUC: {
18
+ readonly actorId: "app.actor_id";
7
19
  readonly sessionId: "app.session_id";
8
- readonly roleName: "app.role_name";
9
- readonly tenantIds: "app.tenant_ids";
10
- readonly allTenants: "app.all_tenants";
20
+ readonly activeRole: "app.active_role";
21
+ readonly privileges: "app.privileges";
11
22
  };
12
23
  /**
13
- * Set `app.session_id` for the current transaction.
14
- *
15
- * **Contract:** `client` must be inside an open transaction. Either wrap
16
- * with `withTransaction(pool, fn)` or call `await client.query('BEGIN')`
17
- * yourself first.
18
- *
19
- * The variable is set with transaction scope (`set_config(name, value, true)`)
20
- * and is automatically discarded on COMMIT or ROLLBACK. There is no risk
21
- * of cross-request leakage.
22
- *
23
- * **Warning:** This helper does not validate that the session exists or
24
- * is unexpired. Use `validateSession` or `withSession` if you want
25
- * automatic verification.
24
+ * Set a single transaction-local GUC. Low-level escape hatch; prefer the
25
+ * named setters or `setIdentityContext`.
26
26
  *
27
- * @throws {InvalidInputError} If `sessionId` is not a non-empty string.
27
+ * **Contract:** `client` must be inside an open transaction.
28
28
  */
29
- export declare function setSessionId(client: PoolClient, sessionId: string): Promise<void>;
29
+ export declare function setLocal(client: PoolClient, name: string, value: string): Promise<void>;
30
30
  /**
31
- * Set `app.role_name` for the current transaction.
32
- *
33
- * **Contract:** `client` must be inside an open transaction.
34
- *
35
- * **Warning:** This helper does not verify that the requested role is
36
- * one the current session is allowed to use. The caller is responsible
37
- * for not passing user-supplied input directly. Use `withSession` to get
38
- * automatic role validation against the database.
31
+ * Set `app.actor_id` — the user (or service principal) performing the
32
+ * request. `current_user_id()` and the audit trigger read it.
39
33
  *
40
- * @typeParam TRole - String literal union of roles in your application.
41
- * Defaults to `string`. Narrow this in a thin wrapper.
42
- * @throws {InvalidInputError} If `roleName` is not a non-empty string.
34
+ * @throws {InvalidInputError} If `actorId` is not a positive integer.
43
35
  */
44
- export declare function setRoleName<TRole extends string = string>(client: PoolClient, roleName: TRole): Promise<void>;
36
+ export declare function setActorId(client: PoolClient, actorId: number): Promise<void>;
45
37
  /**
46
- * Set `app.tenant_ids` for the current transaction. The value is encoded
47
- * as a comma-separated string of integers (so RLS policies can parse it
48
- * with `string_to_array`). Empty arrays produce an empty string.
38
+ * Set `app.session_id` (the session hash) for correlation/audit.
49
39
  *
50
- * **Contract:** `client` must be inside an open transaction.
51
- *
52
- * @throws {InvalidInputError} If any element of `tenantIds` is not a finite integer.
40
+ * @throws {InvalidInputError} If `sessionId` is not a non-empty string.
53
41
  */
54
- export declare function setTenantIds(client: PoolClient, tenantIds: readonly number[]): Promise<void>;
42
+ export declare function setSessionId(client: PoolClient, sessionId: string): Promise<void>;
55
43
  /**
56
- * Set `app.all_tenants` for the current transaction. When `true`, RLS
57
- * policies typically bypass tenant filtering and allow access to every
58
- * tenant's rows.
44
+ * Set `app.active_role` — the mode/persona role for this request. Pass
45
+ * null to clear it (privilege-only request).
59
46
  *
60
- * **Contract:** `client` must be inside an open transaction.
47
+ * @throws {InvalidInputError} If `roleName` is neither a non-empty string nor null.
48
+ */
49
+ export declare function setActiveRole(client: PoolClient, roleName: string | null): Promise<void>;
50
+ /**
51
+ * Set `app.privileges` — a comma-separated list of the privilege names the
52
+ * user holds. RLS policies parse it with `string_to_array(_, ',')`.
61
53
  *
62
- * @throws {InvalidInputError} If `allTenants` is not a boolean.
54
+ * @throws {InvalidInputError} If `privileges` is not an array of strings,
55
+ * or any entry contains a comma.
63
56
  */
64
- export declare function setAllTenants(client: PoolClient, allTenants: boolean): Promise<void>;
57
+ export declare function setPrivileges(client: PoolClient, privileges: readonly string[]): Promise<void>;
65
58
  /**
66
- * Set all four session variables in one call. Equivalent to calling
67
- * `setSessionId`, `setRoleName`, `setTenantIds`, and `setAllTenants`
68
- * sequentially, but more concise.
59
+ * Set all four identity GUCs in one call.
69
60
  *
70
61
  * **Contract:** `client` must be inside an open transaction.
71
62
  */
72
- export declare function setSessionContext<TRole extends string = string>(client: PoolClient, context: {
63
+ export declare function setIdentityContext(client: PoolClient, context: {
64
+ actorId: number;
73
65
  sessionId: string;
74
- roleName: TRole;
75
- tenantIds: readonly number[];
76
- allTenants: boolean;
66
+ activeRole: string | null;
67
+ privileges: readonly string[];
77
68
  }): Promise<void>;
78
69
  //# sourceMappingURL=set-helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"set-helpers.d.ts","sourceRoot":"","sources":["../src/set-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAKrC;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;;CAKpB,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAKf;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,WAAW,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EAC7D,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,KAAK,GACd,OAAO,CAAC,IAAI,CAAC,CAKf;AAED;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,OAAO,CAAC,IAAI,CAAC,CAef;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,UAAU,EAClB,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,IAAI,CAAC,CAQf;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,EACnE,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE;IACP,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,KAAK,CAAC;IAChB,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B,UAAU,EAAE,OAAO,CAAC;CACrB,GACA,OAAO,CAAC,IAAI,CAAC,CAKf"}
1
+ {"version":3,"file":"set-helpers.d.ts","sourceRoot":"","sources":["../src/set-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAKrC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY;;;;;CAKf,CAAC;AAEX;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK7F;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKnF;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKvF;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAK9F;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAapG;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE;IACP,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B,GACA,OAAO,CAAC,IAAI,CAAC,CAKf"}
@@ -1,29 +1,52 @@
1
1
  import { InvalidInputError } from './errors.js';
2
2
  const SET_CONFIG = 'SELECT set_config($1, $2, true)';
3
3
  /**
4
- * The four GUC variable names this library uses. Re-exported here in
5
- * case consumers need them in custom RLS policies.
4
+ * The identity GUC contract — the only GUCs `@smplcty/auth` sets. All are
5
+ * transaction-local (`set_config(name, value, true)`), so they're
6
+ * discarded automatically on COMMIT/ROLLBACK; cross-request leakage is
7
+ * impossible. Re-exported so consumers can reference them in RLS policies.
8
+ *
9
+ * Scope GUCs (tenant ids, plant/region scope, visible rep ids, …) are
10
+ * **not** here — intra-tenant scope is app-owned (set via the scope hook).
11
+ *
12
+ * - `app.actor_id` — the acting user (human or service). Powers
13
+ * `current_user_id()` and audit attribution.
14
+ * - `app.session_id` — the session hash, for correlation/audit.
15
+ * - `app.active_role` — the chosen mode/persona role for the request.
16
+ * - `app.privileges` — comma-separated privilege names the user holds.
6
17
  */
7
- export const SESSION_VAR_NAMES = {
18
+ export const IDENTITY_GUC = {
19
+ actorId: 'app.actor_id',
8
20
  sessionId: 'app.session_id',
9
- roleName: 'app.role_name',
10
- tenantIds: 'app.tenant_ids',
11
- allTenants: 'app.all_tenants',
21
+ activeRole: 'app.active_role',
22
+ privileges: 'app.privileges',
12
23
  };
13
24
  /**
14
- * Set `app.session_id` for the current transaction.
25
+ * Set a single transaction-local GUC. Low-level escape hatch; prefer the
26
+ * named setters or `setIdentityContext`.
15
27
  *
16
- * **Contract:** `client` must be inside an open transaction. Either wrap
17
- * with `withTransaction(pool, fn)` or call `await client.query('BEGIN')`
18
- * yourself first.
19
- *
20
- * The variable is set with transaction scope (`set_config(name, value, true)`)
21
- * and is automatically discarded on COMMIT or ROLLBACK. There is no risk
22
- * of cross-request leakage.
28
+ * **Contract:** `client` must be inside an open transaction.
29
+ */
30
+ export async function setLocal(client, name, value) {
31
+ if (typeof name !== 'string' || name.length === 0) {
32
+ throw new InvalidInputError('GUC name must be a non-empty string');
33
+ }
34
+ await client.query(SET_CONFIG, [name, value]);
35
+ }
36
+ /**
37
+ * Set `app.actor_id` — the user (or service principal) performing the
38
+ * request. `current_user_id()` and the audit trigger read it.
23
39
  *
24
- * **Warning:** This helper does not validate that the session exists or
25
- * is unexpired. Use `validateSession` or `withSession` if you want
26
- * automatic verification.
40
+ * @throws {InvalidInputError} If `actorId` is not a positive integer.
41
+ */
42
+ export async function setActorId(client, actorId) {
43
+ if (!Number.isInteger(actorId) || actorId <= 0) {
44
+ throw new InvalidInputError('actorId must be a positive integer');
45
+ }
46
+ await client.query(SET_CONFIG, [IDENTITY_GUC.actorId, String(actorId)]);
47
+ }
48
+ /**
49
+ * Set `app.session_id` (the session hash) for correlation/audit.
27
50
  *
28
51
  * @throws {InvalidInputError} If `sessionId` is not a non-empty string.
29
52
  */
@@ -31,80 +54,50 @@ export async function setSessionId(client, sessionId) {
31
54
  if (typeof sessionId !== 'string' || sessionId.length === 0) {
32
55
  throw new InvalidInputError('sessionId must be a non-empty string');
33
56
  }
34
- await client.query(SET_CONFIG, [SESSION_VAR_NAMES.sessionId, sessionId]);
57
+ await client.query(SET_CONFIG, [IDENTITY_GUC.sessionId, sessionId]);
35
58
  }
36
59
  /**
37
- * Set `app.role_name` for the current transaction.
60
+ * Set `app.active_role` — the mode/persona role for this request. Pass
61
+ * null to clear it (privilege-only request).
38
62
  *
39
- * **Contract:** `client` must be inside an open transaction.
40
- *
41
- * **Warning:** This helper does not verify that the requested role is
42
- * one the current session is allowed to use. The caller is responsible
43
- * for not passing user-supplied input directly. Use `withSession` to get
44
- * automatic role validation against the database.
45
- *
46
- * @typeParam TRole - String literal union of roles in your application.
47
- * Defaults to `string`. Narrow this in a thin wrapper.
48
- * @throws {InvalidInputError} If `roleName` is not a non-empty string.
63
+ * @throws {InvalidInputError} If `roleName` is neither a non-empty string nor null.
49
64
  */
50
- export async function setRoleName(client, roleName) {
51
- if (typeof roleName !== 'string' || roleName.length === 0) {
52
- throw new InvalidInputError('roleName must be a non-empty string');
65
+ export async function setActiveRole(client, roleName) {
66
+ if (roleName !== null && (typeof roleName !== 'string' || roleName.length === 0)) {
67
+ throw new InvalidInputError('roleName must be a non-empty string or null');
53
68
  }
54
- await client.query(SET_CONFIG, [SESSION_VAR_NAMES.roleName, roleName]);
69
+ await client.query(SET_CONFIG, [IDENTITY_GUC.activeRole, roleName ?? '']);
55
70
  }
56
71
  /**
57
- * Set `app.tenant_ids` for the current transaction. The value is encoded
58
- * as a comma-separated string of integers (so RLS policies can parse it
59
- * with `string_to_array`). Empty arrays produce an empty string.
60
- *
61
- * **Contract:** `client` must be inside an open transaction.
72
+ * Set `app.privileges` — a comma-separated list of the privilege names the
73
+ * user holds. RLS policies parse it with `string_to_array(_, ',')`.
62
74
  *
63
- * @throws {InvalidInputError} If any element of `tenantIds` is not a finite integer.
75
+ * @throws {InvalidInputError} If `privileges` is not an array of strings,
76
+ * or any entry contains a comma.
64
77
  */
65
- export async function setTenantIds(client, tenantIds) {
66
- if (!Array.isArray(tenantIds)) {
67
- throw new InvalidInputError('tenantIds must be an array of integers');
78
+ export async function setPrivileges(client, privileges) {
79
+ if (!Array.isArray(privileges)) {
80
+ throw new InvalidInputError('privileges must be an array of strings');
68
81
  }
69
- for (const id of tenantIds) {
70
- if (!Number.isInteger(id)) {
71
- throw new InvalidInputError(`tenantIds must contain only integers; got ${String(id)}`);
82
+ for (const p of privileges) {
83
+ if (typeof p !== 'string' || p.length === 0) {
84
+ throw new InvalidInputError('privileges must contain only non-empty strings');
85
+ }
86
+ if (p.includes(',')) {
87
+ throw new InvalidInputError(`privilege names must not contain commas; got "${p}"`);
72
88
  }
73
89
  }
74
- await client.query(SET_CONFIG, [
75
- SESSION_VAR_NAMES.tenantIds,
76
- tenantIds.join(','),
77
- ]);
78
- }
79
- /**
80
- * Set `app.all_tenants` for the current transaction. When `true`, RLS
81
- * policies typically bypass tenant filtering and allow access to every
82
- * tenant's rows.
83
- *
84
- * **Contract:** `client` must be inside an open transaction.
85
- *
86
- * @throws {InvalidInputError} If `allTenants` is not a boolean.
87
- */
88
- export async function setAllTenants(client, allTenants) {
89
- if (typeof allTenants !== 'boolean') {
90
- throw new InvalidInputError('allTenants must be a boolean');
91
- }
92
- await client.query(SET_CONFIG, [
93
- SESSION_VAR_NAMES.allTenants,
94
- allTenants ? 'true' : 'false',
95
- ]);
90
+ await client.query(SET_CONFIG, [IDENTITY_GUC.privileges, privileges.join(',')]);
96
91
  }
97
92
  /**
98
- * Set all four session variables in one call. Equivalent to calling
99
- * `setSessionId`, `setRoleName`, `setTenantIds`, and `setAllTenants`
100
- * sequentially, but more concise.
93
+ * Set all four identity GUCs in one call.
101
94
  *
102
95
  * **Contract:** `client` must be inside an open transaction.
103
96
  */
104
- export async function setSessionContext(client, context) {
97
+ export async function setIdentityContext(client, context) {
98
+ await setActorId(client, context.actorId);
105
99
  await setSessionId(client, context.sessionId);
106
- await setRoleName(client, context.roleName);
107
- await setTenantIds(client, context.tenantIds);
108
- await setAllTenants(client, context.allTenants);
100
+ await setActiveRole(client, context.activeRole);
101
+ await setPrivileges(client, context.privileges);
109
102
  }
110
103
  //# sourceMappingURL=set-helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"set-helpers.js","sourceRoot":"","sources":["../src/set-helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,UAAU,GAAG,iCAAiC,CAAC;AAErD;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,SAAS,EAAE,gBAAgB;IAC3B,QAAQ,EAAE,eAAe;IACzB,SAAS,EAAE,gBAAgB;IAC3B,UAAU,EAAE,iBAAiB;CACrB,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAkB,EAClB,SAAiB;IAEjB,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,iBAAiB,CAAC,sCAAsC,CAAC,CAAC;IACtE,CAAC;IACD,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,iBAAiB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAkB,EAClB,QAAe;IAEf,IAAI,OAAO,QAAQ,KAA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AAI,iBAAiB,CAAC,gDAAgD,CAAC,CAAC;QAChF,CAAC;QACD,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,IAAI,iBAAiB,CAAC,iDAAiD,CAAC,GAAG,CAAC,CAAC;QACrF,CAAC;IACH,CAAC;IACD,MAAM,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAClF,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAkB,EAClB,OAKC;IAED,MAAM,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC9C,MAAM,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAChD,MAAM,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Queryable } from './types.js';
2
+ /**
3
+ * Record activity on a session: stamp `last_seen_at = now()`. Powers the
4
+ * "track activity" requirement (distinct from `created_at`, the sign-in
5
+ * time). No-ops on an unknown, expired, or revoked session.
6
+ *
7
+ * Returns `true` if a live session was touched, `false` otherwise — handy
8
+ * for piggy-backing a liveness check on the activity update.
9
+ *
10
+ * @throws {InvalidInputError} If `token` is not a non-empty string.
11
+ */
12
+ export declare function touchSession(db: Queryable, token: string): Promise<boolean>;
13
+ //# sourceMappingURL=touch-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"touch-session.d.ts","sourceRoot":"","sources":["../src/touch-session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAW5C;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMjF"}