@digilogiclabs/create-saas-app 2.7.3 → 2.8.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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/templates/shared/observability/web/src/lib/observability.ts +14 -22
- package/dist/templates/web/ai-platform/template/src/components/providers/app-providers.tsx +17 -27
- package/dist/templates/web/base/template/src/components/providers/app-providers.tsx +17 -30
- package/dist/templates/web/iot-dashboard/template/src/components/providers/app-providers.tsx +17 -24
- package/dist/templates/web/marketplace/template/src/components/providers/app-providers.tsx +17 -27
- package/dist/templates/web/micro-saas/template/src/components/providers/app-providers.tsx +17 -24
- package/dist/templates/web/ui-auth/template/src/components/providers/app-providers.tsx +17 -31
- package/dist/templates/web/ui-auth-payments-ai/template/src/components/providers/app-providers.tsx +17 -35
- package/dist/templates/web/ui-auth-payments-audio/template/src/components/providers/app-providers.tsx +17 -35
- package/dist/templates/web/ui-auth-payments-video/template/src/components/providers/app-providers.tsx +17 -31
- package/package.json +1 -1
- package/src/templates/shared/observability/web/src/lib/observability.ts +14 -22
- package/src/templates/web/ai-platform/template/src/components/providers/app-providers.tsx +17 -27
- package/src/templates/web/base/template/src/components/providers/app-providers.tsx +17 -30
- package/src/templates/web/iot-dashboard/template/src/components/providers/app-providers.tsx +17 -24
- package/src/templates/web/marketplace/template/src/components/providers/app-providers.tsx +17 -27
- package/src/templates/web/micro-saas/template/src/components/providers/app-providers.tsx +17 -24
- package/src/templates/web/ui-auth/template/src/components/providers/app-providers.tsx +17 -31
- package/src/templates/web/ui-auth-payments-ai/template/src/components/providers/app-providers.tsx +17 -35
- package/src/templates/web/ui-auth-payments-audio/template/src/components/providers/app-providers.tsx +17 -35
- package/src/templates/web/ui-auth-payments-video/template/src/components/providers/app-providers.tsx +17 -31
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getClientIp } from '@digilogiclabs/platform-core/auth';
|
|
2
|
+
import type { AuditEvent, AuditCategory } from '@digilogiclabs/platform-core';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Observability helpers — audit logging, error reporting, metrics.
|
|
@@ -13,22 +14,11 @@ const SERVICE_NAME = 'my-app';
|
|
|
13
14
|
|
|
14
15
|
// ─── Lazy Singletons ────────────────────────────────────────
|
|
15
16
|
|
|
16
|
-
let auditLogPromise: Promise<AuditLogger> | null = null;
|
|
17
|
-
|
|
18
17
|
interface AuditLogger {
|
|
19
|
-
log(event: AuditEvent): Promise<
|
|
18
|
+
log(event: AuditEvent): Promise<unknown>;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
action: string;
|
|
24
|
-
actor: { id: string; type: string; email?: string };
|
|
25
|
-
resource?: { type: string; id?: string };
|
|
26
|
-
outcome: 'success' | 'failure' | 'blocked';
|
|
27
|
-
metadata?: Record<string, unknown>;
|
|
28
|
-
category?: string;
|
|
29
|
-
ip?: string;
|
|
30
|
-
userAgent?: string;
|
|
31
|
-
}
|
|
21
|
+
let auditLogPromise: Promise<AuditLogger> | null = null;
|
|
32
22
|
|
|
33
23
|
async function getAuditLog(): Promise<AuditLogger> {
|
|
34
24
|
if (!auditLogPromise) {
|
|
@@ -37,7 +27,7 @@ async function getAuditLog(): Promise<AuditLogger> {
|
|
|
37
27
|
const { getPlatform } = await import('@/lib/platform');
|
|
38
28
|
const platform = await getPlatform();
|
|
39
29
|
const { DatabaseAuditLog } = await import('@digilogiclabs/platform-core');
|
|
40
|
-
return new DatabaseAuditLog(platform.db,
|
|
30
|
+
return new DatabaseAuditLog({ database: platform.db, serviceName: SERVICE_NAME });
|
|
41
31
|
} catch {
|
|
42
32
|
return {
|
|
43
33
|
log: async (event: AuditEvent) => {
|
|
@@ -67,7 +57,7 @@ export function auditAction(params: {
|
|
|
67
57
|
actorEmail?: string;
|
|
68
58
|
resourceType?: string;
|
|
69
59
|
resourceId?: string;
|
|
70
|
-
outcome?: 'success' | 'failure' | '
|
|
60
|
+
outcome?: 'success' | 'failure' | 'denied' | 'error';
|
|
71
61
|
metadata?: Record<string, unknown>;
|
|
72
62
|
request?: Request;
|
|
73
63
|
}): void {
|
|
@@ -81,14 +71,16 @@ export function auditAction(params: {
|
|
|
81
71
|
type: params.actorId === 'system' ? 'system' : 'user',
|
|
82
72
|
email: params.actorEmail,
|
|
83
73
|
},
|
|
84
|
-
|
|
74
|
+
target: params.resourceType
|
|
85
75
|
? { type: params.resourceType, id: params.resourceId }
|
|
86
76
|
: undefined,
|
|
87
77
|
outcome: params.outcome || 'success',
|
|
88
|
-
|
|
78
|
+
data: {
|
|
79
|
+
...params.metadata,
|
|
80
|
+
ip: params.request ? getClientIp(params.request) : undefined,
|
|
81
|
+
userAgent: params.request ? getUserAgent(params.request) : undefined,
|
|
82
|
+
},
|
|
89
83
|
category,
|
|
90
|
-
ip: params.request ? getClientIp(params.request) : undefined,
|
|
91
|
-
userAgent: params.request ? getUserAgent(params.request) : undefined,
|
|
92
84
|
})
|
|
93
85
|
)
|
|
94
86
|
.catch(() => {});
|
|
@@ -124,12 +116,12 @@ export function captureError(error: unknown, context?: Record<string, unknown>):
|
|
|
124
116
|
|
|
125
117
|
// ─── Helpers ─────────────────────────────────────────────────
|
|
126
118
|
|
|
127
|
-
function inferCategory(action: string):
|
|
128
|
-
if (action.startsWith('admin.')) return '
|
|
119
|
+
function inferCategory(action: string): AuditCategory {
|
|
120
|
+
if (action.startsWith('admin.')) return 'admin_action';
|
|
129
121
|
if (action.startsWith('payment.')) return 'billing';
|
|
130
122
|
if (action.startsWith('account.')) return 'data_mutation';
|
|
131
123
|
if (action.startsWith('auth.')) return 'authentication';
|
|
132
124
|
if (action.startsWith('cron.')) return 'system';
|
|
133
125
|
if (action.startsWith('security.')) return 'security';
|
|
134
|
-
return '
|
|
126
|
+
return 'custom';
|
|
135
127
|
}
|
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { ThemeProvider } from 'next-themes'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
interface AppProvidersProps {
|
|
7
|
-
children: React.ReactNode
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
-
return (
|
|
12
|
-
<ThemeProvider attribute="class" defaultTheme="
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
payments: {
|
|
19
|
-
provider: 'stripe',
|
|
20
|
-
},
|
|
21
|
-
}}
|
|
22
|
-
>
|
|
23
|
-
{children}
|
|
24
|
-
</DLLProvider>
|
|
25
|
-
</ThemeProvider>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from 'next-themes'
|
|
4
|
+
import { Toaster } from '@digilogiclabs/saas-factory-ui'
|
|
5
|
+
|
|
6
|
+
interface AppProvidersProps {
|
|
7
|
+
children: React.ReactNode
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
+
return (
|
|
12
|
+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
|
|
13
|
+
{children}
|
|
14
|
+
<Toaster />
|
|
15
|
+
</ThemeProvider>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -1,30 +1,17 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
defaultTheme="{{defaultTheme}}"
|
|
19
|
-
enableSystem
|
|
20
|
-
disableTransitionOnChange
|
|
21
|
-
storageKey="{{packageName}}-theme"
|
|
22
|
-
>
|
|
23
|
-
<AppThemeProvider themeColor="{{themeColor}}">
|
|
24
|
-
{children}
|
|
25
|
-
<Toaster />
|
|
26
|
-
</AppThemeProvider>
|
|
27
|
-
</ThemeProvider>
|
|
28
|
-
</DLLProvider>
|
|
29
|
-
)
|
|
30
|
-
}
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from 'next-themes'
|
|
4
|
+
import { Toaster } from '@digilogiclabs/saas-factory-ui'
|
|
5
|
+
|
|
6
|
+
interface AppProvidersProps {
|
|
7
|
+
children: React.ReactNode
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
+
return (
|
|
12
|
+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
|
|
13
|
+
{children}
|
|
14
|
+
<Toaster />
|
|
15
|
+
</ThemeProvider>
|
|
16
|
+
)
|
|
17
|
+
}
|
package/dist/templates/web/iot-dashboard/template/src/components/providers/app-providers.tsx
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { ThemeProvider } from 'next-themes'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
interface AppProvidersProps {
|
|
7
|
-
children: React.ReactNode
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
-
return (
|
|
12
|
-
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}}
|
|
19
|
-
>
|
|
20
|
-
{children}
|
|
21
|
-
</DLLProvider>
|
|
22
|
-
</ThemeProvider>
|
|
23
|
-
)
|
|
24
|
-
}
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from 'next-themes'
|
|
4
|
+
import { Toaster } from '@digilogiclabs/saas-factory-ui'
|
|
5
|
+
|
|
6
|
+
interface AppProvidersProps {
|
|
7
|
+
children: React.ReactNode
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
+
return (
|
|
12
|
+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
|
|
13
|
+
{children}
|
|
14
|
+
<Toaster />
|
|
15
|
+
</ThemeProvider>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { ThemeProvider } from 'next-themes'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
interface AppProvidersProps {
|
|
7
|
-
children: React.ReactNode
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
-
return (
|
|
12
|
-
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
payments: {
|
|
19
|
-
provider: 'stripe',
|
|
20
|
-
},
|
|
21
|
-
}}
|
|
22
|
-
>
|
|
23
|
-
{children}
|
|
24
|
-
</DLLProvider>
|
|
25
|
-
</ThemeProvider>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from 'next-themes'
|
|
4
|
+
import { Toaster } from '@digilogiclabs/saas-factory-ui'
|
|
5
|
+
|
|
6
|
+
interface AppProvidersProps {
|
|
7
|
+
children: React.ReactNode
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
+
return (
|
|
12
|
+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
|
|
13
|
+
{children}
|
|
14
|
+
<Toaster />
|
|
15
|
+
</ThemeProvider>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { ThemeProvider } from 'next-themes'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
interface AppProvidersProps {
|
|
7
|
-
children: React.ReactNode
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
-
return (
|
|
12
|
-
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}}
|
|
19
|
-
>
|
|
20
|
-
{children}
|
|
21
|
-
</DLLProvider>
|
|
22
|
-
</ThemeProvider>
|
|
23
|
-
)
|
|
24
|
-
}
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from 'next-themes'
|
|
4
|
+
import { Toaster } from '@digilogiclabs/saas-factory-ui'
|
|
5
|
+
|
|
6
|
+
interface AppProvidersProps {
|
|
7
|
+
children: React.ReactNode
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
+
return (
|
|
12
|
+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
|
|
13
|
+
{children}
|
|
14
|
+
<Toaster />
|
|
15
|
+
</ThemeProvider>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
enableSystem
|
|
19
|
-
disableTransitionOnChange
|
|
20
|
-
storageKey="{{packageName}}-theme"
|
|
21
|
-
>
|
|
22
|
-
<DLLProvider>
|
|
23
|
-
<AppThemeProvider themeColor="{{themeColor}}">
|
|
24
|
-
{children}
|
|
25
|
-
<Toaster />
|
|
26
|
-
</AppThemeProvider>
|
|
27
|
-
</DLLProvider>
|
|
28
|
-
</ThemeProvider>
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
-
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from 'next-themes'
|
|
4
|
+
import { Toaster } from '@digilogiclabs/saas-factory-ui'
|
|
5
|
+
|
|
6
|
+
interface AppProvidersProps {
|
|
7
|
+
children: React.ReactNode
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
+
return (
|
|
12
|
+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
|
|
13
|
+
{children}
|
|
14
|
+
<Toaster />
|
|
15
|
+
</ThemeProvider>
|
|
16
|
+
)
|
|
17
|
+
}
|
package/dist/templates/web/ui-auth-payments-ai/template/src/components/providers/app-providers.tsx
CHANGED
|
@@ -1,35 +1,17 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<ThemeProvider
|
|
20
|
-
attribute="class"
|
|
21
|
-
defaultTheme={defaultTheme}
|
|
22
|
-
enableSystem
|
|
23
|
-
disableTransitionOnChange
|
|
24
|
-
storageKey={`${packageName}-theme`}
|
|
25
|
-
>
|
|
26
|
-
<DLLProvider>
|
|
27
|
-
<AppThemeProvider themeColor={themeColor}>
|
|
28
|
-
{children}
|
|
29
|
-
<Toaster />
|
|
30
|
-
</AppThemeProvider>
|
|
31
|
-
</DLLProvider>
|
|
32
|
-
</ThemeProvider>
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from 'next-themes'
|
|
4
|
+
import { Toaster } from '@digilogiclabs/saas-factory-ui'
|
|
5
|
+
|
|
6
|
+
interface AppProvidersProps {
|
|
7
|
+
children: React.ReactNode
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
+
return (
|
|
12
|
+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
|
|
13
|
+
{children}
|
|
14
|
+
<Toaster />
|
|
15
|
+
</ThemeProvider>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -1,35 +1,17 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<ThemeProvider
|
|
20
|
-
attribute="class"
|
|
21
|
-
defaultTheme={defaultTheme}
|
|
22
|
-
enableSystem
|
|
23
|
-
disableTransitionOnChange
|
|
24
|
-
storageKey={`${packageName}-theme`}
|
|
25
|
-
>
|
|
26
|
-
<DLLProvider>
|
|
27
|
-
<AppThemeProvider themeColor={themeColor}>
|
|
28
|
-
{children}
|
|
29
|
-
<Toaster />
|
|
30
|
-
</AppThemeProvider>
|
|
31
|
-
</DLLProvider>
|
|
32
|
-
</ThemeProvider>
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from 'next-themes'
|
|
4
|
+
import { Toaster } from '@digilogiclabs/saas-factory-ui'
|
|
5
|
+
|
|
6
|
+
interface AppProvidersProps {
|
|
7
|
+
children: React.ReactNode
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
+
return (
|
|
12
|
+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
|
|
13
|
+
{children}
|
|
14
|
+
<Toaster />
|
|
15
|
+
</ThemeProvider>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
enableSystem
|
|
19
|
-
disableTransitionOnChange
|
|
20
|
-
storageKey="{{packageName}}-theme"
|
|
21
|
-
>
|
|
22
|
-
<DLLProvider>
|
|
23
|
-
<AppThemeProvider themeColor="{{themeColor}}">
|
|
24
|
-
{children}
|
|
25
|
-
<Toaster />
|
|
26
|
-
</AppThemeProvider>
|
|
27
|
-
</DLLProvider>
|
|
28
|
-
</ThemeProvider>
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
-
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from 'next-themes'
|
|
4
|
+
import { Toaster } from '@digilogiclabs/saas-factory-ui'
|
|
5
|
+
|
|
6
|
+
interface AppProvidersProps {
|
|
7
|
+
children: React.ReactNode
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
+
return (
|
|
12
|
+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
|
|
13
|
+
{children}
|
|
14
|
+
<Toaster />
|
|
15
|
+
</ThemeProvider>
|
|
16
|
+
)
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getClientIp } from '@digilogiclabs/platform-core/auth';
|
|
2
|
+
import type { AuditEvent, AuditCategory } from '@digilogiclabs/platform-core';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Observability helpers — audit logging, error reporting, metrics.
|
|
@@ -13,22 +14,11 @@ const SERVICE_NAME = 'my-app';
|
|
|
13
14
|
|
|
14
15
|
// ─── Lazy Singletons ────────────────────────────────────────
|
|
15
16
|
|
|
16
|
-
let auditLogPromise: Promise<AuditLogger> | null = null;
|
|
17
|
-
|
|
18
17
|
interface AuditLogger {
|
|
19
|
-
log(event: AuditEvent): Promise<
|
|
18
|
+
log(event: AuditEvent): Promise<unknown>;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
action: string;
|
|
24
|
-
actor: { id: string; type: string; email?: string };
|
|
25
|
-
resource?: { type: string; id?: string };
|
|
26
|
-
outcome: 'success' | 'failure' | 'blocked';
|
|
27
|
-
metadata?: Record<string, unknown>;
|
|
28
|
-
category?: string;
|
|
29
|
-
ip?: string;
|
|
30
|
-
userAgent?: string;
|
|
31
|
-
}
|
|
21
|
+
let auditLogPromise: Promise<AuditLogger> | null = null;
|
|
32
22
|
|
|
33
23
|
async function getAuditLog(): Promise<AuditLogger> {
|
|
34
24
|
if (!auditLogPromise) {
|
|
@@ -37,7 +27,7 @@ async function getAuditLog(): Promise<AuditLogger> {
|
|
|
37
27
|
const { getPlatform } = await import('@/lib/platform');
|
|
38
28
|
const platform = await getPlatform();
|
|
39
29
|
const { DatabaseAuditLog } = await import('@digilogiclabs/platform-core');
|
|
40
|
-
return new DatabaseAuditLog(platform.db,
|
|
30
|
+
return new DatabaseAuditLog({ database: platform.db, serviceName: SERVICE_NAME });
|
|
41
31
|
} catch {
|
|
42
32
|
return {
|
|
43
33
|
log: async (event: AuditEvent) => {
|
|
@@ -67,7 +57,7 @@ export function auditAction(params: {
|
|
|
67
57
|
actorEmail?: string;
|
|
68
58
|
resourceType?: string;
|
|
69
59
|
resourceId?: string;
|
|
70
|
-
outcome?: 'success' | 'failure' | '
|
|
60
|
+
outcome?: 'success' | 'failure' | 'denied' | 'error';
|
|
71
61
|
metadata?: Record<string, unknown>;
|
|
72
62
|
request?: Request;
|
|
73
63
|
}): void {
|
|
@@ -81,14 +71,16 @@ export function auditAction(params: {
|
|
|
81
71
|
type: params.actorId === 'system' ? 'system' : 'user',
|
|
82
72
|
email: params.actorEmail,
|
|
83
73
|
},
|
|
84
|
-
|
|
74
|
+
target: params.resourceType
|
|
85
75
|
? { type: params.resourceType, id: params.resourceId }
|
|
86
76
|
: undefined,
|
|
87
77
|
outcome: params.outcome || 'success',
|
|
88
|
-
|
|
78
|
+
data: {
|
|
79
|
+
...params.metadata,
|
|
80
|
+
ip: params.request ? getClientIp(params.request) : undefined,
|
|
81
|
+
userAgent: params.request ? getUserAgent(params.request) : undefined,
|
|
82
|
+
},
|
|
89
83
|
category,
|
|
90
|
-
ip: params.request ? getClientIp(params.request) : undefined,
|
|
91
|
-
userAgent: params.request ? getUserAgent(params.request) : undefined,
|
|
92
84
|
})
|
|
93
85
|
)
|
|
94
86
|
.catch(() => {});
|
|
@@ -124,12 +116,12 @@ export function captureError(error: unknown, context?: Record<string, unknown>):
|
|
|
124
116
|
|
|
125
117
|
// ─── Helpers ─────────────────────────────────────────────────
|
|
126
118
|
|
|
127
|
-
function inferCategory(action: string):
|
|
128
|
-
if (action.startsWith('admin.')) return '
|
|
119
|
+
function inferCategory(action: string): AuditCategory {
|
|
120
|
+
if (action.startsWith('admin.')) return 'admin_action';
|
|
129
121
|
if (action.startsWith('payment.')) return 'billing';
|
|
130
122
|
if (action.startsWith('account.')) return 'data_mutation';
|
|
131
123
|
if (action.startsWith('auth.')) return 'authentication';
|
|
132
124
|
if (action.startsWith('cron.')) return 'system';
|
|
133
125
|
if (action.startsWith('security.')) return 'security';
|
|
134
|
-
return '
|
|
126
|
+
return 'custom';
|
|
135
127
|
}
|
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import { ThemeProvider } from 'next-themes'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
interface AppProvidersProps {
|
|
7
|
-
children: React.ReactNode
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
-
return (
|
|
12
|
-
<ThemeProvider attribute="class" defaultTheme="
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
payments: {
|
|
19
|
-
provider: 'stripe',
|
|
20
|
-
},
|
|
21
|
-
}}
|
|
22
|
-
>
|
|
23
|
-
{children}
|
|
24
|
-
</DLLProvider>
|
|
25
|
-
</ThemeProvider>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { ThemeProvider } from 'next-themes'
|
|
4
|
+
import { Toaster } from '@digilogiclabs/saas-factory-ui'
|
|
5
|
+
|
|
6
|
+
interface AppProvidersProps {
|
|
7
|
+
children: React.ReactNode
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function AppProviders({ children }: AppProvidersProps) {
|
|
11
|
+
return (
|
|
12
|
+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
|
|
13
|
+
{children}
|
|
14
|
+
<Toaster />
|
|
15
|
+
</ThemeProvider>
|
|
16
|
+
)
|
|
17
|
+
}
|