@heliyos/heliyos-api-core 1.0.44 → 1.0.46

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.
@@ -0,0 +1,51 @@
1
+ export declare enum EventType {
2
+ AUDIT = "AUDIT",
3
+ INTERACTION = "INTERACTION"
4
+ }
5
+ export declare enum ActorType {
6
+ USER = "USER",
7
+ SYSTEM = "SYSTEM",
8
+ AGENT = "AGENT"
9
+ }
10
+ interface IActor {
11
+ type: ActorType;
12
+ uuid: string;
13
+ }
14
+ interface IEventMetadata {
15
+ eventType: EventType;
16
+ actor: IActor;
17
+ organizationUUID: string;
18
+ objectType: string;
19
+ objectUUID: string;
20
+ }
21
+ /**
22
+ * Creates a timestamped event log entry in the events collection
23
+ *
24
+ * @param metadata - Event metadata object containing:
25
+ * - eventType: Type of event (AUDIT/INTERACTION)
26
+ * - actor: Who performed the action (USER/SYSTEM/AGENT with their UUID)
27
+ * - organizationUUID: Organization identifier
28
+ * - objectType: Type of object being modified (e.g., 'User', 'Document')
29
+ * - objectUUID: Unique identifier of the modified object
30
+ * @param originalVersion - The state of the object before changes
31
+ * @param updatedVersion - The state of the object after changes
32
+ * @param changeSummary - Human-readable description of what changed
33
+ *
34
+ * @example
35
+ * await logEvent(
36
+ * {
37
+ * eventType: EventType.AUDIT,
38
+ * actor: { type: ActorType.USER, uuid: 'user-123e4567-e89b-12d3-a456-426614174000' },
39
+ * organizationUUID: '123e4567-e89b-12d3-a456-426614174000',
40
+ * objectType: 'User',
41
+ * objectUUID: '123e4567-e89b-12d3-a456-426614174000'
42
+ * },
43
+ * { name: 'John' },
44
+ * { name: 'John Doe' },
45
+ * 'Updated user name from John to John Doe'
46
+ * );
47
+ *
48
+ * @throws Will throw an error if the event creation fails
49
+ */
50
+ export declare function logEvent(metadata: IEventMetadata, originalVersion: any, updatedVersion: any, changeSummary: string): Promise<void>;
51
+ export {};
package/dist/events.js ADDED
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ActorType = exports.EventType = void 0;
13
+ exports.logEvent = logEvent;
14
+ const mongoose_1 = require("./mongoose");
15
+ const logger_1 = require("./logger");
16
+ // Define the event types and actor types
17
+ var EventType;
18
+ (function (EventType) {
19
+ EventType["AUDIT"] = "AUDIT";
20
+ EventType["INTERACTION"] = "INTERACTION";
21
+ })(EventType || (exports.EventType = EventType = {}));
22
+ var ActorType;
23
+ (function (ActorType) {
24
+ ActorType["USER"] = "USER";
25
+ ActorType["SYSTEM"] = "SYSTEM";
26
+ ActorType["AGENT"] = "AGENT";
27
+ })(ActorType || (exports.ActorType = ActorType = {}));
28
+ // Create the schema for events
29
+ const eventSchema = new mongoose_1.Schema({
30
+ timestamp: {
31
+ type: Date,
32
+ required: true,
33
+ index: true
34
+ },
35
+ metadata: {
36
+ eventType: {
37
+ type: String,
38
+ enum: Object.values(EventType),
39
+ required: true
40
+ },
41
+ actor: {
42
+ type: {
43
+ type: String,
44
+ enum: Object.values(ActorType),
45
+ required: true
46
+ },
47
+ uuid: {
48
+ type: String,
49
+ required: true
50
+ }
51
+ },
52
+ organizationUUID: {
53
+ type: String,
54
+ required: true,
55
+ index: true
56
+ },
57
+ objectType: {
58
+ type: String,
59
+ required: true,
60
+ index: true
61
+ },
62
+ objectUUID: {
63
+ type: String,
64
+ required: true,
65
+ index: true
66
+ }
67
+ },
68
+ originalVersion: {
69
+ type: mongoose_1.Schema.Types.Mixed,
70
+ required: true
71
+ },
72
+ updatedVersion: {
73
+ type: mongoose_1.Schema.Types.Mixed,
74
+ required: true
75
+ },
76
+ changeSummary: {
77
+ type: String,
78
+ required: true
79
+ }
80
+ }, {
81
+ collection: 'events',
82
+ timeseries: {
83
+ timeField: 'timestamp',
84
+ metaField: 'metadata',
85
+ granularity: 'seconds'
86
+ }
87
+ });
88
+ // Create the model
89
+ const Event = (0, mongoose_1.model)('events', eventSchema);
90
+ /**
91
+ * Creates a timestamped event log entry in the events collection
92
+ *
93
+ * @param metadata - Event metadata object containing:
94
+ * - eventType: Type of event (AUDIT/INTERACTION)
95
+ * - actor: Who performed the action (USER/SYSTEM/AGENT with their UUID)
96
+ * - organizationUUID: Organization identifier
97
+ * - objectType: Type of object being modified (e.g., 'User', 'Document')
98
+ * - objectUUID: Unique identifier of the modified object
99
+ * @param originalVersion - The state of the object before changes
100
+ * @param updatedVersion - The state of the object after changes
101
+ * @param changeSummary - Human-readable description of what changed
102
+ *
103
+ * @example
104
+ * await logEvent(
105
+ * {
106
+ * eventType: EventType.AUDIT,
107
+ * actor: { type: ActorType.USER, uuid: 'user-123e4567-e89b-12d3-a456-426614174000' },
108
+ * organizationUUID: '123e4567-e89b-12d3-a456-426614174000',
109
+ * objectType: 'User',
110
+ * objectUUID: '123e4567-e89b-12d3-a456-426614174000'
111
+ * },
112
+ * { name: 'John' },
113
+ * { name: 'John Doe' },
114
+ * 'Updated user name from John to John Doe'
115
+ * );
116
+ *
117
+ * @throws Will throw an error if the event creation fails
118
+ */
119
+ function logEvent(metadata, originalVersion, updatedVersion, changeSummary) {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ try {
122
+ yield Event.create({
123
+ timestamp: new Date(),
124
+ metadata,
125
+ originalVersion,
126
+ updatedVersion,
127
+ changeSummary
128
+ });
129
+ }
130
+ catch (error) {
131
+ logger_1.logger.error('Failed to create event log', {
132
+ error,
133
+ metadata,
134
+ changeSummary
135
+ });
136
+ throw error;
137
+ }
138
+ });
139
+ }
package/dist/index.d.ts CHANGED
@@ -19,3 +19,4 @@ export { HttpError } from "./@types/globals/customError";
19
19
  export type { ICoreAppOptions } from "./@types/globals/middleware";
