@banata-auth/convex 0.1.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 (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +104 -0
  3. package/dist/auth-config.d.ts +22 -0
  4. package/dist/auth-config.d.ts.map +1 -0
  5. package/dist/auth-config.js +3 -0
  6. package/dist/auth-config.js.map +1 -0
  7. package/dist/auth.d.ts +462 -0
  8. package/dist/auth.d.ts.map +1 -0
  9. package/dist/component/adapter.d.ts +21 -0
  10. package/dist/component/adapter.d.ts.map +1 -0
  11. package/dist/component/adapter.js +3 -0
  12. package/dist/component/adapter.js.map +1 -0
  13. package/dist/component/schema.d.ts +1026 -0
  14. package/dist/component/schema.d.ts.map +1 -0
  15. package/dist/hooks.d.ts +25 -0
  16. package/dist/hooks.d.ts.map +1 -0
  17. package/dist/http.d.ts +41 -0
  18. package/dist/http.d.ts.map +1 -0
  19. package/dist/http.js +62 -0
  20. package/dist/http.js.map +1 -0
  21. package/dist/index.d.ts +9 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +9516 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/node.d.ts +389 -0
  26. package/dist/node.d.ts.map +1 -0
  27. package/dist/node.js +9559 -0
  28. package/dist/node.js.map +1 -0
  29. package/dist/plugins/audit.d.ts +106 -0
  30. package/dist/plugins/audit.d.ts.map +1 -0
  31. package/dist/plugins/config.d.ts +83 -0
  32. package/dist/plugins/config.d.ts.map +1 -0
  33. package/dist/plugins/domains.d.ts +3 -0
  34. package/dist/plugins/domains.d.ts.map +1 -0
  35. package/dist/plugins/email-sender.d.ts +75 -0
  36. package/dist/plugins/email-sender.d.ts.map +1 -0
  37. package/dist/plugins/email-templates.d.ts +108 -0
  38. package/dist/plugins/email-templates.d.ts.map +1 -0
  39. package/dist/plugins/email.d.ts +82 -0
  40. package/dist/plugins/email.d.ts.map +1 -0
  41. package/dist/plugins/enterprise.d.ts +3 -0
  42. package/dist/plugins/enterprise.d.ts.map +1 -0
  43. package/dist/plugins/events.d.ts +40 -0
  44. package/dist/plugins/events.d.ts.map +1 -0
  45. package/dist/plugins/index.d.ts +18 -0
  46. package/dist/plugins/index.d.ts.map +1 -0
  47. package/dist/plugins/index.js +9192 -0
  48. package/dist/plugins/index.js.map +1 -0
  49. package/dist/plugins/organization-rbac.d.ts +3 -0
  50. package/dist/plugins/organization-rbac.d.ts.map +1 -0
  51. package/dist/plugins/portal.d.ts +34 -0
  52. package/dist/plugins/portal.d.ts.map +1 -0
  53. package/dist/plugins/projects.d.ts +16 -0
  54. package/dist/plugins/projects.d.ts.map +1 -0
  55. package/dist/plugins/protection.d.ts +127 -0
  56. package/dist/plugins/protection.d.ts.map +1 -0
  57. package/dist/plugins/types.d.ts +508 -0
  58. package/dist/plugins/types.d.ts.map +1 -0
  59. package/dist/plugins/user-management.d.ts +8 -0
  60. package/dist/plugins/user-management.d.ts.map +1 -0
  61. package/dist/plugins/vault.d.ts +68 -0
  62. package/dist/plugins/vault.d.ts.map +1 -0
  63. package/dist/plugins/webhook.d.ts +65 -0
  64. package/dist/plugins/webhook.d.ts.map +1 -0
  65. package/dist/triggers.d.ts +158 -0
  66. package/dist/triggers.d.ts.map +1 -0
  67. package/dist/triggers.js +36 -0
  68. package/dist/triggers.js.map +1 -0
  69. package/package.json +102 -0
  70. package/src/component/adapter.ts +21 -0
  71. package/src/component/convex.config.ts +15 -0
  72. package/src/component/schema.ts +916 -0
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Audit log plugin for Banata Auth.
3
+ *
4
+ * Provides:
5
+ * - API endpoints for listing, creating, and exporting audit events
6
+ * - Automatic logging of auth events via Better Auth hooks
7
+ * - Organization-scoped audit trails
8
+ *
9
+ * This plugin follows Better Auth's plugin pattern and uses the Convex
10
+ * database adapter (from Better Auth's context) to store events in the
11
+ * `auditEvent` table defined in the component schema.
12
+ *
13
+ * @see {@link ../../component/schema.ts} for the auditEvent table definition
14
+ * @see {@link ../../../shared/src/types.ts} for the AuditEvent SDK type
15
+ */
16
+ import type { BetterAuthPlugin } from "better-auth";
17
+ import { type PluginDBAdapter } from "./types";
18
+ export interface AuditLogPluginOptions {
19
+ /** Actions to automatically log. If empty, logs all auth actions. */
20
+ autoLogActions?: string[];
21
+ /** Whether to auto-log all Better Auth endpoint calls. Default: true */
22
+ autoLog?: boolean;
23
+ }
24
+ /**
25
+ * Audit log plugin for Banata Auth.
26
+ *
27
+ * Registers custom API endpoints under `/api/auth/banata/audit-logs/`
28
+ * for listing, creating, and exporting audit events.
29
+ *
30
+ * Also installs an `after` hook on all Better Auth endpoints to
31
+ * automatically log auth events (sign-in, sign-up, password changes,
32
+ * organization operations, admin actions, etc.) into the `auditEvent`
33
+ * table via the Convex database adapter.
34
+ *
35
+ * @param options - Optional configuration for auto-logging behavior
36
+ * @returns A Better Auth plugin descriptor
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { auditLog } from "./plugins/audit";
41
+ *
42
+ * const plugins = [
43
+ * auditLog(),
44
+ * // ... other plugins
45
+ * ];
46
+ * ```
47
+ */
48
+ export declare function auditLog(options?: AuditLogPluginOptions): BetterAuthPlugin;
49
+ /**
50
+ * Parameters for the `logAuditEvent` helper.
51
+ *
52
+ * Maps directly to the `auditEvent` table columns defined in
53
+ * the component schema (see `src/component/schema.ts`).
54
+ */
55
+ export interface LogAuditEventParams {
56
+ /** Optional project scope for multi-tenant isolation. */
57
+ projectId?: string;
58
+ action: string;
59
+ actorType: "user" | "admin" | "system" | "api_key" | "scim";
60
+ actorId: string;
61
+ actorName?: string;
62
+ actorEmail?: string;
63
+ actorMetadata?: Record<string, string>;
64
+ targets?: Array<{
65
+ type: string;
66
+ id: string;
67
+ name?: string;
68
+ metadata?: Record<string, string>;
69
+ }>;
70
+ organizationId?: string;
71
+ ipAddress?: string;
72
+ userAgent?: string;
73
+ requestId?: string;
74
+ changes?: {
75
+ before?: Record<string, unknown>;
76
+ after?: Record<string, unknown>;
77
+ };
78
+ idempotencyKey?: string;
79
+ metadata?: Record<string, string>;
80
+ }
81
+ /**
82
+ * Log an audit event from a Better Auth hook or trigger handler.
83
+ *
84
+ * This helper can be called from Better Auth hooks, Convex triggers,
85
+ * or any code that has access to the database adapter to create an
86
+ * audit event record without going through the HTTP endpoint.
87
+ *
88
+ * @param adapter - The Better Auth database adapter (ctx.context.adapter)
89
+ * @param params - The audit event data
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import { logAuditEvent } from "./plugins/audit";
94
+ *
95
+ * // Inside a Better Auth hook or trigger:
96
+ * await logAuditEvent(ctx.context.adapter, {
97
+ * action: "user.login",
98
+ * actorType: "user",
99
+ * actorId: user.id,
100
+ * actorEmail: user.email,
101
+ * ipAddress: request.headers.get("x-forwarded-for"),
102
+ * });
103
+ * ```
104
+ */
105
+ export declare function logAuditEvent(adapter: Pick<PluginDBAdapter, "create">, params: LogAuditEventParams): Promise<void>;
106
+ //# sourceMappingURL=audit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/plugins/audit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD,OAAO,EAEN,KAAK,eAAe,EAKpB,MAAM,SAAS,CAAC;AAIjB,MAAM,WAAW,qBAAqB;IACrC,qEAAqE;IACrE,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,wEAAwE;IACxE,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AA0HD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,gBAAgB,CAsR1E;AAID;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IACnC,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,OAAO,CAAC,EAAE,KAAK,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAClC,CAAC,CAAC;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;IAChF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,aAAa,CAClC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,EACxC,MAAM,EAAE,mBAAmB,GACzB,OAAO,CAAC,IAAI,CAAC,CAmCf"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Dashboard configuration plugin for Banata Auth.
3
+ *
4
+ * Provides CRUD endpoints for dashboard configuration data that
5
+ * doesn't exist natively in Better Auth:
6
+ *
7
+ * - `/banata/config/public` — Read runtime auth config for public UIs
8
+ * - `/banata/config/dashboard` — Read dashboard config (with persisted overrides)
9
+ * - `/banata/config/dashboard/save` — Save partial dashboard config overrides
10
+ * - `/banata/config/roles/list` — List custom role definitions
11
+ * - `/banata/config/roles/create` — Create a role definition
12
+ * - `/banata/config/roles/delete` — Delete a role definition
13
+ * - `/banata/config/permissions/list` — List custom permission definitions
14
+ * - `/banata/config/permissions/create` — Create a permission definition
15
+ * - `/banata/config/permissions/delete` — Delete a permission definition
16
+ * - `/banata/config/branding/get` — Get branding config
17
+ * - `/banata/config/branding/save` — Upsert branding config
18
+ * - `/banata/config/emails/list` — List email toggles
19
+ * - `/banata/config/emails/toggle` — Toggle an email type on/off
20
+ * - `/banata/config/project/get` — Get project config (name, description, env)
21
+ * - `/banata/config/project/save` — Save project config
22
+ *
23
+ * All endpoints are registered under `/api/auth/banata/config/...` through
24
+ * Better Auth's plugin system and proxied via the existing catch-all route.
25
+ *
26
+ * @see {@link ../../component/schema.ts} for table definitions
27
+ * @see {@link ../auth.ts} for plugin registration
28
+ */
29
+ import type { BetterAuthPlugin } from "better-auth";
30
+ export interface ConfigPluginOptions {
31
+ /**
32
+ * Static auth methods config — mirrors BanataAuthConfig.authMethods.
33
+ * These are read from the server environment, not stored in DB.
34
+ */
35
+ authMethods?: {
36
+ sso?: boolean;
37
+ emailPassword?: boolean;
38
+ passkey?: boolean;
39
+ magicLink?: boolean;
40
+ emailOtp?: boolean;
41
+ twoFactor?: boolean;
42
+ organization?: boolean;
43
+ anonymous?: boolean;
44
+ username?: boolean;
45
+ };
46
+ /**
47
+ * Social providers config — keys are provider names, values indicate
48
+ * whether they are enabled + whether they use demo credentials.
49
+ */
50
+ socialProviders?: Record<string, {
51
+ enabled: boolean;
52
+ demo?: boolean;
53
+ }>;
54
+ /**
55
+ * Static feature flags.
56
+ */
57
+ features?: {
58
+ hostedUi?: boolean;
59
+ signUp?: boolean;
60
+ mfa?: boolean;
61
+ localization?: boolean;
62
+ };
63
+ /**
64
+ * Static session configuration.
65
+ */
66
+ sessions?: {
67
+ maxSessionLength?: string;
68
+ accessTokenDuration?: string;
69
+ inactivityTimeout?: string;
70
+ corsOrigins?: string[];
71
+ };
72
+ }
73
+ /**
74
+ * Config plugin for the Banata Auth dashboard.
75
+ *
76
+ * Registers endpoints under `/api/auth/banata/config/...` for managing
77
+ * dashboard configuration, roles, permissions, branding, and emails.
78
+ *
79
+ * @param options - Static config values sourced from environment/auth config
80
+ * @returns A Better Auth plugin descriptor
81
+ */
82
+ export declare function configPlugin(options?: ConfigPluginOptions): BetterAuthPlugin;
83
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/plugins/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AA4BpD,MAAM,WAAW,mBAAmB;IACnC;;;OAGG;IACH,WAAW,CAAC,EAAE;QACb,GAAG,CAAC,EAAE,OAAO,CAAC;QACd,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;IAEF;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAEvE;;OAEG;IACH,QAAQ,CAAC,EAAE;QACV,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,GAAG,CAAC,EAAE,OAAO,CAAC;QACd,YAAY,CAAC,EAAE,OAAO,CAAC;KACvB,CAAC;IAEF;;OAEG;IACH,QAAQ,CAAC,EAAE;QACV,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC;CACF;AAkuBD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,CAmxD5E"}
@@ -0,0 +1,3 @@
1
+ import type { BetterAuthPlugin } from "better-auth";
2
+ export declare function domainsPlugin(): BetterAuthPlugin;
3
+ //# sourceMappingURL=domains.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domains.d.ts","sourceRoot":"","sources":["../../src/plugins/domains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAqLpD,wBAAgB,aAAa,IAAI,gBAAgB,CAwOhD"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Provider-agnostic email sending abstraction for Banata Auth.
3
+ *
4
+ * All providers use the Fetch API directly (no Node.js SDKs), making this
5
+ * compatible with Convex's runtime, Cloudflare Workers, Deno, and any
6
+ * other edge/serverless environment.
7
+ *
8
+ * Supported providers:
9
+ * - Resend (https://resend.com)
10
+ * - SendGrid (https://sendgrid.com)
11
+ * - Amazon SES (https://aws.amazon.com/ses) — via SES v2 HTTP API
12
+ * - Mailgun (https://mailgun.com)
13
+ * - Postmark (https://postmarkapp.com)
14
+ */
15
+ export type EmailProviderId = "resend" | "sendgrid" | "ses" | "mailgun" | "postmark";
16
+ export interface EmailMessage {
17
+ /** Sender address (e.g., "noreply@acme.com" or "Acme <noreply@acme.com>"). */
18
+ from: string;
19
+ /** Recipient address. */
20
+ to: string;
21
+ /** Email subject. */
22
+ subject: string;
23
+ /** HTML body. */
24
+ html: string;
25
+ /** Plain text body (fallback). */
26
+ text?: string;
27
+ /** Reply-to address. */
28
+ replyTo?: string;
29
+ }
30
+ export interface EmailProviderCredentials {
31
+ /** API key (used by Resend, SendGrid, Mailgun, Postmark). */
32
+ apiKey?: string;
33
+ /** AWS region (used by SES). */
34
+ region?: string;
35
+ /** AWS access key ID (used by SES). */
36
+ accessKeyId?: string;
37
+ /** AWS secret access key (used by SES). */
38
+ secretAccessKey?: string;
39
+ /** Mailgun domain (e.g., "mg.example.com"). */
40
+ domain?: string;
41
+ }
42
+ export interface SendResult {
43
+ success: boolean;
44
+ messageId?: string;
45
+ error?: string;
46
+ }
47
+ /**
48
+ * Send an email using the specified provider.
49
+ *
50
+ * This is the main entry point for sending emails. It dispatches to the
51
+ * appropriate provider implementation based on the `provider` parameter.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { sendEmail } from "@banata-auth/convex/plugins";
56
+ *
57
+ * await sendEmail("resend", {
58
+ * from: "noreply@acme.com",
59
+ * to: "user@example.com",
60
+ * subject: "Welcome!",
61
+ * html: "<h1>Welcome</h1>",
62
+ * }, {
63
+ * apiKey: "re_xxxxx",
64
+ * });
65
+ * ```
66
+ */
67
+ export declare function sendEmail(provider: EmailProviderId, message: EmailMessage, credentials: EmailProviderCredentials): Promise<SendResult>;
68
+ /**
69
+ * Validate that the required credentials are present for a given provider.
70
+ */
71
+ export declare function validateCredentials(provider: EmailProviderId, credentials: EmailProviderCredentials): {
72
+ valid: boolean;
73
+ missing: string[];
74
+ };
75
+ //# sourceMappingURL=email-sender.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-sender.d.ts","sourceRoot":"","sources":["../../src/plugins/email-sender.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,UAAU,GAAG,KAAK,GAAG,SAAS,GAAG,UAAU,CAAC;AAErF,MAAM,WAAW,YAAY;IAC5B,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,wBAAwB;IACxC,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2CAA2C;IAC3C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,UAAU;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AA2SD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,SAAS,CAC9B,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,wBAAwB,GACnC,OAAO,CAAC,UAAU,CAAC,CAoBrB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAClC,QAAQ,EAAE,eAAe,EACzB,WAAW,EAAE,wBAAwB,GACnC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAoBvC"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Built-in email templates for Banata Auth.
3
+ *
4
+ * Server-renderable HTML email templates designed for maximum email client
5
+ * compatibility. Uses inline styles and table-based layouts (the email
6
+ * industry standard) for consistent rendering across Gmail, Outlook,
7
+ * Apple Mail, Yahoo Mail, and others.
8
+ *
9
+ * Templates are parameterized with branding (colors, logo, app name)
10
+ * and can be overridden per-template via the dashboard.
11
+ *
12
+ * The visual design follows React Email / Resend conventions:
13
+ * - Clean, minimal layout
14
+ * - Centered card with subtle border
15
+ * - Primary-colored CTA button
16
+ * - Muted footer with legal text
17
+ */
18
+ export interface EmailBranding {
19
+ /** Application name displayed in the email header. */
20
+ appName: string;
21
+ /** Primary color for buttons and accents (hex). */
22
+ primaryColor: string;
23
+ /** Background color of the email body (hex). */
24
+ bgColor: string;
25
+ /** Logo URL (optional, displayed above the heading). */
26
+ logoUrl?: string;
27
+ /** Border radius for buttons in pixels. */
28
+ borderRadius: number;
29
+ /** Font family stack (full CSS value). */
30
+ fontFamily: string;
31
+ /** Whether dark mode is enabled. Affects card/text colors. */
32
+ darkMode: boolean;
33
+ /** Custom CSS to inject into a <style> block in the email. */
34
+ customCss?: string;
35
+ }
36
+ /**
37
+ * Map a short font name (stored in DB) to a full CSS font-family stack.
38
+ */
39
+ export declare function fontNameToStack(font: string | null | undefined): string | undefined;
40
+ export type EmailTemplateType = "verification" | "password-reset" | "magic-link" | "email-otp" | "invitation" | "welcome";
41
+ export interface VerificationEmailData {
42
+ type: "verification";
43
+ userName: string;
44
+ verificationUrl: string;
45
+ token: string;
46
+ }
47
+ export interface PasswordResetEmailData {
48
+ type: "password-reset";
49
+ userName: string;
50
+ resetUrl: string;
51
+ token: string;
52
+ }
53
+ export interface MagicLinkEmailData {
54
+ type: "magic-link";
55
+ email: string;
56
+ magicLinkUrl: string;
57
+ token: string;
58
+ }
59
+ export interface EmailOtpData {
60
+ type: "email-otp";
61
+ email: string;
62
+ otp: string;
63
+ }
64
+ export interface InvitationEmailData {
65
+ type: "invitation";
66
+ email: string;
67
+ invitationId: string;
68
+ organizationName: string;
69
+ inviterName: string;
70
+ /** If the consumer provides a URL builder, we can include a direct link. */
71
+ acceptUrl?: string;
72
+ }
73
+ export interface WelcomeEmailData {
74
+ type: "welcome";
75
+ userName: string;
76
+ /** URL to the app dashboard or getting-started page. */
77
+ dashboardUrl?: string;
78
+ }
79
+ export type EmailData = VerificationEmailData | PasswordResetEmailData | MagicLinkEmailData | EmailOtpData | InvitationEmailData | WelcomeEmailData;
80
+ export interface RenderedEmail {
81
+ subject: string;
82
+ html: string;
83
+ text: string;
84
+ }
85
+ /**
86
+ * Render an email template with the given data and branding.
87
+ *
88
+ * Can be called from:
89
+ * - The Convex auth plugin (automatic sending on auth events)
90
+ * - The SDK (`banataAuth.emails.send(...)`)
91
+ * - The dashboard (template preview)
92
+ *
93
+ * @param data - The email data (type-discriminated union)
94
+ * @param brandingOverrides - Partial branding, merged with defaults
95
+ * @returns The rendered email with subject, HTML, and plain text
96
+ */
97
+ export declare function renderEmail(data: EmailData, brandingOverrides?: Partial<EmailBranding>): RenderedEmail;
98
+ /**
99
+ * Get the subject line for a given email template type.
100
+ * Useful for the dashboard template preview.
101
+ */
102
+ export declare function getTemplateSubject(type: EmailTemplateType, appName?: string): string;
103
+ /**
104
+ * Generate preview data for a template type.
105
+ * Used by the dashboard template preview and the SDK.
106
+ */
107
+ export declare function getPreviewData(type: EmailTemplateType): EmailData;
108
+ //# sourceMappingURL=email-templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-templates.d.ts","sourceRoot":"","sources":["../../src/plugins/email-templates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,WAAW,aAAa;IAC7B,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,YAAY,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,QAAQ,EAAE,OAAO,CAAC;IAClB,8DAA8D;IAC9D,SAAS,CAAC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B,GACrB,sBAAsB,GACtB,kBAAkB,GAClB,YAAY,GACZ,mBAAmB,GACnB,gBAAgB,CAAC;AAIpB,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACb;AAqWD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAC1B,IAAI,EAAE,SAAS,EACf,iBAAiB,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GACxC,aAAa,CAqBf;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,SAAgB,GAAG,MAAM,CAe3F;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,iBAAiB,GAAG,SAAS,CA6CjE"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Built-in email plugin for Banata Auth.
3
+ *
4
+ * Provides automatic email sending on auth events (verification,
5
+ * password reset, magic link, OTP, invitation, welcome) using the
6
+ * provider and credentials configured through the dashboard.
7
+ *
8
+ * The plugin:
9
+ * 1. Reads the active email provider + API key from the DB (set via dashboard)
10
+ * 2. Reads branding config from the DB (colors, logo, app name)
11
+ * 3. Renders built-in HTML email templates with the branding
12
+ * 4. Sends via the configured provider's HTTP API (no Node.js SDKs)
13
+ *
14
+ * Consumer callbacks (in BanataAuthEmailConfig) still work as overrides:
15
+ * if a consumer provides e.g. `sendVerificationEmail`, it takes priority
16
+ * over the built-in sending for that email type.
17
+ *
18
+ * Also exposes API endpoints for the SDK and dashboard:
19
+ * - POST /banata/emails/send — SDK-driven email sending
20
+ * - POST /banata/emails/preview — Template preview for dashboard
21
+ * - POST /banata/test-email — Send test email
22
+ */
23
+ import type { BetterAuthPlugin } from "better-auth";
24
+ import { type PluginDBAdapter } from "./types";
25
+ /** Options for the banataEmail plugin. */
26
+ export interface BanataEmailOptions {
27
+ /**
28
+ * Default "from" address for all outgoing emails.
29
+ * Can include a name: "Acme <noreply@acme.com>"
30
+ */
31
+ fromAddress?: string;
32
+ /**
33
+ * Default "reply-to" address for outgoing emails.
34
+ */
35
+ replyTo?: string;
36
+ /**
37
+ * Application name used in email templates.
38
+ * Falls back to branding config, then "Banata Auth".
39
+ */
40
+ appName?: string;
41
+ }
42
+ /**
43
+ * Create the Banata Auth email plugin.
44
+ *
45
+ * Registers API endpoints for SDK-driven email sending, template
46
+ * preview, and test email delivery.
47
+ */
48
+ export declare function banataEmail(options?: BanataEmailOptions): BetterAuthPlugin;
49
+ export declare function createAutoEmailCallbacks(getDb: () => PluginDBAdapter, emailOptions: BanataEmailOptions): {
50
+ sendVerificationEmail: (params: {
51
+ user: {
52
+ email: string;
53
+ name: string;
54
+ };
55
+ url: string;
56
+ token: string;
57
+ }) => Promise<void>;
58
+ sendResetPassword: (params: {
59
+ user: {
60
+ email: string;
61
+ name: string;
62
+ };
63
+ url: string;
64
+ token: string;
65
+ }) => Promise<void>;
66
+ sendMagicLink: (params: {
67
+ email: string;
68
+ url: string;
69
+ token: string;
70
+ }) => Promise<void>;
71
+ sendOtp: (params: {
72
+ email: string;
73
+ otp: string;
74
+ }) => Promise<void>;
75
+ sendInvitationEmail: (params: {
76
+ email: string;
77
+ invitationId: string;
78
+ organizationName: string;
79
+ inviterName: string;
80
+ }) => Promise<void>;
81
+ };
82
+ //# sourceMappingURL=email.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../../src/plugins/email.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAiBpD,OAAO,EAIN,KAAK,eAAe,EAKpB,MAAM,SAAS,CAAC;AAoBjB,0CAA0C;AAC1C,MAAM,WAAW,kBAAkB;IAClC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AA+gBD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,gBAAgB,CA4e9E;AAiCD,wBAAgB,wBAAwB,CACvC,KAAK,EAAE,MAAM,eAAe,EAC5B,YAAY,EAAE,kBAAkB;oCAGO;QACrC,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;QACtC,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;KACd;gCA0BiC;QACjC,IAAI,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;QACtC,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;KACd;4BA0B6B;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;sBA0BnD;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;kCAyBlB;QACnC,KAAK,EAAE,MAAM,CAAC;QACd,YAAY,EAAE,MAAM,CAAC;QACrB,gBAAgB,EAAE,MAAM,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC;KACpB;EA2BF"}
@@ -0,0 +1,3 @@
1
+ import type { BetterAuthPlugin } from "better-auth";
2
+ export declare function enterpriseProvisioningPlugin(): BetterAuthPlugin;
3
+ //# sourceMappingURL=enterprise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enterprise.d.ts","sourceRoot":"","sources":["../../src/plugins/enterprise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAqlBpD,wBAAgB,4BAA4B,IAAI,gBAAgB,CAsgB/D"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Events plugin for Banata Auth.
3
+ *
4
+ * Provides a unified event stream API that queries the existing `auditEvent`
5
+ * table and maps records into lightweight `WebhookEvent`-compatible shapes.
6
+ *
7
+ * This gives consumers a simple, poll-based alternative to webhooks —
8
+ * similar to WorkOS's Events API. Under the hood, events are sourced from
9
+ * audit log records stored by the audit plugin.
10
+ *
11
+ * @see {@link ./audit.ts} for the underlying audit log plugin
12
+ * @see {@link ../../../shared/src/types.ts} for the WebhookEvent SDK type
13
+ */
14
+ import type { BetterAuthPlugin } from "better-auth";
15
+ import { type AuditEventRow } from "./types";
16
+ /**
17
+ * Map an audit event row to a lightweight event payload.
18
+ */
19
+ /** @internal Exported for testing. */
20
+ export declare function toEventPayload(row: AuditEventRow): Record<string, unknown>;
21
+ /**
22
+ * Events plugin for Banata Auth.
23
+ *
24
+ * Registers a single API endpoint under `/api/auth/banata/events/list`
25
+ * that exposes audit events as a lightweight, pollable event stream.
26
+ *
27
+ * @returns A Better Auth plugin descriptor
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { eventsPlugin } from "./plugins/events";
32
+ *
33
+ * const plugins = [
34
+ * eventsPlugin(),
35
+ * // ... other plugins
36
+ * ];
37
+ * ```
38
+ */
39
+ export declare function eventsPlugin(): BetterAuthPlugin;
40
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/plugins/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGpD,OAAO,EACN,KAAK,aAAa,EAMlB,MAAM,SAAS,CAAC;AAuBjB;;GAEG;AACH,sCAAsC;AACtC,wBAAgB,cAAc,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAkB1E;AAYD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,IAAI,gBAAgB,CA4G/C"}
@@ -0,0 +1,18 @@
1
+ export { auditLog, logAuditEvent, type AuditLogPluginOptions, type LogAuditEventParams, } from "./audit";
2
+ export { webhookSystem, signWebhookPayload, verifyWebhookSignature, dispatchWebhookEvent, type WebhookPluginOptions, } from "./webhook";
3
+ export { configPlugin, type ConfigPluginOptions } from "./config";
4
+ export { banataProtection, type BanataProtectionOptions, type BotVerifyFn, type BotVerificationResult, } from "./protection";
5
+ export { banataEmail, createAutoEmailCallbacks, type BanataEmailOptions, } from "./email";
6
+ export { domainsPlugin } from "./domains";
7
+ export { eventsPlugin } from "./events";
8
+ export { vaultPlugin, type VaultPluginOptions, } from "./vault";
9
+ export { projectsPlugin, type ProjectsPluginOptions, } from "./projects";
10
+ export { enterpriseProvisioningPlugin } from "./enterprise";
11
+ export { portalPlugin } from "./portal";
12
+ export { organizationRbacPlugin } from "./organization-rbac";
13
+ export { userManagementPlugin } from "./user-management";
14
+ export { renderEmail, getTemplateSubject, getPreviewData, type EmailBranding, type EmailData, type EmailTemplateType, type RenderedEmail, type VerificationEmailData, type PasswordResetEmailData, type MagicLinkEmailData, type EmailOtpData, type InvitationEmailData, type WelcomeEmailData, } from "./email-templates";
15
+ export { sendEmail, validateCredentials, type EmailProviderId, type EmailMessage, type EmailProviderCredentials, type SendResult, } from "./email-sender";
16
+ export { projectScopeSchema, getProjectScope, getEffectiveProjectPermissions, requireProjectPermission, } from "./types";
17
+ export type { PluginDBAdapter, PluginAuthContext, PluginEndpointContext, PluginHookContext, WhereClause, SortBy, SessionUser, SessionRecord, AuditEventRow, WebhookEndpointRow, WebhookDeliveryRow, RoleDefinitionRow, PermissionDefinitionRow, BrandingConfigRow, EmailConfigRow, EmailTemplateRow, ProjectRow, } from "./types";
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACN,QAAQ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