@dads-framework/identity-better-auth 0.1.0 → 0.2.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 (63) hide show
  1. package/README.md +214 -16
  2. package/dist/identity-better-auth.tsbuildinfo +1 -1
  3. package/dist/impersonation-store/index.d.ts +3 -0
  4. package/dist/impersonation-store/index.d.ts.map +1 -0
  5. package/dist/impersonation-store/index.js +3 -0
  6. package/dist/impersonation-store/index.js.map +1 -0
  7. package/dist/impersonation-store/postgres-impersonation-store.d.ts +4 -0
  8. package/dist/impersonation-store/postgres-impersonation-store.d.ts.map +1 -0
  9. package/dist/impersonation-store/postgres-impersonation-store.js +75 -0
  10. package/dist/impersonation-store/postgres-impersonation-store.js.map +1 -0
  11. package/dist/index.d.ts +6 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +5 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/lib/configure-better-auth.d.ts +1226 -5
  16. package/dist/lib/configure-better-auth.d.ts.map +1 -1
  17. package/dist/lib/configure-better-auth.js +21 -3
  18. package/dist/lib/configure-better-auth.js.map +1 -1
  19. package/dist/lib/create-better-auth-identity.d.ts +4 -0
  20. package/dist/lib/create-better-auth-identity.d.ts.map +1 -1
  21. package/dist/lib/create-better-auth-identity.js +22 -16
  22. package/dist/lib/create-better-auth-identity.js.map +1 -1
  23. package/dist/lib/enterprise-callback-context.d.ts +9 -0
  24. package/dist/lib/enterprise-callback-context.d.ts.map +1 -0
  25. package/dist/lib/enterprise-callback-context.js +9 -0
  26. package/dist/lib/enterprise-callback-context.js.map +1 -0
  27. package/dist/lib/enterprise-options.d.ts +31 -0
  28. package/dist/lib/enterprise-options.d.ts.map +1 -0
  29. package/dist/lib/enterprise-options.js +119 -0
  30. package/dist/lib/enterprise-options.js.map +1 -0
  31. package/dist/lib/enterprise-plugin.d.ts +1038 -0
  32. package/dist/lib/enterprise-plugin.d.ts.map +1 -0
  33. package/dist/lib/enterprise-plugin.js +211 -0
  34. package/dist/lib/enterprise-plugin.js.map +1 -0
  35. package/dist/lib/enterprise-routes.d.ts +5 -0
  36. package/dist/lib/enterprise-routes.d.ts.map +1 -0
  37. package/dist/lib/enterprise-routes.js +215 -0
  38. package/dist/lib/enterprise-routes.js.map +1 -0
  39. package/dist/lib/identity-handler.d.ts +2 -1
  40. package/dist/lib/identity-handler.d.ts.map +1 -1
  41. package/dist/lib/identity-handler.js +25 -5
  42. package/dist/lib/identity-handler.js.map +1 -1
  43. package/dist/lib/identity-session-readers.d.ts +23 -0
  44. package/dist/lib/identity-session-readers.d.ts.map +1 -0
  45. package/dist/lib/identity-session-readers.js +81 -0
  46. package/dist/lib/identity-session-readers.js.map +1 -0
  47. package/dist/lib/install-identity-schema-v2.d.ts +4 -0
  48. package/dist/lib/install-identity-schema-v2.d.ts.map +1 -0
  49. package/dist/lib/install-identity-schema-v2.js +8 -0
  50. package/dist/lib/install-identity-schema-v2.js.map +1 -0
  51. package/dist/lib/migrations/20261120070530_identity_jwks.migration.d.ts +5 -0
  52. package/dist/lib/migrations/20261120070530_identity_jwks.migration.d.ts.map +1 -0
  53. package/dist/lib/migrations/20261120070530_identity_jwks.migration.js +10 -0
  54. package/dist/lib/migrations/20261120070530_identity_jwks.migration.js.map +1 -0
  55. package/dist/lib/migrations/20261120070600_enterprise_sso.migration.d.ts +5 -0
  56. package/dist/lib/migrations/20261120070600_enterprise_sso.migration.d.ts.map +1 -0
  57. package/dist/lib/migrations/20261120070600_enterprise_sso.migration.js +33 -0
  58. package/dist/lib/migrations/20261120070600_enterprise_sso.migration.js.map +1 -0
  59. package/dist/lib/migrations/20261120070700_staff_impersonation.migration.d.ts +6 -0
  60. package/dist/lib/migrations/20261120070700_staff_impersonation.migration.d.ts.map +1 -0
  61. package/dist/lib/migrations/20261120070700_staff_impersonation.migration.js +37 -0
  62. package/dist/lib/migrations/20261120070700_staff_impersonation.migration.js.map +1 -0
  63. package/package.json +12 -5
