@momentumcms/auth 0.4.1 → 0.5.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momentumcms/auth",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "Better Auth integration for Momentum CMS",
5
5
  "license": "MIT",
6
6
  "author": "Momentum CMS Contributors",
@@ -26,12 +26,20 @@
26
26
  "main": "./index.cjs",
27
27
  "types": "./src/index.d.ts",
28
28
  "peerDependencies": {
29
+ "@angular/core": ">=19.0.0",
29
30
  "@momentumcms/core": ">=0.0.1",
31
+ "@momentumcms/email": ">=0.5.1",
30
32
  "@momentumcms/logger": ">=0.0.1",
31
33
  "better-auth": "^1.4.0",
32
34
  "better-sqlite3": "^12.0.0",
33
35
  "nodemailer": "^8.0.0",
34
36
  "pg": "^8.0.0"
35
37
  },
38
+ "dependencies": {
39
+ "@angular/compiler": "~21.2.0",
40
+ "@angular/platform-browser": "~21.2.0",
41
+ "@angular/platform-server": "~21.2.0",
42
+ "juice": "^11.1.1"
43
+ },
36
44
  "module": "./index.js"
37
45
  }
package/src/lib/auth.d.ts CHANGED
@@ -2,6 +2,7 @@ import { betterAuth } from 'better-auth';
2
2
  import type { Pool } from 'pg';
3
3
  import type { Database } from 'better-sqlite3';
4
4
  import { type EmailConfig } from './email';
5
+ import { type FindEmailTemplateFn } from './email-templates';
5
6
  import type { Field } from '@momentumcms/core';
6
7
  import type { OAuthProvidersConfig } from './auth-core';
7
8
  export type { MomentumUser, MomentumSession, OAuthProviderConfig, OAuthProvidersConfig, } from './auth-core';
@@ -26,6 +27,12 @@ export interface MomentumEmailOptions extends EmailConfig {
26
27
  appName?: string;
27
28
  /** Require email verification on signup. Default: false */
28
29
  requireEmailVerification?: boolean;
30
+ /**
31
+ * Optional callback to look up email templates from the database.
32
+ * When provided, DB templates are used first; falls back to Angular SSR rendering.
33
+ * Typically wired from the email plugin's API.
34
+ */
35
+ findEmailTemplate?: FindEmailTemplateFn;
29
36
  }
30
37
  /**
31
38
  * Configuration options for Momentum Auth.
@@ -43,8 +50,6 @@ export interface MomentumAuthConfig {
43
50
  email?: MomentumEmailOptions;
44
51
  /** OAuth social login providers */
45
52
  socialProviders?: OAuthProvidersConfig;
46
- /** Enable two-factor authentication (TOTP). Default: false */
47
- twoFactorAuth?: boolean;
48
53
  /** Additional Better Auth plugins (from sub-plugins). */
49
54
  plugins?: unknown[];
50
55
  /** Extra user fields to register with Better Auth's user.additionalFields. */
@@ -66,8 +71,6 @@ export interface MomentumAuthConfigLegacy {
66
71
  email?: MomentumEmailOptions;
67
72
  /** OAuth social login providers */
68
73
  socialProviders?: OAuthProvidersConfig;
69
- /** Enable two-factor authentication (TOTP). Default: false */
70
- twoFactorAuth?: boolean;
71
74
  }
72
75
  /**
73
76
  * Get the list of enabled OAuth provider names from config/env vars.
@@ -0,0 +1,11 @@
1
+ export interface PasswordResetEmailData {
2
+ name?: string;
3
+ url: string;
4
+ appName: string;
5
+ expiresIn: string;
6
+ }
7
+ export declare class PasswordResetEmailComponent {
8
+ readonly data: PasswordResetEmailData;
9
+ readonly year: number;
10
+ get greeting(): string;
11
+ }
@@ -0,0 +1,11 @@
1
+ export interface VerificationEmailData {
2
+ name?: string;
3
+ url: string;
4
+ appName: string;
5
+ expiresIn: string;
6
+ }
7
+ export declare class VerificationEmailComponent {
8
+ readonly data: VerificationEmailData;
9
+ readonly year: number;
10
+ get greeting(): string;
11
+ }
@@ -1,7 +1,20 @@
1
+ /**
2
+ * Result of looking up an email template from the database.
3
+ * Returned by `findEmailTemplate` callbacks.
4
+ */
5
+ export interface DbEmailTemplate {
6
+ subject?: string;
7
+ emailBlocks?: unknown[];
8
+ }
9
+ /**
10
+ * Callback type for looking up email templates from the database.
11
+ * Returns null if no template is found (falls back to Angular SSR rendering).
12
+ */
13
+ export type FindEmailTemplateFn = (slug: string) => Promise<DbEmailTemplate | null>;
1
14
  /**
2
15
  * Email template options.
3
16
  */
