@dads-framework/identity-better-auth 0.0.0-stage → 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 (80) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +280 -2
  3. package/dist/identity-better-auth.tsbuildinfo +1 -0
  4. package/dist/impersonation-store/index.d.ts +3 -0
  5. package/dist/impersonation-store/index.d.ts.map +1 -0
  6. package/dist/impersonation-store/index.js +3 -0
  7. package/dist/impersonation-store/index.js.map +1 -0
  8. package/dist/impersonation-store/postgres-impersonation-store.d.ts +4 -0
  9. package/dist/impersonation-store/postgres-impersonation-store.d.ts.map +1 -0
  10. package/dist/impersonation-store/postgres-impersonation-store.js +75 -0
  11. package/dist/impersonation-store/postgres-impersonation-store.js.map +1 -0
  12. package/dist/index.d.ts +10 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +9 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/lib/account-invitations.d.ts +7 -0
  17. package/dist/lib/account-invitations.d.ts.map +1 -0
  18. package/dist/lib/account-invitations.js +46 -0
  19. package/dist/lib/account-invitations.js.map +1 -0
  20. package/dist/lib/configure-better-auth.d.ts +1509 -0
  21. package/dist/lib/configure-better-auth.d.ts.map +1 -0
  22. package/dist/lib/configure-better-auth.js +85 -0
  23. package/dist/lib/configure-better-auth.js.map +1 -0
  24. package/dist/lib/create-better-auth-identity.d.ts +9 -0
  25. package/dist/lib/create-better-auth-identity.d.ts.map +1 -0
  26. package/dist/lib/create-better-auth-identity.js +37 -0
  27. package/dist/lib/create-better-auth-identity.js.map +1 -0
  28. package/dist/lib/enterprise-callback-context.d.ts +9 -0
  29. package/dist/lib/enterprise-callback-context.d.ts.map +1 -0
  30. package/dist/lib/enterprise-callback-context.js +9 -0
  31. package/dist/lib/enterprise-callback-context.js.map +1 -0
  32. package/dist/lib/enterprise-options.d.ts +31 -0
  33. package/dist/lib/enterprise-options.d.ts.map +1 -0
  34. package/dist/lib/enterprise-options.js +119 -0
  35. package/dist/lib/enterprise-options.js.map +1 -0
  36. package/dist/lib/enterprise-plugin.d.ts +1038 -0
  37. package/dist/lib/enterprise-plugin.d.ts.map +1 -0
  38. package/dist/lib/enterprise-plugin.js +211 -0
  39. package/dist/lib/enterprise-plugin.js.map +1 -0
  40. package/dist/lib/enterprise-routes.d.ts +5 -0
  41. package/dist/lib/enterprise-routes.d.ts.map +1 -0
  42. package/dist/lib/enterprise-routes.js +215 -0
  43. package/dist/lib/enterprise-routes.js.map +1 -0
  44. package/dist/lib/identity-email.d.ts +4 -0
  45. package/dist/lib/identity-email.d.ts.map +1 -0
  46. package/dist/lib/identity-email.js +15 -0
  47. package/dist/lib/identity-email.js.map +1 -0
  48. package/dist/lib/identity-handler.d.ts +9 -0
  49. package/dist/lib/identity-handler.d.ts.map +1 -0
  50. package/dist/lib/identity-handler.js +102 -0
  51. package/dist/lib/identity-handler.js.map +1 -0
  52. package/dist/lib/identity-options.d.ts +15 -0
  53. package/dist/lib/identity-options.d.ts.map +1 -0
  54. package/dist/lib/identity-options.js +17 -0
  55. package/dist/lib/identity-options.js.map +1 -0
  56. package/dist/lib/identity-session-readers.d.ts +23 -0
  57. package/dist/lib/identity-session-readers.d.ts.map +1 -0
  58. package/dist/lib/identity-session-readers.js +81 -0
  59. package/dist/lib/identity-session-readers.js.map +1 -0
  60. package/dist/lib/install-identity-schema-v2.d.ts +4 -0
  61. package/dist/lib/install-identity-schema-v2.d.ts.map +1 -0
  62. package/dist/lib/install-identity-schema-v2.js +8 -0
  63. package/dist/lib/install-identity-schema-v2.js.map +1 -0
  64. package/dist/lib/migrations/20261120070500_identity.migration.d.ts +5 -0
  65. package/dist/lib/migrations/20261120070500_identity.migration.d.ts.map +1 -0
  66. package/dist/lib/migrations/20261120070500_identity.migration.js +81 -0
  67. package/dist/lib/migrations/20261120070500_identity.migration.js.map +1 -0
  68. package/dist/lib/migrations/20261120070530_identity_jwks.migration.d.ts +5 -0
  69. package/dist/lib/migrations/20261120070530_identity_jwks.migration.d.ts.map +1 -0
  70. package/dist/lib/migrations/20261120070530_identity_jwks.migration.js +10 -0
  71. package/dist/lib/migrations/20261120070530_identity_jwks.migration.js.map +1 -0
  72. package/dist/lib/migrations/20261120070600_enterprise_sso.migration.d.ts +5 -0
  73. package/dist/lib/migrations/20261120070600_enterprise_sso.migration.d.ts.map +1 -0
  74. package/dist/lib/migrations/20261120070600_enterprise_sso.migration.js +33 -0
  75. package/dist/lib/migrations/20261120070600_enterprise_sso.migration.js.map +1 -0
  76. package/dist/lib/migrations/20261120070700_staff_impersonation.migration.d.ts +6 -0
  77. package/dist/lib/migrations/20261120070700_staff_impersonation.migration.d.ts.map +1 -0
  78. package/dist/lib/migrations/20261120070700_staff_impersonation.migration.js +37 -0
  79. package/dist/lib/migrations/20261120070700_staff_impersonation.migration.js.map +1 -0
  80. package/package.json +50 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-options.d.ts","sourceRoot":"","sources":["../../src/lib/identity-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C,eAAO,MAAM,aAAa,cAAc,CAAC;AAEzC,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;KAAE,CAAC;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAC5C,QAAQ,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACnE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CACpC,CAAC;AAEF,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAgBvD"}