@@ -0,0 +1,3 @@
1
+ export { createPostgresImpersonationStore } from "./postgres-impersonation-store.js";
2
+ export { installStaffImpersonationSchemaV1 } from "../lib/migrations/20261120070700_staff_impersonation.migration.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/impersonation-store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAE,iCAAiC,EAAE,MAAM,mEAAmE,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { createPostgresImpersonationStore } from "./postgres-impersonation-store.js";
2
+ export { installStaffImpersonationSchemaV1 } from "../lib/migrations/20261120070700_staff_impersonation.migration.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/impersonation-store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAE,iCAAiC,EAAE,MAAM,mEAAmE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { ImpersonationOptions } from "@dads-framework/identity/impersonation";
2
+ import type { PostgresPool } from "kysely";
3
+ export declare function createPostgresImpersonationStore(pool: PostgresPool): Pick<ImpersonationOptions, "store" | "writeAudit">;
4
+ //# sourceMappingURL=postgres-impersonation-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-impersonation-store.d.ts","sourceRoot":"","sources":["../../src/impersonation-store/postgres-impersonation-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,oBAAoB,EACrB,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AA2B3C,wBAAgB,gCAAgC,CAC9C,IAAI,EAAE,YAAY,GACjB,IAAI,CAAC,oBAAoB,EAAE,OAAO,GAAG,YAAY,CAAC,CA6DpD"}
@@ -0,0 +1,75 @@
1
+ function storedText(row, column) {
2
+ const value = Reflect.get(row, column);
3
+ if (typeof value !== "string")
4
+ throw new Error("Invalid stored impersonation grant");
5
+ return value;
6
+ }
7
+ function parseGrant(row) {
8
+ if (row === undefined)
9
+ return null;
10
+ if (typeof row !== "object" || row === null) {
11
+ throw new Error("Invalid stored impersonation grant");
12
+ }
13
+ const expiresAtMs = Number(storedText(row, "expires_at_ms"));
14
+ if (!Number.isSafeInteger(expiresAtMs))
15
+ throw new Error("Invalid impersonation grant expiry");
16
+ return {
17
+ id: storedText(row, "id"),
18
+ tenantId: storedText(row, "tenant_id"),
19
+ effectiveAccountId: storedText(row, "effective_account_id"),
20
+ staffAccountId: storedText(row, "staff_account_id"),
21
+ staffSessionId: storedText(row, "staff_session_id"),
22
+ expiresAtMs,
23
+ };
24
+ }
25
+ export function createPostgresImpersonationStore(pool) {
26
+ async function query(sql, parameters) {
27
+ const client = await pool.connect();
28
+ try {
29
+ return await client.query(sql, parameters);
30
+ }
31
+ finally {
32
+ client.release();
33
+ }
34
+ }
35
+ return {
36
+ store: {
37
+ async insert(grant, event) {
38
+ await query(`WITH created AS (
39
+ INSERT INTO identity_staff_impersonation_grants
40
+ (id, tenant_id, staff_account_id, effective_account_id, staff_session_id, expires_at_ms)
41
+ VALUES ($1, $2, $3, $4, $5, $6)
42
+ RETURNING id
43
+ )
44
+ INSERT INTO identity_staff_impersonation_audit (event)
45
+ SELECT $7::jsonb FROM created`, [
46
+ grant.id,
47
+ grant.tenantId,
48
+ grant.staffAccountId,
49
+ grant.effectiveAccountId,
50
+ grant.staffSessionId,
51
+ grant.expiresAtMs,
52
+ JSON.stringify(event),
53
+ ]);
54
+ },
55
+ async read(id) {
56
+ const result = await query(`SELECT id, tenant_id, staff_account_id, effective_account_id, staff_session_id, expires_at_ms::text
57
+ FROM identity_staff_impersonation_grants WHERE id = $1`, [id]);
58
+ return parseGrant(result.rows[0]);
59
+ },
60
+ async remove(id, event) {
61
+ const result = await query(`WITH deleted AS (
62
+ DELETE FROM identity_staff_impersonation_grants WHERE id = $1
63
+ RETURNING id
64
+ )
65
+ INSERT INTO identity_staff_impersonation_audit (event)
66
+ SELECT $2::jsonb FROM deleted`, [id, JSON.stringify(event)]);
67
+ return result.rowCount === 1;
68
+ },
69
+ },
70
+ async writeAudit(event) {
71
+ await query("INSERT INTO identity_staff_impersonation_audit (event) VALUES ($1::jsonb)", [JSON.stringify(event)]);
72
+ },
73
+ };
74
+ }
75
+ //# sourceMappingURL=postgres-impersonation-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgres-impersonation-store.js","sourceRoot":"","sources":["../../src/impersonation-store/postgres-impersonation-store.ts"],"names":[],"mappings":"AAMA,SAAS,UAAU,CAAC,GAAW,EAAE,MAAc;IAC7C,MAAM,KAAK,GAAY,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAChD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAC3B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,UAAU,CAAC,GAAY;IAC9B,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACnC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,CAAC;IAC7D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,OAAO;QACL,EAAE,EAAE,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC;QACzB,QAAQ,EAAE,UAAU,CAAC,GAAG,EAAE,WAAW,CAAC;QACtC,kBAAkB,EA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AAC,CAC5B,CAAC;gBACF,OAAO,MAAM,CAAC,QAAQ,KAAK,CAAC,CAAC;YAC/B,CAAC;SACF;QACD,KAAK,CAAC,UAAU,CAAC,KAAK;YACpB,MAAM,KAAK,CACT,2EAA2E,EAC3E,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CACxB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,10 @@
1
1
  export { createBetterAuthIdentity } from "./lib/create-better-auth-identity.js";