4
- interface EmailTemplateOptions {
17
+ export interface EmailTemplateOptions {
5
18
  /** Recipient's name */
6
19
  name?: string;
7
20
  /** Action URL (reset link, verification link, etc.) */
@@ -10,39 +23,46 @@ interface EmailTemplateOptions {
10
23
  appName?: string;
11
24
  /** Expiration time for the link (e.g., '1 hour') */
12
25
  expiresIn?: string;
26
+ /** Optional callback to look up templates from the database (DB-first). */
27
+ findEmailTemplate?: FindEmailTemplateFn;
13
28
  }
14
29
  /**
15
30
  * Generate password reset email content.
16
31
  *
32
+ * If `findEmailTemplate` is provided, queries the DB for a 'password-reset' template first.
33
+ * Falls back to Angular SSR rendering if no DB template is found.
34
+ *
17
35
  * @example
18
36
  * ```typescript
19
- * const { subject, text, html } = getPasswordResetEmail({
37
+ * const { subject, text, html } = await getPasswordResetEmail({
20
38
  * name: 'John',
21
39
  * url: 'https://example.com/admin/reset-password?token=abc123',
22
40
  * expiresIn: '1 hour',
23
41
  * });
24
42
  * ```
25
43
  */
26
- export declare function getPasswordResetEmail(options: EmailTemplateOptions): {
44
+ export declare function getPasswordResetEmail(options: EmailTemplateOptions): Promise<{
27
45
  subject: string;
28
46
  text: string;
29
47
  html: string;
30
- };
48
+ }>;
31
49
  /**
32
50
  * Generate email verification email content.
33
51
  *
52
+ * If `findEmailTemplate` is provided, queries the DB for a 'verification' template first.
53
+ * Falls back to Angular SSR rendering if no DB template is found.
54
+ *
34
55
  * @example
35
56
  * ```typescript
36
- * const { subject, text, html } = getVerificationEmail({
57
+ * const { subject, text, html } = await getVerificationEmail({
37
58
  * name: 'John',
38
59
  * url: 'https://example.com/admin/verify-email?token=abc123',
39
60
  * expiresIn: '24 hours',
40
61
  * });
41
62
  * ```
42
63
  */
43
- export declare function getVerificationEmail(options: EmailTemplateOptions): {
64
+ export declare function getVerificationEmail(options: EmailTemplateOptions): Promise<{
44
65
  subject: string;
45
66
  text: string;
46
67
  html: string;
47
- };
48
- export {};
68
+ }>;
@@ -1,19 +1,16 @@
1
1
  /**
2
- * Admin Sub-Plugin (Stub)
2
+ * Admin Sub-Plugin
3
3
  *
4
4
  * Wraps Better Auth's admin plugin for user management capabilities:
5
5
  * - Ban/unban users
6
6
  * - Impersonate users
7
7
  * - Admin-level session fields
8
- *
9
- * This is a stub — the Better Auth admin plugin import will be added
10
- * when the full admin integration is implemented.
11
8
  */
12
9
  import type { MomentumAuthSubPlugin } from './sub-plugin.types';
13
10
  /**
14
11
  * Creates the admin sub-plugin.
15
12
  *
16
- * Adds ban/impersonation fields to the user and session collections.
17
- * The actual Better Auth admin plugin will be wired in a future iteration.
13
+ * Adds ban/impersonation fields to the user and session collections
14
+ * and registers the Better Auth admin plugin for ban/unban/impersonation endpoints.
18
15
  */
19
16
  export declare function authAdmin(): MomentumAuthSubPlugin;
@@ -1,19 +1,16 @@
1
1
  /**
2
- * Organization Sub-Plugin (Stub)
2
+ * Organization Sub-Plugin
3
3
  *
4
4
  * Wraps Better Auth's organization plugin for multi-tenant capabilities:
5
5
  * - Organizations
6
6
  * - Members with roles
7
7
  * - Invitations
8
- *
9
- * This is a stub — the Better Auth organization plugin import will be added
10
- * when the full organization integration is implemented.
11
8
  */
12
9
  import type { MomentumAuthSubPlugin } from './sub-plugin.types';
13
10
  /**
14
11
  * Creates the organization sub-plugin.
15
12
  *
16
- * Adds organization, member, and invitation collections.
17
- * The actual Better Auth organization plugin will be wired in a future iteration.
13
+ * Adds organization, member, and invitation collections
14
+ * and registers the Better Auth organization plugin for multi-tenant endpoints.
18
15
  */
19
16
  export declare function authOrganization(): MomentumAuthSubPlugin;