alepha 0.13.5 → 0.13.7

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 (136) hide show
  1. package/dist/api-audits/index.browser.js +116 -0
  2. package/dist/api-audits/index.browser.js.map +1 -0
  3. package/dist/api-audits/index.d.ts +1194 -0
  4. package/dist/api-audits/index.js +674 -0
  5. package/dist/api-audits/index.js.map +1 -0
  6. package/dist/api-notifications/index.d.ts +147 -147
  7. package/dist/api-parameters/index.browser.js +36 -5
  8. package/dist/api-parameters/index.browser.js.map +1 -1
  9. package/dist/api-parameters/index.d.ts +711 -33
  10. package/dist/api-parameters/index.js +831 -17
  11. package/dist/api-parameters/index.js.map +1 -1
  12. package/dist/api-users/index.d.ts +16 -3
  13. package/dist/api-users/index.js +699 -19
  14. package/dist/api-users/index.js.map +1 -1
  15. package/dist/api-verifications/index.js +2 -1
  16. package/dist/api-verifications/index.js.map +1 -1
  17. package/dist/bin/index.js +1 -0
  18. package/dist/bin/index.js.map +1 -1
  19. package/dist/cli/index.d.ts +85 -31
  20. package/dist/cli/index.js +205 -33
  21. package/dist/cli/index.js.map +1 -1
  22. package/dist/command/index.d.ts +67 -6
  23. package/dist/command/index.js +30 -3
  24. package/dist/command/index.js.map +1 -1
  25. package/dist/core/index.browser.js +241 -61
  26. package/dist/core/index.browser.js.map +1 -1
  27. package/dist/core/index.d.ts +170 -90
  28. package/dist/core/index.js +264 -67
  29. package/dist/core/index.js.map +1 -1
  30. package/dist/core/index.native.js +248 -65
  31. package/dist/core/index.native.js.map +1 -1
  32. package/dist/email/index.js +15 -10554
  33. package/dist/email/index.js.map +1 -1
  34. package/dist/logger/index.d.ts +4 -4
  35. package/dist/logger/index.js +77 -72
  36. package/dist/logger/index.js.map +1 -1
  37. package/dist/orm/index.d.ts +5 -1
  38. package/dist/orm/index.js +24 -7
  39. package/dist/orm/index.js.map +1 -1
  40. package/dist/queue/index.d.ts +4 -4
  41. package/dist/redis/index.d.ts +10 -10
  42. package/dist/security/index.d.ts +28 -28
  43. package/dist/server/index.d.ts +10 -1
  44. package/dist/server/index.js +20 -6
  45. package/dist/server/index.js.map +1 -1
  46. package/dist/server-auth/index.d.ts +163 -152
  47. package/dist/server-auth/index.js +40 -10
  48. package/dist/server-auth/index.js.map +1 -1
  49. package/dist/server-cookies/index.js +5 -1
  50. package/dist/server-cookies/index.js.map +1 -1
  51. package/dist/server-links/index.d.ts +33 -33
  52. package/dist/server-security/index.d.ts +9 -9
  53. package/dist/thread/index.js +2 -2
  54. package/dist/thread/index.js.map +1 -1
  55. package/dist/vite/index.d.ts +2 -2
  56. package/dist/vite/index.js +102 -45
  57. package/dist/vite/index.js.map +1 -1
  58. package/dist/websocket/index.browser.js +3 -3
  59. package/dist/websocket/index.browser.js.map +1 -1
  60. package/dist/websocket/index.d.ts +7 -7
  61. package/dist/websocket/index.js +4 -4
  62. package/dist/websocket/index.js.map +1 -1
  63. package/package.json +14 -9
  64. package/src/api-audits/controllers/AuditController.ts +186 -0
  65. package/src/api-audits/entities/audits.ts +132 -0
  66. package/src/api-audits/index.browser.ts +18 -0
  67. package/src/api-audits/index.ts +58 -0
  68. package/src/api-audits/primitives/$audit.ts +159 -0
  69. package/src/api-audits/schemas/auditQuerySchema.ts +23 -0
  70. package/src/api-audits/schemas/auditResourceSchema.ts +9 -0
  71. package/src/api-audits/schemas/createAuditSchema.ts +27 -0
  72. package/src/api-audits/services/AuditService.ts +412 -0
  73. package/src/api-parameters/controllers/ConfigController.ts +324 -0
  74. package/src/api-parameters/entities/parameters.ts +93 -10
  75. package/src/api-parameters/index.ts +43 -4
  76. package/src/api-parameters/primitives/$config.ts +291 -19
  77. package/src/api-parameters/schedulers/ConfigActivationScheduler.ts +30 -0
  78. package/src/api-parameters/services/ConfigStore.ts +491 -0
  79. package/src/api-users/atoms/realmAuthSettingsAtom.ts +19 -0
  80. package/src/api-users/controllers/UserRealmController.ts +0 -2
  81. package/src/api-users/index.ts +2 -0
  82. package/src/api-users/primitives/$userRealm.ts +18 -3
  83. package/src/api-users/providers/UserRealmProvider.ts +6 -3
  84. package/src/api-users/services/RegistrationService.ts +2 -1
  85. package/src/api-users/services/SessionService.ts +4 -0
  86. package/src/api-users/services/UserService.ts +3 -0
  87. package/src/api-verifications/index.ts +7 -1
  88. package/src/bin/index.ts +1 -0
  89. package/src/cli/assets/biomeJson.ts +1 -1
  90. package/src/cli/assets/dummySpecTs.ts +7 -0
  91. package/src/cli/assets/editorconfig.ts +13 -0
  92. package/src/cli/assets/mainTs.ts +14 -0
  93. package/src/cli/commands/BiomeCommands.ts +2 -0
  94. package/src/cli/commands/CoreCommands.ts +28 -9
  95. package/src/cli/commands/VerifyCommands.ts +2 -1
  96. package/src/cli/commands/ViteCommands.ts +8 -9
  97. package/src/cli/services/AlephaCliUtils.ts +214 -23
  98. package/src/command/helpers/Asker.ts +0 -1
  99. package/src/command/primitives/$command.ts +67 -0
  100. package/src/command/providers/CliProvider.ts +39 -8
  101. package/src/core/Alepha.ts +40 -30
  102. package/src/core/helpers/jsonSchemaToTypeBox.ts +307 -0
  103. package/src/core/index.shared.ts +1 -0
  104. package/src/core/index.ts +30 -3
  105. package/src/core/providers/EventManager.ts +1 -1
  106. package/src/core/providers/StateManager.ts +23 -12
  107. package/src/core/providers/TypeProvider.ts +26 -34
  108. package/src/logger/index.ts +8 -6
  109. package/src/logger/primitives/$logger.ts +1 -1
  110. package/src/logger/providers/{SimpleFormatterProvider.ts → PrettyFormatterProvider.ts} +10 -1
  111. package/src/orm/index.ts +6 -0
  112. package/src/orm/services/PgRelationManager.ts +2 -2
  113. package/src/orm/services/PostgresModelBuilder.ts +11 -7
  114. package/src/orm/services/Repository.ts +16 -7
  115. package/src/orm/services/SqliteModelBuilder.ts +10 -0
  116. package/src/server/index.ts +6 -0
  117. package/src/server/primitives/$action.ts +10 -1
  118. package/src/server/providers/ServerBodyParserProvider.ts +11 -5
  119. package/src/server/providers/ServerRouterProvider.ts +13 -7
  120. package/src/server-auth/primitives/$auth.ts +7 -0
  121. package/src/server-auth/providers/ServerAuthProvider.ts +51 -8
  122. package/src/server-cookies/index.ts +2 -1
  123. package/src/thread/primitives/$thread.ts +2 -2
  124. package/src/vite/index.ts +0 -2
  125. package/src/vite/tasks/buildServer.ts +3 -4
  126. package/src/vite/tasks/generateCloudflare.ts +35 -19
  127. package/src/vite/tasks/generateDocker.ts +18 -4
  128. package/src/vite/tasks/generateSitemap.ts +5 -7
  129. package/src/vite/tasks/generateVercel.ts +76 -41
  130. package/src/vite/tasks/runAlepha.ts +16 -1
  131. package/src/websocket/providers/NodeWebSocketServerProvider.ts +3 -11
  132. package/src/websocket/services/WebSocketClient.ts +3 -3
  133. package/dist/cli/dist-BlfFtOk2.js +0 -2770
  134. package/dist/cli/dist-BlfFtOk2.js.map +0 -1
  135. package/src/api-parameters/controllers/ParameterController.ts +0 -45
  136. package/src/api-parameters/services/ParameterStore.ts +0 -23