2
2
  export { IDENTITY_PATH, type BetterAuthIdentityOptions, } from "./lib/identity-options.js";
3
+ export { installIdentitySchemaV2 } from "./lib/install-identity-schema-v2.js";
3
4
  export { up as installIdentitySchemaV1 } from "./lib/migrations/20261120070500_identity.migration.js";
5
+ export { createEnterpriseBetterAuthIdentity } from "./lib/create-better-auth-identity.js";
6
+ export { enterpriseSsoDomainChallenge, type EnterpriseSsoProvider, } from "./lib/enterprise-options.js";
7
+ export { up as installIdentityEnterpriseSsoSchema } from "./lib/migrations/20261120070600_enterprise_sso.migration.js";
8
+ export { up as installIdentitySigningKeyMetadataSchema } from "./lib/migrations/20261120070530_identity_jwks.migration.js";
9
+ export type { EnterpriseBetterAuthIdentity, EnterpriseSsoSession, } from "./lib/identity-session-readers.js";
4
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EACL,aAAa,EACb,KAAK,yBAAyB,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,EAAE,IAAI,uBAAuB,EAAE,MAAM,uDAAuD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EACL,aAAa,EACb,KAAK,yBAAyB,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,EAAE,IAAI,uBAAuB,EAAE,MAAM,uDAAuD,CAAC;AAEtG,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EACL,4BAA4B,EAC5B,KAAK,qBAAqB,GAC3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,EAAE,IAAI,kCAAkC,EAAE,MAAM,6DAA6D,CAAC;AACvH,OAAO,EAAE,EAAE,IAAI,uCAAuC,EAAE,MAAM,4DAA4D,CAAC;AAC3H,YAAY,EACV,4BAA4B,EAC5B,oBAAoB,GACrB,MAAM,mCAAmC,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,9 @@
1
1
  export { createBetterAuthIdentity } from "./lib/create-better-auth-identity.js";
2
2
  export { IDENTITY_PATH, } from "./lib/identity-options.js";
3
+ export { installIdentitySchemaV2 } from "./lib/install-identity-schema-v2.js";
3
4
  export { up as installIdentitySchemaV1 } from "./lib/migrations/20261120070500_identity.migration.js";
5
+ export { createEnterpriseBetterAuthIdentity } from "./lib/create-better-auth-identity.js";
6
+ export { enterpriseSsoDomainChallenge, } from "./lib/enterprise-options.js";
7
+ export { up as installIdentityEnterpriseSsoSchema } from "./lib/migrations/20261120070600_enterprise_sso.migration.js";
8
+ export { up as installIdentitySigningKeyMetadataSchema } from "./lib/migrations/20261120070530_identity_jwks.migration.js";
4
9
  //# 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,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EACL,aAAa,GAEd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,EAAE,IAAI,uBAAuB,EAAE,MAAM,uDAAuD,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EACL,aAAa,GAEd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,EAAE,IAAI,uBAAuB,EAAE,MAAM,uDAAuD,CAAC;AAEtG,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EACL,4BAA4B,GAE7B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,EAAE,IAAI,kCAAkC,EAAE,MAAM,6DAA6D,CAAC;AACvH,OAAO,EAAE,EAAE,IAAI,uCAAuC,EAAE,MAAM,4DAA4D,CAAC"}