@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
@@ -2,16 +2,16 @@ import type { CreateSessionInput, Queryable, Session } from './types.js';
2
2
  /**
3
3
  * Create a new session for an already-authenticated user.
4
4
  *
5
- * The caller is responsible for verifying the user's identity (via
6
- * Twilio Verify, OIDC callback, password check, or whatever) BEFORE
7
- * calling this function. `createSession` does not perform any
8
- * authentication of its own — it simply persists a session row and
9
- * returns the new session token.
5
+ * The caller is responsible for verifying the user's identity (via a
6
+ * `MethodHandler`, Twilio Verify, OIDC callback, password check, …)
7
+ * BEFORE calling this. `createSession` performs no authentication — it
8
+ * persists a session row and returns the new token.
10
9
  *
11
- * The session ID is generated server-side using `crypto.randomUUID()`
12
- * (122 bits of entropy). The expiration is computed server-side as
13
- * `now() + interval $ttl` so there is no clock skew between the app and
14
- * the database.
10
+ * A fresh opaque token (256 bits of entropy) is generated server-side;
11
+ * only its **SHA-256 hash** is stored, as the `sessions` primary key. The
12
+ * raw token is returned **once** in {@link Session.token} — hand it to the
13
+ * client and don't persist it. Expiration is computed server-side as
14
+ * `now() + interval $ttl` so there's no app/database clock skew.
15
15
  *
16
16
  * @example
17
17
  * ```ts
@@ -21,6 +21,7 @@ import type { CreateSessionInput, Queryable, Session } from './types.js';
21
21
  * ip: req.ip,
22
22
  * geo: { country: 'US', region: 'CA' },
23
23
  * });
24
+ * setCookie('session', session.token); // raw token to the client, once
24
25
  * ```
25
26
  *
26
27
  * @throws {InvalidInputError} If `ttl` is empty or `userCommunicationMethodId` is not a positive integer.
@@ -1 +1 @@
1
- {"version":3,"file":"create-session.d.ts","sourceRoot":"","sources":["../src/create-session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAoDzE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,aAAa,CACjC,EAAE,EAAE,SAAS,EACb,KAAK,EAAE,kBAAkB,GACxB,OAAO,CAAC,OAAO,CAAC,CAyDlB"}
1
+ {"version":3,"file":"create-session.d.ts","sourceRoot":"","sources":["../src/create-session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AA6CzE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,aAAa,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CA+C9F"}
@@ -1,7 +1,5 @@
1
- import { randomUUID } from 'node:crypto';
2
1
  import { InvalidInputError } from './errors.js';
3
- const TS_SUFFIX = process.env['USE_AT_FOR_TIMESTAMPS'] !== 'false' ? '_at' : '';
4
- const CREATED_COL = `created${TS_SUFFIX}`;
2
+ import { generateToken, hashToken } from './internal/hash-token.js';
5
3
  const INSERT_SESSION = `
6
4
  INSERT INTO sessions (
7
5
  session_id,
@@ -26,10 +24,8 @@ const INSERT_SESSION = `
26
24
  $9
27
25
  )
28
26
  RETURNING
29
- session_id AS "sessionId",
30
- user_communication_method_id AS "_userCommunicationMethodId",
31
- ${CREATED_COL} AS "createdAt",
32
- expires_at AS "expiresAt"
27
+ created_at AS "createdAt",
28
+ expires_at AS "expiresAt"
33
29
  `;
34
30
  const SELECT_USER_ID = `
35
31
  SELECT user_id AS "userId"
@@ -39,16 +35,16 @@ const SELECT_USER_ID = `
39
35
  /**
40
36
  * Create a new session for an already-authenticated user.
41
37
  *
42
- * The caller is responsible for verifying the user's identity (via
43
- * Twilio Verify, OIDC callback, password check, or whatever) BEFORE
44
- * calling this function. `createSession` does not perform any
45
- * authentication of its own — it simply persists a session row and
46
- * returns the new session token.
38
+ * The caller is responsible for verifying the user's identity (via a
39
+ * `MethodHandler`, Twilio Verify, OIDC callback, password check, …)
40
+ * BEFORE calling this. `createSession` performs no authentication — it
41
+ * persists a session row and returns the new token.
47
42
  *
48
- * The session ID is generated server-side using `crypto.randomUUID()`
49
- * (122 bits of entropy). The expiration is computed server-side as
50
- * `now() + interval $ttl` so there is no clock skew between the app and
51
- * the database.
43
+ * A fresh opaque token (256 bits of entropy) is generated server-side;
44
+ * only its **SHA-256 hash** is stored, as the `sessions` primary key. The
45
+ * raw token is returned **once** in {@link Session.token} — hand it to the
46
+ * client and don't persist it. Expiration is computed server-side as
47
+ * `now() + interval $ttl` so there's no app/database clock skew.
52
48
  *
53
49
  * @example
54
50
  * ```ts
@@ -58,19 +54,20 @@ const SELECT_USER_ID = `
58
54
  * ip: req.ip,
59
55
  * geo: { country: 'US', region: 'CA' },
60
56
  * });
57
+ * setCookie('session', session.token); // raw token to the client, once
61
58
  * ```
62
59
  *
63
60
  * @throws {InvalidInputError} If `ttl` is empty or `userCommunicationMethodId` is not a positive integer.
64
61
  */