@@ -0,0 +1,132 @@
1
+ import type { Static } from "alepha";
2
+ import { t } from "alepha";
3
+ import { $entity, pg } from "alepha/orm";
4
+
5
+ /**
6
+ * Audit severity levels for categorizing events.
7
+ */
8
+ export const auditSeveritySchema = t.enum(["info", "warning", "critical"], {
9
+ default: "info",
10
+ description: "Severity level of the audit event",
11
+ });
12
+
13
+ export type AuditSeverity = Static<typeof auditSeveritySchema>;
14
+
15
+ /**
16
+ * Audit log entity for tracking important system events.
17
+ *
18
+ * Stores comprehensive audit information including:
19
+ * - Who performed the action (userId, userRealm)
20
+ * - What happened (type, action, resource)
21
+ * - When it happened (createdAt)
22
+ * - Context and details (metadata, ipAddress, userAgent)
23
+ */
24
+ export const audits = $entity({
25
+ name: "audits",
26
+ schema: t.object({
27
+ id: pg.primaryKey(t.bigint()),
28
+ createdAt: pg.createdAt(),
29
+
30
+ /**
31
+ * Audit event type (e.g., "auth", "user", "payment", "system").
32
+ * Used for categorizing and filtering audit events.
33
+ */
34
+ type: t.text({
35
+ description: "Audit event type (e.g., auth, user, payment, system)",
36
+ }),
37
+
38
+ /**
39
+ * Specific action performed (e.g., "login", "logout", "create", "update", "delete").
40
+ */
41
+ action: t.text({
42
+ description: "Specific action performed (e.g., login, create, update)",
43
+ }),
44
+
45
+ /**
46
+ * Severity level of the event.
47
+ */
48
+ severity: pg.default(auditSeveritySchema, "info"),
49
+
50
+ /**
51
+ * User ID who performed the action (null for system events).
52
+ */
53
+ userId: t.optional(t.uuid()),
54
+
55
+ /**
56
+ * User realm for multi-tenant support.
57
+ */
58
+ userRealm: t.optional(t.text()),
59
+
60
+ /**
61
+ * User email at the time of the event (denormalized for history).
62
+ */
63
+ userEmail: t.optional(t.email()),
64
+
65
+ /**
66
+ * Resource type affected (e.g., "user", "order", "file").
67
+ */
68
+ resourceType: t.optional(t.text()),
69
+
70
+ /**
71
+ * Resource ID affected.
72
+ */
73
+ resourceId: t.optional(t.text()),
74
+
75
+ /**
76
+ * Human-readable description of the event.
77
+ */
78
+ description: t.optional(t.text()),
79
+
80
+ /**
81
+ * Additional metadata/context as JSON.
82
+ */
83
+ metadata: t.optional(t.json()),
84
+
85
+ /**
86
+ * Client IP address.
87
+ */
88
+ ipAddress: t.optional(t.text()),
89
+
90
+ /**
91
+ * Client user agent.
92
+ */
93
+ userAgent: t.optional(t.text()),
94
+
95
+ /**
96
+ * Session ID if applicable.
97
+ */
98
+ sessionId: t.optional(t.uuid()),
99
+
100
+ /**
101
+ * Request ID for correlation.
102
+ */
103
+ requestId: t.optional(t.text()),
104
+
105
+ /**
106
+ * Whether the action was successful.
107
+ */
108
+ success: pg.default(t.boolean(), true),
109
+
110
+ /**
111
+ * Error message if the action failed.
112
+ */
113
+ errorMessage: t.optional(t.text()),
114
+ }),
115
+ indexes: [
116
+ "createdAt",
117
+ "type",
118
+ "action",
119
+ "userId",
120
+ "userRealm",
121
+ "resourceType",
122
+ "resourceId",
123
+ "severity",
124
+ { columns: ["type", "action"] },
125
+ { columns: ["userId", "createdAt"] },
126
+ { columns: ["userRealm", "createdAt"] },
127
+ ],
128
+ });
129
+
130
+ export const auditEntitySchema = audits.schema;
131
+ export const auditEntityInsertSchema = audits.insertSchema;
132
+ export type AuditEntity = Static<typeof audits.schema>;
@@ -0,0 +1,18 @@
1
+ // Browser exports for api-audits module
2
+ // Only exports types and schemas that are safe for browser usage
3
+
4
+ export type { AuditController } from "./controllers/AuditController.ts";
5
+ export * from "./entities/audits.ts";
6
+ export type {
7
+ AuditLogOptions,
8
+ AuditPrimitive,
9
+ AuditPrimitiveOptions,
10
+ } from "./primitives/$audit.ts";
11
+ export * from "./schemas/auditQuerySchema.ts";
12
+ export * from "./schemas/auditResourceSchema.ts";
13
+ export * from "./schemas/createAuditSchema.ts";
14
+ export type {
15
+ AuditService,
16
+ AuditStats,
17
+ AuditTypeDefinition,
18
+ } from "./services/AuditService.ts";
@@ -0,0 +1,58 @@
1
+ import { $module } from "alepha";
2
+ import { AuditController } from "./controllers/AuditController.ts";
3
+ import { AuditService } from "./services/AuditService.ts";
4
+
5
+ // ---------------------------------------------------------------------------------------------------------------------
6
+
7
+ export * from "./controllers/AuditController.ts";
8
+ export * from "./entities/audits.ts";
9
+ export * from "./primitives/$audit.ts";
10
+ export * from "./schemas/auditQuerySchema.ts";
11
+ export * from "./schemas/auditResourceSchema.ts";
12
+ export * from "./schemas/createAuditSchema.ts";
13
+ export * from "./services/AuditService.ts";
14
+
15
+ // ---------------------------------------------------------------------------------------------------------------------
16
+
17
+ /**
18
+ * Provides audit logging API endpoints for Alepha applications.
19
+ *
20
+ * This module includes:
21
+ * - Audit log CRUD operations
22
+ * - Filtering and searching audit events
23
+ * - Audit statistics and analytics
24
+ * - `$audit` primitive for domain-specific audit types
25
+ *
26
+ * @module alepha.api.audits
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * // In your app module
31
+ * import { AlephaApiAudits } from "alepha/api/audits";
32
+ *
33
+ * const App = $module({
34
+ * name: "app",
35
+ * services: [AlephaApiAudits, ...],
36
+ * });
37
+ *
38
+ * // Create domain-specific audit types
39
+ * class PaymentAudits {
40
+ * audit = $audit({
41
+ * type: "payment",
42
+ * actions: ["create", "refund", "cancel"],
43
+ * });
44
+ *
45
+ * async onPaymentCreated(paymentId: string, userId: string) {
46
+ * await this.audit.log("create", {
47
+ * userId,
48
+ * resourceType: "payment",
49
+ * resourceId: paymentId,
50
+ * });
51
+ * }
52
+ * }
53
+ * ```
54
+ */
55
+ export const AlephaApiAudits = $module({
56
+ name: "alepha.api.audits",
57
+ services: [AuditService, AuditController],
58
+ });
@@ -0,0 +1,159 @@
1
+ import { $inject, createPrimitive, KIND, Primitive } from "alepha";
2
+ import {
3
+ AuditService,
4
+ type AuditTypeDefinition,
5
+ } from "../services/AuditService.ts";
6
+
7
+ /**
8
+ * Options for creating an audit type primitive.
9
+ */
10
+ export interface AuditPrimitiveOptions {
11
+ /**
12
+ * Unique audit type identifier (e.g., "auth", "payment", "order").
13
+ */
14
+ type: string;
15
+
16
+ /**
17
+ * Human-readable description of this audit type.
18
+ */
19
+ description?: string;
20
+
21
+ /**
22
+ * List of allowed actions for this audit type.
23
+ */
24
+ actions: string[];
25
+ }
26
+
27
+ /**
28
+ * Audit type primitive for registering domain-specific audit events.
29
+ *
30
+ * Provides a type-safe way to define and log audit events within a specific domain.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * class PaymentAudits {
35
+ * audit = $audit({
36
+ * type: "payment",
37
+ * description: "Payment-related audit events",
38
+ * actions: ["create", "refund", "cancel", "dispute"],
39
+ * });
40
+ *
41
+ * async logPaymentCreated(paymentId: string, userId: string, amount: number) {
42
+ * await this.audit.log("create", {
43
+ * userId,
44
+ * resourceType: "payment",
45
+ * resourceId: paymentId,
46
+ * description: `Payment of ${amount} created`,
47
+ * metadata: { amount },
48
+ * });
49
+ * }
50
+ * }
51
+ * ```
52
+ */
53
+ export class AuditPrimitive extends Primitive<AuditPrimitiveOptions> {
54
+ protected readonly auditService = $inject(AuditService);
55
+
56
+ /**
57
+ * The audit type identifier.
58
+ */
59
+ public get type(): string {
60
+ return this.options.type;
61
+ }
62
+
63
+ /**
64
+ * The audit type description.
65
+ */
66
+ public get description(): string | undefined {
67
+ return this.options.description;
68
+ }
69
+
70
+ /**
71
+ * The allowed actions for this audit type.
72
+ */
73
+ public get actions(): string[] {
74
+ return this.options.actions;
75
+ }
76
+
77
+ /**
78
+ * Log an audit event for this type.
79
+ */
80
+ public async log(
81
+ action: string,
82
+ options: AuditLogOptions = {},
83
+ ): Promise<void> {
84
+ await this.auditService.record(this.options.type, action, options);
85
+ }
86
+
87
+ /**
88
+ * Log a successful audit event.
89
+ */
90
+ public async logSuccess(
91
+ action: string,
92
+ options: Omit<AuditLogOptions, "success"> = {},
93
+ ): Promise<void> {
94
+ await this.log(action, { ...options, success: true });
95
+ }
96
+
97
+ /**
98
+ * Log a failed audit event.
99
+ */
100
+ public async logFailure(
101
+ action: string,
102
+ errorMessage: string,
103
+ options: Omit<AuditLogOptions, "success" | "errorMessage"> = {},
104
+ ): Promise<void> {
105
+ await this.log(action, { ...options, success: false, errorMessage });
106
+ }
107
+
108
+ /**
109
+ * Called during initialization to register this audit type.
110
+ */
111
+ protected onInit(): void {
112
+ const definition: AuditTypeDefinition = {
113
+ type: this.options.type,
114
+ description: this.options.description,
115
+ actions: this.options.actions,
116
+ };
117
+ this.auditService.registerType(definition);
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Options for logging an audit event.
123
+ */
124
+ export interface AuditLogOptions {
125
+ severity?: "info" | "warning" | "critical";
126
+ userId?: string;
127
+ userRealm?: string;
128
+ userEmail?: string;
129
+ resourceType?: string;
130
+ resourceId?: string;
131
+ description?: string;
132
+ metadata?: Record<string, unknown>;
133
+ ipAddress?: string;
134
+ userAgent?: string;
135
+ sessionId?: string;
136
+ requestId?: string;
137
+ success?: boolean;
138
+ errorMessage?: string;
139
+ }
140
+
141
+ /**
142
+ * Create an audit type primitive.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * class OrderAudits {
147
+ * audit = $audit({
148
+ * type: "order",
149
+ * description: "Order management events",
150
+ * actions: ["create", "update", "cancel", "fulfill", "ship"],
151
+ * });
152
+ * }
153
+ * ```
154
+ */
155
+ export const $audit = (options: AuditPrimitiveOptions) => {
156
+ return createPrimitive(AuditPrimitive, options);
157
+ };
158
+
159
+ $audit[KIND] = AuditPrimitive;
@@ -0,0 +1,23 @@
1
+ import type { Static } from "alepha";
2
+ import { t } from "alepha";
3
+ import { pageQuerySchema } from "alepha/orm";
4
+ import { auditSeveritySchema } from "../entities/audits.ts";
5
+
6
+ /**
7
+ * Query schema for searching and filtering audit logs.
8
+ */
9
+ export const auditQuerySchema = t.extend(pageQuerySchema, {
10
+ type: t.optional(t.text({ description: "Filter by audit type" })),
11
+ action: t.optional(t.text({ description: "Filter by action" })),
12
+ severity: t.optional(auditSeveritySchema),
13
+ userId: t.optional(t.uuid({ description: "Filter by user ID" })),
14
+ userRealm: t.optional(t.text({ description: "Filter by user realm" })),
15
+ resourceType: t.optional(t.text({ description: "Filter by resource type" })),
16
+ resourceId: t.optional(t.text({ description: "Filter by resource ID" })),
17
+ success: t.optional(t.boolean({ description: "Filter by success status" })),
18
+ from: t.optional(t.datetime({ description: "Start date filter" })),
19
+ to: t.optional(t.datetime({ description: "End date filter" })),
20
+ search: t.optional(t.text({ description: "Search in description" })),
21
+ });
22
+
23
+ export type AuditQuery = Static<typeof auditQuerySchema>;
@@ -0,0 +1,9 @@
1
+ import type { Static } from "alepha";
2
+ import { audits } from "../entities/audits.ts";
3
+
4
+ /**
5
+ * Resource schema for audit log responses.
6
+ */
7
+ export const auditResourceSchema = audits.schema;
8
+
9
+ export type AuditResource = Static<typeof auditResourceSchema>;
@@ -0,0 +1,27 @@
1
+ import type { Static } from "alepha";
2
+ import { t } from "alepha";
3
+ import { auditSeveritySchema } from "../entities/audits.ts";
4
+
5
+ /**
6
+ * Schema for creating a new audit log entry.
7
+ */
8
+ export const createAuditSchema = t.object({
9
+ type: t.text({ description: "Audit event type" }),
10
+ action: t.text({ description: "Specific action performed" }),
11
+ severity: t.optional(auditSeveritySchema),
12
+ userId: t.optional(t.uuid()),
13
+ userRealm: t.optional(t.text()),
14
+ userEmail: t.optional(t.email()),
15
+ resourceType: t.optional(t.text()),
16
+ resourceId: t.optional(t.text()),
17
+ description: t.optional(t.text()),
18
+ metadata: t.optional(t.json()),
19
+ ipAddress: t.optional(t.text()),
20
+ userAgent: t.optional(t.text()),
21
+ sessionId: t.optional(t.uuid()),
22
+ requestId: t.optional(t.text()),
23
+ success: t.optional(t.boolean()),
24
+ errorMessage: t.optional(t.text()),
25
+ });
26
+
27
+ export type CreateAudit = Static<typeof createAuditSchema>;