20
20
  export type { RolesPermissionsType, ResourcePolicyActionsType, } from "./static/authPolicyFile";
21
21
  export { Schema, Document, Model, FilterQuery, UpdateQuery, Pagination, Types, mongooseConnection, mongoInstance, } from "./mongoose";
22
+ export { logEvent, EventType, ActorType } from './events';
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.mongoInstance = exports.mongooseConnection = exports.Types = exports.Model = exports.Document = exports.Schema = exports.HttpError = exports.getSecretsManagerSecret = exports.resendSendEmail = exports.pusherTriggerBatch = exports.pusherTrigger = exports.pusher = exports.emailTemplates = exports.getEmailTemplate = exports.allowedOrigin = exports.logger = exports.SQSUtil = exports.getRedisClient = exports.authorizeUser = exports.authPolicy = exports.loadAppEnv = exports.joiObject = exports.validate = exports.axios = exports.coreApp = exports.authentication = void 0;
26
+ exports.ActorType = exports.EventType = exports.logEvent = exports.mongoInstance = exports.mongooseConnection = exports.Types = exports.Model = exports.Document = exports.Schema = exports.HttpError = exports.getSecretsManagerSecret = exports.resendSendEmail = exports.pusherTriggerBatch = exports.pusherTrigger = exports.pusher = exports.emailTemplates = exports.getEmailTemplate = exports.allowedOrigin = exports.logger = exports.SQSUtil = exports.getRedisClient = exports.authorizeUser = exports.authPolicy = exports.loadAppEnv = exports.joiObject = exports.validate = exports.axios = exports.coreApp = exports.authentication = void 0;
27
27
  const dotenv = __importStar(require("dotenv"));
28
28
  dotenv.config();
29
29
  // Core exports
@@ -72,3 +72,7 @@ Object.defineProperty(exports, "Model", { enumerable: true, get: function () { r
72
72
  Object.defineProperty(exports, "Types", { enumerable: true, get: function () { return mongoose_1.Types; } });
73
73
  Object.defineProperty(exports, "mongooseConnection", { enumerable: true, get: function () { return mongoose_1.mongooseConnection; } });
74
74
  Object.defineProperty(exports, "mongoInstance", { enumerable: true, get: function () { return mongoose_1.mongoInstance; } });
75
+ var events_1 = require("./events");
76
+ Object.defineProperty(exports, "logEvent", { enumerable: true, get: function () { return events_1.logEvent; } });
77
+ Object.defineProperty(exports, "EventType", { enumerable: true, get: function () { return events_1.EventType; } });
78
+ Object.defineProperty(exports, "ActorType", { enumerable: true, get: function () { return events_1.ActorType; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heliyos/heliyos-api-core",
3
- "version": "1.0.44",
3
+ "version": "1.0.46",
4
4
  "description": "Heliyos's core api functions and middlewares. Its a private package hosted on npm.",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -40,7 +40,7 @@
40
40
  "helmet": "^8.0.0",
41
41
  "http": "0.0.1-security",
42
42
  "joi": "^17.13.3",
43
- "mongoose": "8.8.0",
43
+ "mongoose": "8.9.5",
44
44
  "morgan": "1.10.0",
45
45
  "pusher": "5.2.0",
46
46
  "redis": "4.7.0",