@@ -0,0 +1,17 @@
1
+ export const IDENTITY_PATH = "/api/auth";
2
+ export function validatedOrigin(baseUrl) {
3
+ const url = new URL(baseUrl);
4
+ const local = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
5
+ if (url.protocol !== "https:" && !(local && url.protocol === "http:")) {
6
+ throw new Error("Identity requires HTTPS or a loopback HTTP origin.");
7
+ }
8
+ if (url.username ||
9
+ url.password ||
10
+ url.pathname !== "/" ||
11
+ url.search ||
12
+ url.hash) {
13
+ throw new Error("Identity requires a bare origin.");
14
+ }
15
+ return url.origin;
16
+ }
17
+ //# sourceMappingURL=identity-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-options.js","sourceRoot":"","sources":["../../src/lib/identity-options.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;AAWzC,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,MAAM,KAAK,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACzE,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IACD,IACE,GAAG,CAAC,QAAQ;QACZ,GAAG,CAAC,QAAQ;QACZ,GAAG,CAAC,QAAQ,KAAK,GAAG;QACpB,GAAG,CAAC,MAAM;QACV,GAAG,CAAC,IAAI,EACR,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,GAAG,CAAC,MAAM,CAAC;AACpB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { Identity, IdentitySession } from "@dads-framework/identity";
2
+ import type { configureBetterAuth } from "./configure-better-auth.js";
3
+ import { type EnterpriseSsoProvider } from "./enterprise-options.js";
4
+ export type EnterpriseSsoSession = IdentitySession & {
5
+ readonly providerId: string;
6
+ readonly tenantId: string;
7
+ readonly authenticatedAt: Date;
8
+ };
9
+ export type EnterpriseBetterAuthIdentity = Identity & {
10
+ /** Authenticate the user for a tenant. Applications still authorize membership separately. */
11
+ readonly readTenantSession: (headers: Headers, tenantId: string) => Promise<IdentitySession | null>;
12
+ /** Snapshot a verified session to check tenant policy without another database lookup. */
13
+ readonly readTenantSessionPolicy: (headers: Headers) => Promise<{
14
+ readonly session: IdentitySession;
15
+ readonly allowsTenant: (tenantId: string) => boolean;
16
+ } | null>;
17
+ /** Read a session authenticated via this tenant's configured SSO provider. */
18
+ readonly readEnterpriseSession: (headers: Headers, tenantId: string, maxAgeMs?: number) => Promise<EnterpriseSsoSession | null>;
19
+ };
20
+ type BetterAuth = ReturnType<typeof configureBetterAuth>;
21
+ export declare function createIdentitySessionReaders(vendor: BetterAuth, providers: readonly EnterpriseSsoProvider[]): Omit<EnterpriseBetterAuthIdentity, "handle">;
22
+ export {};
23
+ //# sourceMappingURL=identity-session-readers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-session-readers.d.ts","sourceRoot":"","sources":["../../src/lib/identity-session-readers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,yBAAyB,CAAC;AAGjC,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG;IACnD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,eAAe,EAAE,IAAI,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,QAAQ,GAAG;IACpD,8FAA8F;IAC9F,QAAQ,CAAC,iBAAiB,EAAE,CAC1B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,KACb,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACrC,0FAA0F;IAC1F,QAAQ,CAAC,uBAAuB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;QAC9D,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;QAClC,QAAQ,CAAC,YAAY,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;KACtD,GAAG,IAAI,CAAC,CAAC;IACV,8EAA8E;IAC9E,QAAQ,CAAC,qBAAqB,EAAE,CAC9B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC;CAC3C,CAAC;AAEF,KAAK,UAAU,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEzD,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,SAAS,qBAAqB,EAAE,GAC1C,IAAI,CAAC,4BAA4B,EAAE,QAAQ,CAAC,CAsE9C"}
@@ -0,0 +1,81 @@
1
+ import { enterpriseProviderBinding, } from "./enterprise-options.js";
2
+ import { forEmail } from "./enterprise-plugin.js";
3
+ export function createIdentitySessionReaders(vendor, providers) {
4
+ async function readCurrent(headers) {
5
+ const current = await vendor.api.getSession({ headers });
6
+ if (current === null || !current.user.emailVerified)
7
+ return null;
8
+ const provider = forEmail(providers, current.user.email);
9
+ const sessionBinding = "ssoProviderBinding" in current.session
10
+ ? current.session.ssoProviderBinding
11
+ : undefined;
12
+ const hasProviderSession = sessionMatchesProvider(sessionBinding, provider);
13
+ if (!hasProviderSession &&
14
+ (provider?.mode === "required" || sessionBinding != null))
15
+ return null;
16
+ return { current, provider: hasProviderSession ? provider : undefined };
17
+ }
18
+ const readSession = async (headers) => {
19
+ const context = await readCurrent(headers);
20
+ return context === null ? null : identityView(context.current);
21
+ };
22
+ const readEnterpriseSession = async (headers, tenantId, maxAgeMs) => {
23
+ const context = await readCurrent(headers);
24
+ if (context === null || context.provider?.tenantId !== tenantId)
25
+ return null;
26
+ const authenticatedAt = context.current.session.createdAt;
27
+ if (!withinAge(authenticatedAt, maxAgeMs))
28
+ return null;
29
+ return {
30
+ ...identityView(context.current),
31
+ providerId: context.provider.id,
32
+ tenantId,
33
+ authenticatedAt,
34
+ };
35
+ };
36
+ const requiredTenants = new Set(providers
37
+ .filter(({ mode }) => mode === "required")
38
+ .map(({ tenantId }) => tenantId));
39
+ const readTenantSessionPolicy = async (headers) => {
40
+ const context = await readCurrent(headers);
41
+ if (context === null)
42
+ return null;
43
+ const session = identityView(context.current);
44
+ const expiresAt = session.expiresAt.getTime();
45
+ const ssoTenantId = context.provider?.tenantId;
46
+ return {
47
+ session,
48
+ allowsTenant: (tenantId) => expiresAt > Date.now() &&
49
+ (ssoTenantId === tenantId || !requiredTenants.has(tenantId)),
50
+ };
51
+ };
52
+ const readTenantSession = async (headers, tenantId) => {
53
+ const policy = await readTenantSessionPolicy(headers);
54
+ return policy?.allowsTenant(tenantId) ? policy.session : null;
55
+ };
56
+ return {
57
+ readSession,
58
+ readEnterpriseSession,
59
+ readTenantSession,
60
+ readTenantSessionPolicy,
61
+ };
62
+ }
63
+ function sessionMatchesProvider(binding, provider) {
64
+ return (typeof binding === "string" &&
65
+ provider !== undefined &&
66
+ binding === enterpriseProviderBinding(provider));
67
+ }
68
+ function withinAge(authenticatedAt, maxAgeMs) {
69
+ const age = Date.now() - authenticatedAt.getTime();
70
+ return (maxAgeMs === undefined ||
71
+ (Number.isFinite(maxAgeMs) && age >= 0 && age <= maxAgeMs));
72
+ }
73
+ function identityView(current) {
74
+ const { id, email, emailVerified } = current.user;
75
+ return {
76
+ account: { id, email, emailVerified },
77
+ expiresAt: current.session.expiresAt,
78
+ sessionId: current.session.id,
79
+ };
80
+ }
81
+ //# sourceMappingURL=identity-session-readers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity-session-readers.js","sourceRoot":"","sources":["../../src/lib/identity-session-readers.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,yBAAyB,GAE1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AA6BlD,MAAM,UAAU,4BAA4B,CAC1C,MAAkB,EAClB,SAA2C;IAE3C,KAAK,UAAU,WAAW,CAAC,OAAgB;QACzC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACzD,IAAI,OAAO,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa;YAAE,OAAO,IAAI,CAAC;QACjE,MAAM,QAAQ,GAAG,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzD,MAAM,cAAc,GAClB,oBAAoB,IAAI,OAAO,CAAC,OAAO;YACrC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,kBAAkB;YACpC,CAAC,CAAC,SAAS,CAAC;QAChB,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAC5E,IACE,CAAC,kBAAkB;YACnB,CAAC,QAAQ,EAAE,IAAI,KAAK,UAAU,IAAI,cAAc,IAAI,IAAI,CAAC;YAEzD,OAAO,IAAI,CAAC;QACd,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IAC1E,CAAC;IAED,MAA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AAED,SAAS,YAAY,CAAC,OAGrB;IACC,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAClD,OAAO;QACL,OAAO,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE;QACrC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS;QACpC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE;KAC9B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { MigrationBuilder } from "node-pg-migrate";
2
+ /** Installs the default identity schema in a fresh database. */
3
+ export declare function installIdentitySchemaV2(pgm: MigrationBuilder): void;
4
+ //# sourceMappingURL=install-identity-schema-v2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-identity-schema-v2.d.ts","sourceRoot":"","sources":["../../src/lib/install-identity-schema-v2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKxD,gEAAgE;AAChE,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,CAGnE"}
@@ -0,0 +1,8 @@
1
+ import { up as installIdentitySchemaV1 } from "./migrations/20261120070500_identity.migration.js";
2
+ import { up as installIdentitySigningKeyMetadataSchema } from "./migrations/20261120070530_identity_jwks.migration.js";
3
+ /** Installs the default identity schema in a fresh database. */
4
+ export function installIdentitySchemaV2(pgm) {
5
+ installIdentitySchemaV1(pgm);
6
+ installIdentitySigningKeyMetadataSchema(pgm);
7
+ }
8
+ //# sourceMappingURL=install-identity-schema-v2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-identity-schema-v2.js","sourceRoot":"","sources":["../../src/lib/install-identity-schema-v2.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,IAAI,uBAAuB,EAAE,MAAM,mDAAmD,CAAC;AAClG,OAAO,EAAE,EAAE,IAAI,uCAAuC,EAAE,MAAM,wDAAwD,CAAC;AAEvH,gEAAgE;AAChE,MAAM,UAAU,uBAAuB,CAAC,GAAqB;IAC3D,uBAAuB,CAAC,GAAG,CAAC,CAAC;IAC7B,uCAAuC,CAAC,GAAG,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { MigrationBuilder } from "node-pg-migrate";
2
+ export declare const dependsOn: readonly string[];
3
+ export declare function up(migration: MigrationBuilder): void;
4
+ export declare function down(migration: MigrationBuilder): void;
5
+ //# sourceMappingURL=20261120070500_identity.migration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20261120070500_identity.migration.d.ts","sourceRoot":"","sources":["../../../src/lib/migrations/20261120070500_identity.migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,eAAO,MAAM,SAAS,EAAE,SAAS,MAAM,EAAO,CAAC;AAE/C,wBAAgB,EAAE,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAoEpD;AAED,wBAAgB,IAAI,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAStD"}
@@ -0,0 +1,81 @@
1
+ export const dependsOn = [];
2
+ export function up(migration) {
3
+ migration.sql(`
4
+ CREATE TABLE identity_users (
5
+ id text PRIMARY KEY,
6
+ name text NOT NULL,
7
+ email text NOT NULL UNIQUE,
8
+ "emailVerified" boolean NOT NULL DEFAULT false,
9
+ image text,
10
+ "createdAt" timestamptz NOT NULL,
11
+ "updatedAt" timestamptz NOT NULL
12
+ );
13
+
14
+ CREATE TABLE identity_credentials (
15
+ id text PRIMARY KEY,
16
+ "accountId" text NOT NULL,
17
+ "providerId" text NOT NULL,
18
+ "userId" text NOT NULL REFERENCES identity_users (id) ON DELETE CASCADE,
19
+ "accessToken" text,
20
+ "refreshToken" text,
21
+ "idToken" text,
22
+ "accessTokenExpiresAt" timestamptz,
23
+ "refreshTokenExpiresAt" timestamptz,
24
+ scope text,
25
+ password text,
26
+ "createdAt" timestamptz NOT NULL,
27
+ "updatedAt" timestamptz NOT NULL,
28
+ UNIQUE ("providerId", "accountId")
29
+ );
30
+ CREATE INDEX identity_credentials_user_id_idx ON identity_credentials ("userId");
31
+
32
+ CREATE TABLE identity_sessions (
33
+ id text PRIMARY KEY,
34
+ token text NOT NULL UNIQUE,
35
+ "expiresAt" timestamptz NOT NULL,
36
+ "createdAt" timestamptz NOT NULL,
37
+ "updatedAt" timestamptz NOT NULL,
38
+ "ipAddress" text,
39
+ "userAgent" text,
40
+ "userId" text NOT NULL REFERENCES identity_users (id) ON DELETE CASCADE
41
+ );
42
+ CREATE INDEX identity_sessions_user_id_idx ON identity_sessions ("userId");
43
+
44
+ CREATE TABLE identity_verifications (
45
+ id text PRIMARY KEY,
46
+ identifier text NOT NULL,
47
+ value text NOT NULL,
48
+ "expiresAt" timestamptz NOT NULL,
49
+ "createdAt" timestamptz NOT NULL,
50
+ "updatedAt" timestamptz NOT NULL
51
+ );
52
+ CREATE INDEX identity_verifications_identifier_idx ON identity_verifications (identifier);
53
+
54
+ CREATE TABLE identity_signing_keys (
55
+ id text PRIMARY KEY,
56
+ "publicKey" text NOT NULL,
57
+ "privateKey" text NOT NULL,
58
+ "createdAt" timestamptz NOT NULL,
59
+ "expiresAt" timestamptz
60
+ );
61
+
62
+ CREATE TABLE identity_account_invitations (
63
+ digest text PRIMARY KEY,
64
+ email text NOT NULL,
65
+ expires_at timestamptz NOT NULL,
66
+ issued_by text NOT NULL REFERENCES identity_users (id) ON DELETE CASCADE
67
+ );
68
+ CREATE INDEX identity_account_invitations_expires_at_idx ON identity_account_invitations (expires_at);
69
+ `);
70
+ }
71
+ export function down(migration) {
72
+ migration.sql(`
73
+ DROP TABLE identity_account_invitations;
74
+ DROP TABLE identity_signing_keys;
75
+ DROP TABLE identity_verifications;
76
+ DROP TABLE identity_sessions;
77
+ DROP TABLE identity_credentials;
78
+ DROP TABLE identity_users;
79
+ `);
80
+ }
81
+ //# sourceMappingURL=20261120070500_identity.migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20261120070500_identity.migration.js","sourceRoot":"","sources":["../../../src/lib/migrations/20261120070500_identity.migration.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAsB,EAAE,CAAC;AAE/C,MAAM,UAAU,EAAE,CAAC,SAA2B;IAC5C,SAAS,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEb,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,SAA2B;IAC9C,SAAS,CAAC,GAAG,CAAC;;;;;;;GAOb,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { MigrationBuilder } from "node-pg-migrate";
2
+ export declare const dependsOn: readonly string[];
3
+ export declare function up(migration: MigrationBuilder): void;
4
+ export declare function down(migration: MigrationBuilder): void;
5
+ //# sourceMappingURL=20261120070530_identity_jwks.migration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20261120070530_identity_jwks.migration.d.ts","sourceRoot":"","sources":["../../../src/lib/migrations/20261120070530_identity_jwks.migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,eAAO,MAAM,SAAS,EAAE,SAAS,MAAM,EAEtC,CAAC;AAEF,wBAAgB,EAAE,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAIpD;AAED,wBAAgB,IAAI,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAItD"}
@@ -0,0 +1,10 @@
1
+ export const dependsOn = [
2
+ "20261120070500_identity.migration",
3
+ ];
4
+ export function up(migration) {
5
+ migration.sql("ALTER TABLE identity_signing_keys ADD COLUMN alg text, ADD COLUMN crv text");
6
+ }
7
+ export function down(migration) {
8
+ migration.sql("ALTER TABLE identity_signing_keys DROP COLUMN alg, DROP COLUMN crv");
9
+ }
10
+ //# sourceMappingURL=20261120070530_identity_jwks.migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20261120070530_identity_jwks.migration.js","sourceRoot":"","sources":["../../../src/lib/migrations/20261120070530_identity_jwks.migration.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAsB;IAC1C,mCAAmC;CACpC,CAAC;AAEF,MAAM,UAAU,EAAE,CAAC,SAA2B;IAC5C,SAAS,CAAC,GAAG,CACX,4EAA4E,CAC7E,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,SAA2B;IAC9C,SAAS,CAAC,GAAG,CACX,oEAAoE,CACrE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { MigrationBuilder } from "node-pg-migrate";
2
+ export declare const dependsOn: readonly string[];
3
+ export declare function up(migration: MigrationBuilder): void;
4
+ export declare function down(migration: MigrationBuilder): void;
5
+ //# sourceMappingURL=20261120070600_enterprise_sso.migration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20261120070600_enterprise_sso.migration.d.ts","sourceRoot":"","sources":["../../../src/lib/migrations/20261120070600_enterprise_sso.migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,eAAO,MAAM,SAAS,EAAE,SAAS,MAAM,EAEtC,CAAC;AAEF,wBAAgB,EAAE,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAoBpD;AAED,wBAAgB,IAAI,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAOtD"}
@@ -0,0 +1,33 @@
1
+ export const dependsOn = [
2
+ "20261120070500_identity.migration",
3
+ ];
4
+ export function up(migration) {
5
+ migration.sql(`
6
+ CREATE TABLE identity_sso_providers (
7
+ id text PRIMARY KEY,
8
+ issuer text NOT NULL,
9
+ "oidcConfig" text,
10
+ "samlConfig" text,
11
+ "userId" text NOT NULL REFERENCES identity_users (id) ON DELETE CASCADE,
12
+ "providerId" text NOT NULL UNIQUE,
13
+ "organizationId" text,
14
+ domain text NOT NULL,
15
+ "domainVerified" boolean,
16
+ CONSTRAINT identity_sso_providers_configuration_only CHECK (false)
17
+ );
18
+ ALTER TABLE identity_sessions ADD COLUMN "ssoProviderBinding" text;
19
+ ALTER TABLE identity_credentials ADD COLUMN "ssoProviderBinding" text;
20
+ CREATE UNIQUE INDEX identity_credentials_enterprise_provider_user_idx
21
+ ON identity_credentials ("providerId", "userId")
22
+ WHERE "providerId" LIKE 'sso-%';
23
+ `);
24
+ }
25
+ export function down(migration) {
26
+ migration.sql(`
27
+ DROP TABLE identity_sso_providers;
28
+ DROP INDEX identity_credentials_enterprise_provider_user_idx;
29
+ ALTER TABLE identity_sessions DROP COLUMN "ssoProviderBinding";
30
+ ALTER TABLE identity_credentials DROP COLUMN "ssoProviderBinding";
31
+ `);
32
+ }
33
+ //# sourceMappingURL=20261120070600_enterprise_sso.migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20261120070600_enterprise_sso.migration.js","sourceRoot":"","sources":["../../../src/lib/migrations/20261120070600_enterprise_sso.migration.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAsB;IAC1C,mCAAmC;CACpC,CAAC;AAEF,MAAM,UAAU,EAAE,CAAC,SAA2B;IAC5C,SAAS,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;GAkBb,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,SAA2B;IAC9C,SAAS,CAAC,GAAG,CAAC;;;;;GAKb,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { MigrationBuilder } from "node-pg-migrate";
2
+ export declare const dependsOn: readonly string[];
3
+ export declare function installStaffImpersonationSchemaV1(migration: MigrationBuilder): void;
4
+ export declare function up(migration: MigrationBuilder): void;
5
+ export declare function down(migration: MigrationBuilder): void;
6
+ //# sourceMappingURL=20261120070700_staff_impersonation.migration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20261120070700_staff_impersonation.migration.d.ts","sourceRoot":"","sources":["../../../src/lib/migrations/20261120070700_staff_impersonation.migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,eAAO,MAAM,SAAS,EAAE,SAAS,MAAM,EAEtC,CAAC;AAEF,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,gBAAgB,GAC1B,IAAI,CAuBN;AAED,wBAAgB,EAAE,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAEpD;AAED,wBAAgB,IAAI,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAKtD"}
@@ -0,0 +1,37 @@
1
+ export const dependsOn = [
2
+ "20261120070500_identity.migration",
3
+ ];
4
+ export function installStaffImpersonationSchemaV1(migration) {
5
+ migration.sql(`
6
+ CREATE TABLE identity_staff_impersonation_grants (
7
+ id text PRIMARY KEY,
8
+ tenant_id text NOT NULL,
9
+ staff_account_id text NOT NULL,
10
+ staff_session_id text NOT NULL,
11
+ effective_account_id text NOT NULL,
12
+ expires_at_ms bigint NOT NULL,
13
+ CHECK (staff_account_id <> effective_account_id)
14
+ );
15
+
16
+ CREATE INDEX identity_staff_impersonation_grants_expiry
17
+ ON identity_staff_impersonation_grants (expires_at_ms);
18
+
19
+ CREATE TABLE identity_staff_impersonation_audit (
20
+ id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
21
+ event jsonb NOT NULL
22
+ );
23
+
24
+ CREATE INDEX identity_staff_impersonation_audit_tenant
25
+ ON identity_staff_impersonation_audit ((event->>'tenantId'), id);
26
+ `);
27
+ }
28
+ export function up(migration) {
29
+ installStaffImpersonationSchemaV1(migration);
30
+ }
31
+ export function down(migration) {
32
+ migration.sql(`
33
+ DROP TABLE identity_staff_impersonation_grants;
34
+ DROP TABLE identity_staff_impersonation_audit;
35
+ `);
36
+ }
37
+ //# sourceMappingURL=20261120070700_staff_impersonation.migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"20261120070700_staff_impersonation.migration.js","sourceRoot":"","sources":["../../../src/lib/migrations/20261120070700_staff_impersonation.migration.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,SAAS,GAAsB;IAC1C,mCAAmC;CACpC,CAAC;AAEF,MAAM,UAAU,iCAAiC,CAC/C,SAA2B;IAE3B,SAAS,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;GAqBb,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,EAAE,CAAC,SAA2B;IAC5C,iCAAiC,CAAC,SAAS,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,SAA2B;IAC9C,SAAS,CAAC,GAAG,CAAC;;;GAGb,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@dads-framework/identity-better-auth",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "engines": {
6
+ "node": ">=22"
7
+ },
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./impersonation-store": {
14
+ "types": "./dist/impersonation-store/index.d.ts",
15
+ "default": "./dist/impersonation-store/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md"
21
+ ],
22
+ "scripts": {
23
+ "prepublishOnly": "node ../../../scripts/verify-prepublish.mjs",
24
+ "build": "tsc -b",
25
+ "test": "vitest run",
26
+ "test:integration": "VITEST_TIER=integration vitest run",
27
+ "typecheck": "tsc -b --pretty false"
28
+ },
29
+ "dependencies": {
30
+ "@better-auth/core": "1.7.26",
31
+ "@better-auth/sso": "1.7.26",
32
+ "@dads-framework/identity": "0.2.0",
33
+ "better-auth": "1.7.26",
34
+ "kysely": "0.28.17",
35
+ "node-pg-migrate": "^9.0.0"
36
+ },
37
+ "devDependencies": {
38
+ "@dads-framework/migrations": "0.2.0",
39
+ "@dads-framework/postgres": "0.2.0",
40
+ "@testcontainers/postgresql": "^12.0.4",
41
+ "samlify": "2.15.1",
42
+ "testcontainers": "^12.0.4",
43
+ "vitest": "~4.1.0"
44
+ },
45
+ "license": "MIT",
46
+ "author": "Bryton Cooper",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/brytoncooper/dads-framework.git",
50
+ "directory": "packages/server/identity-better-auth"
51
+ }
52
+ }