65
62
  export async function createSession(db, input) {
66
- if (!Number.isInteger(input.userCommunicationMethodId) ||
67
- input.userCommunicationMethodId <= 0) {
63
+ if (!Number.isInteger(input.userCommunicationMethodId) || input.userCommunicationMethodId <= 0) {
68
64
  throw new InvalidInputError('userCommunicationMethodId must be a positive integer');
69
65
  }
70
66
  if (typeof input.ttl !== 'string' || input.ttl.length === 0) {
71
67
  throw new InvalidInputError('ttl must be a non-empty Postgres interval string (e.g. "30 days")');
72
68
  }
73
- const sessionId = randomUUID();
69
+ const token = generateToken();
70
+ const sessionId = hashToken(token);
74
71
  const geo = input.geo ?? {};
75
72
  const { rows } = await db.query(INSERT_SESSION, [
76
73
  sessionId,
@@ -90,9 +87,7 @@ export async function createSession(db, input) {
90
87
  // have failed silently, which would mean a pg client misconfiguration.
91
88
  throw new Error('createSession: INSERT did not return a row');
92
89
  }
93
- const userResult = await db.query(SELECT_USER_ID, [
94
- input.userCommunicationMethodId,
95
- ]);
90
+ const userResult = await db.query(SELECT_USER_ID, [input.userCommunicationMethodId]);
96
91
  const userRow = userResult.rows[0];
97
92
  if (!userRow) {
98
93
  // The FK on sessions.user_communication_method_id should have
@@ -101,7 +96,7 @@ export async function createSession(db, input) {
101
96
  throw new Error('createSession: user_communication_method_id has no matching user');
102
97
  }
103
98
  return {
104
- sessionId: row.sessionId,
99
+ token,
105
100
  userId: userRow.userId,
106
101
  createdAt: row.createdAt,
107
102
  expiresAt: row.expiresAt,
@@ -1 +1 @@
1
- {"version":3,"file":"create-session.js","sourceRoot":"","sources":["../src/create-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAChF,MAAM,WAAW,GAAG,UAAU,SAAS,EAAE,CAAC;AAE1C,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;MA0BjB,WAAW;;CAEhB,CAAC;AAEF,MAAM,cAAc,GAAG;;;;CAItB,CAAC;AAaF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,EAAa,EACb,KAAyB;IAEzB,IACE,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,yBAAyB,CAAC;QAClD,KAAK,CAAC,yBAAyB,IAAI,CAAC,EACpC,CAAC;QACD,MAAM,IAAI,iBAAiB,CACzB,sDAAsD,CACvD,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,KAAK,CAAC,GAAG,KAA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OAAO,CAAC,OAAO,CAAC,CAalB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,MAAM,CAeT"}
1
+ {"version":3,"file":"dev-otp.d.ts","sourceRoot":"","sources":["../src/dev-otp.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA4C5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAiCnH;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMzG;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAevG"}
package/dist/dev-otp.js CHANGED
@@ -59,16 +59,13 @@ const RECORD_USE = `
59
59
  * positive integer or `code` is not a non-empty string.
60
60
  */
61
61
  export async function verifyDevOtp(db, userCommunicationMethodId, code) {
62
- if (!Number.isInteger(userCommunicationMethodId) ||
63
- userCommunicationMethodId <= 0) {
62
+ if (!Number.isInteger(userCommunicationMethodId) || userCommunicationMethodId <= 0) {
64
63
  throw new InvalidInputError('userCommunicationMethodId must be a positive integer');
65
64
  }
66
65
  if (typeof code !== 'string' || code.length === 0) {
67
66
  throw new InvalidInputError('code must be a non-empty string');
68
67
  }
69
- const { rows } = await db.query(SELECT_ENROLLMENT, [
70
- userCommunicationMethodId,
71
- ]);
68
+ const { rows } = await db.query(SELECT_ENROLLMENT, [userCommunicationMethodId]);
72
69
  const enrollment = rows[0];
73
70
  if (!enrollment) {
74
71
  return false;
@@ -115,13 +112,10 @@ export async function verifyDevOtp(db, userCommunicationMethodId, code) {
115
112
  * @throws {InvalidInputError} If `userCommunicationMethodId` is not a positive integer.
116
113
  */
117
114
  export async function isDevOtpEnrolled(db, userCommunicationMethodId) {
118
- if (!Number.isInteger(userCommunicationMethodId) ||
119
- userCommunicationMethodId <= 0) {
115
+ if (!Number.isInteger(userCommunicationMethodId) || userCommunicationMethodId <= 0) {
120
116
  throw new InvalidInputError('userCommunicationMethodId must be a positive integer');
121
117
  }
122
- const { rowCount } = await db.query(SELECT_ENROLLMENT_EXISTS, [
123
- userCommunicationMethodId,
124
- ]);
118
+ const { rowCount } = await db.query(SELECT_ENROLLMENT_EXISTS, [userCommunicationMethodId]);
125
119
  return (rowCount ?? 0) > 0;
126
120
  }
127
121
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"dev-otp.js","sourceRoot":"","sources":["../src/dev-otp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,mEAAmE;AACnE,sEAAsE;AACtE,qEAAqE;AACrE,6DAA6D;AAC7D,oCAAoC;AACpC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEnC,MAAM,iBAAiB,GAAG;;;;;;;;;;CAUzB,CAAC;AAEF,MAAM,wBAAwB,GAAG;;;;;CAKhC,CAAC;AAEF,MAAM,UAAU,GAAG;;;;;CAKlB,CAAC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AI,iBAAiB,CAAC,kCAAkC,CAAC,CAAC;IAClE,CAAC;IACD,IAAI,OAAO,KAAK,EAAE,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnE,MAAM,IAAI,iBAAiB,CAAC,mCAAmC,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,WAAW,CAAC;QACjB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC,CAAC;AACL,CAAC"}
package/dist/errors.d.ts CHANGED
@@ -24,14 +24,29 @@ export declare class SessionExpiredError extends AuthError {
24
24
  constructor(expiresAt: Date, message?: string);
25
25
  }
26
26
  /**
27
- * Thrown when a user does not have the role requested for a session.
27
+ * Thrown when a request asks to activate a role the user does not hold.
28
+ *
29
+ * Role selection and validation happen in `withSession` (TS): the pure
30
+ * `resolve_session` resolver returns the roles the user holds, and
31
+ * `withSession` rejects a requested role that isn't among them.
28
32
  */
29
- export declare class RoleNotAssignedError extends AuthError {
30
- readonly name = "RoleNotAssignedError";
31
- readonly code: "ROLE_NOT_ASSIGNED";
33
+ export declare class RoleNotHeldError extends AuthError {
34
+ readonly name = "RoleNotHeldError";
35
+ readonly code: "ROLE_NOT_HELD";
32
36
  readonly roleName: string;
33
37
  constructor(roleName: string, message?: string);
34
38
  }
39
+ /**
40
+ * Thrown when `withServiceContext` can't find a `users` row of
41
+ * `kind = 'service'` with the given name. Almost always a missing seed:
42
+ * the service principal must be provisioned before background writes run.
43
+ */
44
+ export declare class ServicePrincipalNotFoundError extends AuthError {
45
+ readonly name = "ServicePrincipalNotFoundError";
46
+ readonly code: "SERVICE_PRINCIPAL_NOT_FOUND";
47
+ readonly serviceName: string;
48
+ constructor(serviceName: string, message?: string);
49
+ }
35
50
  /**
36
51
  * Thrown when a function input fails validation (empty string, wrong type,
37
52
  * etc.) before the library will hit the database.
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,SAAkB,IAAI,EAAE,MAAM,CAAe;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAgB;CACtC;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;IACjD,SAAkB,IAAI,0BAA0B;IAChD,SAAkB,IAAI,EAAG,mBAAmB,CAAU;gBAE1C,OAAO,GAAE,MAA4B;CAGlD;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,SAAkB,IAAI,yBAAyB;IAC/C,SAAkB,IAAI,EAAG,iBAAiB,CAAU;IACpD,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;gBAEb,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM;CAI9C;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;IACjD,SAAkB,IAAI,0BAA0B;IAChD,SAAkB,IAAI,EAAG,mBAAmB,CAAU;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAI/C;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,SAAS;IAC9C,SAAkB,IAAI,uBAAuB;IAC7C,SAAkB,IAAI,EAAG,eAAe,CAAU;gBAEtC,OAAO,EAAE,MAAM;CAG5B"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,SAAkB,IAAI,EAAE,MAAM,CAAe;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAgB;CACtC;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;IACjD,SAAkB,IAAI,0BAA0B;IAChD,SAAkB,IAAI,EAAG,mBAAmB,CAAU;gBAE1C,OAAO,GAAE,MAA4B;CAGlD;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,SAAkB,IAAI,yBAAyB;IAC/C,SAAkB,IAAI,EAAG,iBAAiB,CAAU;IACpD,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;gBAEb,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM;CAI9C;AAED;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;IAC7C,SAAkB,IAAI,sBAAsB;IAC5C,SAAkB,IAAI,EAAG,eAAe,CAAU;IAClD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAI/C;AAED;;;;GAIG;AACH,qBAAa,6BAA8B,SAAQ,SAAS;IAC1D,SAAkB,IAAI,mCAAmC;IACzD,SAAkB,IAAI,EAAG,6BAA6B,CAAU;IAChE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;gBAEjB,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAIlD;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,SAAS;IAC9C,SAAkB,IAAI,uBAAuB;IAC7C,SAAkB,IAAI,EAAG,eAAe,CAAU;gBAEtC,OAAO,EAAE,MAAM;CAG5B"}
package/dist/errors.js CHANGED
@@ -29,17 +29,35 @@ export class SessionExpiredError extends AuthError {
29
29
  }
30
30
  }
31
31
  /**
32
- * Thrown when a user does not have the role requested for a session.
32
+ * Thrown when a request asks to activate a role the user does not hold.
33
+ *
34
+ * Role selection and validation happen in `withSession` (TS): the pure
35
+ * `resolve_session` resolver returns the roles the user holds, and
36
+ * `withSession` rejects a requested role that isn't among them.
33
37
  */
34
- export class RoleNotAssignedError extends AuthError {
35
- name = 'RoleNotAssignedError';
36
- code = 'ROLE_NOT_ASSIGNED';
38
+ export class RoleNotHeldError extends AuthError {
39
+ name = 'RoleNotHeldError';
40
+ code = 'ROLE_NOT_HELD';
37
41
  roleName;
38
42
  constructor(roleName, message) {
39
- super(message ?? `User does not have role: ${roleName}`);
43
+ super(message ?? `User does not hold role: ${roleName}`);
40
44
  this.roleName = roleName;
41
45
  }
42
46
  }
47
+ /**
48
+ * Thrown when `withServiceContext` can't find a `users` row of
49
+ * `kind = 'service'` with the given name. Almost always a missing seed:
50
+ * the service principal must be provisioned before background writes run.
51
+ */
52
+ export class ServicePrincipalNotFoundError extends AuthError {
53
+ name = 'ServicePrincipalNotFoundError';
54
+ code = 'SERVICE_PRINCIPAL_NOT_FOUND';
55
+ serviceName;
56
+ constructor(serviceName, message) {
57
+ super(message ?? `No service principal named: ${serviceName}`);
58
+ this.serviceName = serviceName;
59
+ }
60
+ }
43
61
  /**
44
62
  * Thrown when a function input fails validation (empty string, wrong type,
45
63
  * etc.) before the library will hit the database.
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAChB,IAAI,GAAW,WAAW,CAAC;IACpC,IAAI,GAAW,YAAY,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IAC/B,IAAI,GAAG,sBAAsB,CAAC;IAC9B,IAAI,GAAG,mBAA4B,CAAC;IAEtD,YAAY,UAAkB,mBAAmB;QAC/C,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IAC9B,IAAI,GAAG,qBAAqB,CAAC;IAC7B,IAAI,GAAG,iBAA0B,CAAC;IAC3C,SAAS,CAAO;IAEzB,YAAY,SAAe,EAAE,OAAgB;QAC3C,KAAK,CAAC,OAAO,IAAI,sBAAsB,SAAS,CAAC,WAAW,EAAE,EAAE,CAAC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;IAC7B,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAC3B,IAAI,GAAG,kBAAkB,CAAC;IAC1B,IAAI,GAAG,eAAwB,CAAC;IACzC,QAAQ,CAAS;IAE1B,YAAY,QAAgB,EAAE,OAAgB;QAC5C,KAAK,CAAC,OAAO,IAAI,4BAA4B,QAAQ,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,6BAA8B,SAAQ,SAAS;IACxC,IAAI,GAAG,+BAA+B,CAAC;IACvC,IAAI,GAAG,6BAAsC,CAAC;IACvD,WAAW,CAAS;IAE7B,YAAY,WAAmB,EAAE,OAAgB;QAC/C,KAAK,CAAC,OAAO,IAAI,+BAA+B,WAAW,EAAE,CAAC,CAAC;QAC/D,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC5B,IAAI,GAAG,mBAAmB,CAAC;IAC3B,IAAI,GAAG,eAAwB,CAAC;IAElD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"find-user-by-communication-method.d.ts","sourceRoot":"","sources":["../src/find-user-by-communication-method.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,SAAS,EACT,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAcpB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,6BAA6B,CACjD,EAAE,EAAE,SAAS,EACb,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAa3C"}
1
+ {"version":3,"file":"find-user-by-communication-method.d.ts","sourceRoot":"","sources":["../src/find-user-by-communication-method.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAkBtF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,6BAA6B,CACjD,EAAE,EAAE,SAAS,EACb,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAa3C"}
@@ -6,8 +6,12 @@ const SELECT_BY_COMMUNICATION_METHOD = `
6
6
  FROM user_communication_methods ucm
7
7
  JOIN communication_channels cc
8
8
  ON cc.communication_channel_id = ucm.communication_channel_id
9
+ JOIN users u ON u.user_id = ucm.user_id
9
10
  WHERE cc.name = $1
10
11
  AND ucm.code = $2
12
+ AND ucm.deleted_at IS NULL
13
+ AND cc.deleted_at IS NULL
14
+ AND u.deleted_at IS NULL
11
15
  LIMIT 1
12
16
  `;
13
17
  /**
@@ -41,7 +45,10 @@ export async function findUserByCommunicationMethod(db, query) {
41
45
  if (typeof query?.code !== 'string' || query.code.length === 0) {
42
46
  throw new InvalidInputError('query.code must be a non-empty string');
43
47
  }
44
- const { rows } = await db.query(SELECT_BY_COMMUNICATION_METHOD, [query.channel, query.code]);
48
+ const { rows } = await db.query(SELECT_BY_COMMUNICATION_METHOD, [
49
+ query.channel,
50
+ query.code,
51
+ ]);
45
52
  return rows[0] ?? null;
46
53
  }
47
54
  //# sourceMappingURL=find-user-by-communication-method.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"find-user-by-communication-method.js","sourceRoot":"","sources":["../src/find-user-by-communication-method.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAOhD,MAAM,8BAA8B,GAAG;;;;;;;;;;CAUtC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,EAAa,EACb,KAAoB;IAEpB,IAAI,OAAO,KAAK,EAAE,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,iBAAiB,CAAC,0CAA0C,CAAC,CAAC;IAC1E,CAAC;IACD,IAAI,OAAO,KAAK,EAAE,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,iBAAiB,CAAC,uCAAuC,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,KAAK,CAC7B,8BAA8B,EAC9B,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,CAC5B,CAAC;IACF,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACzB,CAAC"}
1
+ {"version":3,"file":"find-user-by-communication-method.js","sourceRoot":"","sources":["../src/find-user-by-communication-method.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,8BAA8B,GAAG;;;;;;;;;;;;;;CActC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,EAAa,EACb,KAAoB;IAEpB,IAAI,OAAO,KAAK,EAAE,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,iBAAiB,CAAC,0CAA0C,CAAC,CAAC;IAC1E,CAAC;IACD,IAAI,OAAO,KAAK,EAAE,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,iBAAiB,CAAC,uCAAuC,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,KAAK,CAA4B,8BAA8B,EAAE;QACzF,KAAK,CAAC,OAAO;QACb,KAAK,CAAC,IAAI;KACX,CAAC,CAAC;IACH,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACzB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-user-role-names.d.ts","sourceRoot":"","sources":["../src/get-user-role-names.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAc5C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,gBAAgB,CACpC,EAAE,EAAE,SAAS,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,EAAE,CAAC,CAOnB"}
1
+ {"version":3,"file":"get-user-role-names.d.ts","sourceRoot":"","sources":["../src/get-user-role-names.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAgB5C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAOvF"}
@@ -4,6 +4,8 @@ const SELECT_ROLE_NAMES = `
4
4
  FROM user_roles ur
5
5
  JOIN roles r ON r.role_id = ur.role_id
6
6
  WHERE ur.user_id = $1
7
+ AND ur.deleted_at IS NULL
8
+ AND r.deleted_at IS NULL
7
9
  ORDER BY r.name
8
10
  `;
9
11
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"get-user-role-names.js","sourceRoot":"","sources":["../src/get-user-role-names.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,iBAAiB,GAAG;;;;;;CAMzB,CAAC;AAMF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,EAAa,EACb,MAAc;IAEd,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,iBAAiB,CAAC,mCAAmC,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,KAAK,CAAc,iBAAiB,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC"}
1
+ {"version":3,"file":"get-user-role-names.js","sourceRoot":"","sources":["../src/get-user-role-names.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,iBAAiB,GAAG;;;;;;;;CAQzB,CAAC;AAMF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,EAAa,EAAE,MAAc;IAClE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,iBAAiB,CAAC,mCAAmC,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,KAAK,CAAc,iBAAiB,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1E,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,13 +1,17 @@
1
- export { AuthError, SessionNotFoundError, SessionExpiredError, RoleNotAssignedError, InvalidInputError, } from './errors.js';
2
- export type { Queryable, Session, SessionContext, SessionAuth, CreateSessionInput, GeoLocation, UserByCommunicationMethod, FindUserQuery, Logger, WithSessionOptions, } from './types.js';
1
+ export { AuthError, SessionNotFoundError, SessionExpiredError, RoleNotHeldError, ServicePrincipalNotFoundError, InvalidInputError, } from './errors.js';
2
+ export type { Queryable, Session, SessionInfo, SessionContext, SessionIdentity, ScopeHook, SessionAuth, CreateSessionInput, GeoLocation, UserByCommunicationMethod, FindUserQuery, Logger, WithSessionOptions, } from './types.js';
3
3
  export { createSession } from './create-session.js';
4
4
  export { validateSession } from './validate-session.js';
5
- export { revokeSession } from './revoke-session.js';
5
+ export { revokeSession, revokeUserSessions, revokeTenantSessions } from './revoke-session.js';
6
+ export { touchSession } from './touch-session.js';
6
7
  export { findUserByCommunicationMethod } from './find-user-by-communication-method.js';
7
8
  export { getUserRoleNames } from './get-user-role-names.js';
8
9
  export { withSession } from './with-session.js';
9
- export { withTransaction } from './with-transaction.js';
10
- export { setSessionId, setRoleName, setTenantIds, setAllTenants, setSessionContext, SESSION_VAR_NAMES, } from './set-helpers.js';
11
10
  export { withServiceContext } from './with-service-context.js';
12
- export { verifyDevOtp, isDevOtpEnrolled, generateDevOtpSecret, getDevOtpEnrollmentUri, } from './dev-otp.js';
11
+ export { withTransaction } from '@smplcty/db';
12
+ export { IDENTITY_GUC, setLocal, setActorId, setSessionId, setActiveRole, setPrivileges, setIdentityContext, } from './set-helpers.js';
13
+ export { createMethodRouter } from './methods/router.js';
14
+ export { UnknownMethodError, OtpNotAllowedError, VerificationFailedError } from './methods/errors.js';
15
+ export type { MethodHandler, MethodInitiateResult, MethodInitiateContext, MethodCompleteContext, ResolvedUser, MethodRouter, MethodRouterOptions, SignInOptions, AuthDomain, } from './methods/types.js';
16
+ export { verifyDevOtp, isDevOtpEnrolled, generateDevOtpSecret, getDevOtpEnrollmentUri } from './dev-otp.js';
13
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,aAAa,CA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E,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG5D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAI/D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACtG,YAAY,EACV,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,UAAU,GACX,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -1,18 +1,24 @@
1
1
  // Errors
2
- export { AuthError, SessionNotFoundError, SessionExpiredError, RoleNotAssignedError, InvalidInputError, } from './errors.js';
2
+ export { AuthError, SessionNotFoundError, SessionExpiredError, RoleNotHeldError, ServicePrincipalNotFoundError, InvalidInputError, } from './errors.js';
3
3
  // Session lifecycle
4
4
  export { createSession } from './create-session.js';
5
5
  export { validateSession } from './validate-session.js';
6
- export { revokeSession } from './revoke-session.js';
6
+ export { revokeSession, revokeUserSessions, revokeTenantSessions } from './revoke-session.js';
7
+ export { touchSession } from './touch-session.js';
7
8
  export { findUserByCommunicationMethod } from './find-user-by-communication-method.js';
8
9
  export { getUserRoleNames } from './get-user-role-names.js';
9
10
  // Request bootstrapping
10
11
  export { withSession } from './with-session.js';
11
- export { withTransaction } from './with-transaction.js';
12
- // Low-level helpers — must be called inside an open transaction.
13
- export { setSessionId, setRoleName, setTenantIds, setAllTenants, setSessionContext, SESSION_VAR_NAMES, } from './set-helpers.js';
14
- // Background service context — for Lambdas with no user session.
12
+ // Background service context — for workers/Lambdas with no user session.
15
13
  export { withServiceContext } from './with-service-context.js';
14
+ // The transaction primitive now lives in @smplcty/db; re-exported for
15
+ // convenience so consumers don't need a direct import for the common case.
16
+ export { withTransaction } from '@smplcty/db';
17
+ // Identity GUC helpers — must be called inside an open transaction.
18
+ export { IDENTITY_GUC, setLocal, setActorId, setSessionId, setActiveRole, setPrivileges, setIdentityContext, } from './set-helpers.js';
19
+ // Authentication methods — pluggable two-phase handlers + auth_domains router.
20
+ export { createMethodRouter } from './methods/router.js';
21
+ export { UnknownMethodError, OtpNotAllowedError, VerificationFailedError } from './methods/errors.js';
16
22
  // Developer OTP — for devs whose phones can't receive Twilio SMS.
17
- export { verifyDevOtp, isDevOtpEnrolled, generateDevOtpSecret, getDevOtpEnrollmentUri, } from './dev-otp.js';
23
+ export { verifyDevOtp, isDevOtpEnrolled, generateDevOtpSecret, getDevOtpEnrollmentUri } from './dev-otp.js';
18
24
  //# 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,SAAS;AACT,OAAO,EACL,SAAS,EACT,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAgBrB,oBAAoB;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OA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AAChD,yEAAyE;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,sEAAsE;AACtE,2EAA2E;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,oEAAoE;AACpE,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAE1B,+EAA+E;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAatG,kEAAkE;AAClE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Generate a fresh opaque session token: 32 random bytes (256 bits of
3
+ * entropy), base64url-encoded so it's URL/cookie-safe. This is the raw
4
+ * bearer credential returned to the client — it is never stored.
5
+ */
6
+ export declare function generateToken(): string;
7
+ /**
8
+ * Derive the at-rest identifier for a token: its full SHA-256 hex digest.
9
+ * This is what's stored as `sessions.session_id`. A database leak exposes
10
+ * only hashes, which can't be replayed as bearer tokens.
11
+ *
12
+ * Distinct from `hashId` (a truncated, log-safe fingerprint): this is the
13
+ * full-width, collision-resistant key used for lookups.
14
+ */
15
+ export declare function hashToken(token: string): string;
16
+ //# sourceMappingURL=hash-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-token.d.ts","sourceRoot":"","sources":["../../src/internal/hash-token.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C"}
@@ -0,0 +1,21 @@
1
+ import { createHash, randomBytes } from 'node:crypto';
2
+ /**
3
+ * Generate a fresh opaque session token: 32 random bytes (256 bits of
4
+ * entropy), base64url-encoded so it's URL/cookie-safe. This is the raw
5
+ * bearer credential returned to the client — it is never stored.
6
+ */
7
+ export function generateToken() {
8
+ return randomBytes(32).toString('base64url');
9
+ }
10
+ /**
11
+ * Derive the at-rest identifier for a token: its full SHA-256 hex digest.
12
+ * This is what's stored as `sessions.session_id`. A database leak exposes
13
+ * only hashes, which can't be replayed as bearer tokens.
14
+ *
15
+ * Distinct from `hashId` (a truncated, log-safe fingerprint): this is the
16
+ * full-width, collision-resistant key used for lookups.
17
+ */
18
+ export function hashToken(token) {
19
+ return createHash('sha256').update(token).digest('hex');
20
+ }
21
+ //# sourceMappingURL=hash-token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-token.js","sourceRoot":"","sources":["../../src/internal/hash-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtD;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { AuthError } from '../errors.js';
2
+ /**
3
+ * Thrown by the method router when an identifier matches no `auth_domains`
4
+ * row and no default handler is configured (or a matched row's
5
+ * `integration_type` has no registered handler).
6
+ */
7
+ export declare class UnknownMethodError extends AuthError {
8
+ readonly name = "UnknownMethodError";
9
+ readonly code: "UNKNOWN_METHOD";
10
+ /** The identifier that couldn't be routed. */
11
+ readonly identifier: string;
12
+ /** The integration_type that had no handler, if a row matched. */
13
+ readonly integrationType?: string;
14
+ constructor(identifier: string, integrationType?: string);
15
+ }
16
+ /**
17
+ * Thrown when OTP (user-bound) sign-in is attempted for a tenant whose
18
+ * `allow_otp` is false — an SSO-only tenant. Enforced in the router so a
19
+ * crafted request can't bypass a hidden UI button.
20
+ */
21
+ export declare class OtpNotAllowedError extends AuthError {
22
+ readonly name = "OtpNotAllowedError";
23
+ readonly code: "OTP_NOT_ALLOWED";
24
+ readonly tenantId: number;
25
+ constructor(tenantId: number, message?: string);
26
+ }
27
+ /**
28
+ * Thrown by a handler's `complete` when the submitted credential fails
29
+ * verification (wrong/expired OTP, invalid id_token, unverifiable claims),
30
+ * or when a verified identity has no user and no provisioning is allowed.
31
+ */
32
+ export declare class VerificationFailedError extends AuthError {
33
+ readonly name = "VerificationFailedError";
34
+ readonly code: "VERIFICATION_FAILED";
35
+ constructor(message?: string);
36
+ }
37
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/methods/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,SAAS;IAC/C,SAAkB,IAAI,wBAAwB;IAC9C,SAAkB,IAAI,EAAG,gBAAgB,CAAU;IACnD,8CAA8C;IAC9C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,kEAAkE;IAClE,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;gBAEtB,UAAU,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM;CASzD;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,SAAS;IAC/C,SAAkB,IAAI,wBAAwB;IAC9C,SAAkB,IAAI,EAAG,iBAAiB,CAAU;IACpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAI/C;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,SAAS;IACpD,SAAkB,IAAI,6BAA6B;IACnD,SAAkB,IAAI,EAAG,qBAAqB,CAAU;gBAE5C,OAAO,GAAE,MAA8B;CAGpD"}
@@ -0,0 +1,48 @@
1
+ import { AuthError } from '../errors.js';
2
+ /**
3
+ * Thrown by the method router when an identifier matches no `auth_domains`
4
+ * row and no default handler is configured (or a matched row's
5
+ * `integration_type` has no registered handler).
6
+ */
7
+ export class UnknownMethodError extends AuthError {
8
+ name = 'UnknownMethodError';
9
+ code = 'UNKNOWN_METHOD';
10
+ /** The identifier that couldn't be routed. */
11
+ identifier;
12
+ /** The integration_type that had no handler, if a row matched. */
13
+ integrationType;
14
+ constructor(identifier, integrationType) {
15
+ super(integrationType
16
+ ? `No handler registered for integration_type "${integrationType}"`
17
+ : `No sign-in method matched identifier and no default handler is configured`);
18
+ this.identifier = identifier;
19
+ this.integrationType = integrationType;
20
+ }
21
+ }
22
+ /**
23
+ * Thrown when OTP (user-bound) sign-in is attempted for a tenant whose
24
+ * `allow_otp` is false — an SSO-only tenant. Enforced in the router so a
25
+ * crafted request can't bypass a hidden UI button.
26
+ */
27
+ export class OtpNotAllowedError extends AuthError {
28
+ name = 'OtpNotAllowedError';
29
+ code = 'OTP_NOT_ALLOWED';
30
+ tenantId;
31
+ constructor(tenantId, message) {
32
+ super(message ?? `OTP sign-in is not allowed for tenant ${tenantId}`);
33
+ this.tenantId = tenantId;
34
+ }
35
+ }
36
+ /**
37
+ * Thrown by a handler's `complete` when the submitted credential fails
38
+ * verification (wrong/expired OTP, invalid id_token, unverifiable claims),
39
+ * or when a verified identity has no user and no provisioning is allowed.
40
+ */
41
+ export class VerificationFailedError extends AuthError {
42
+ name = 'VerificationFailedError';
43
+ code = 'VERIFICATION_FAILED';
44
+ constructor(message = 'Verification failed') {
45
+ super(message);
46
+ }
47
+ }
48
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/methods/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IAC7B,IAAI,GAAG,oBAAoB,CAAC;IAC5B,IAAI,GAAG,gBAAyB,CAAC;IACnD,8CAA8C;IACrC,UAAU,CAAS;IAC5B,kEAAkE;IACzD,eAAe,CAAU;IAElC,YAAY,UAAkB,EAAE,eAAwB;QACtD,KAAK,CACH,eAAe;YACb,CAAC,CAAC,+CAA+C,eAAe,GAAG;YACnE,CAAC,CAAC,2EAA2E,CAChF,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IAC7B,IAAI,GAAG,oBAAoB,CAAC;IAC5B,IAAI,GAAG,iBAA0B,CAAC;IAC3C,QAAQ,CAAS;IAE1B,YAAY,QAAgB,EAAE,OAAgB;QAC5C,KAAK,CAAC,OAAO,IAAI,yCAAyC,QAAQ,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IAClC,IAAI,GAAG,yBAAyB,CAAC;IACjC,IAAI,GAAG,qBAA8B,CAAC;IAExD,YAAY,UAAkB,qBAAqB;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF"}