@zeeshan60/event-processor 1.0.1 → 1.0.2

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.
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserConvertedToPlaceholder = exports.PlaceholderUserMerged = exports.UserDeleted = exports.UserDisplayNameChanged = exports.UserPhoneNumberChanged = exports.UserCurrencyChanged = exports.PlaceholderUserCreated = exports.UserCreated = exports.UserEventType = void 0;
4
+ const ActivityLogEvents_1 = require("./ActivityLogEvents");
5
+ const uuid_1 = require("uuid");
4
6
  // User Event Types
5
7
  var UserEventType;
6
8
  (function (UserEventType) {
@@ -28,8 +30,10 @@ class UserCreated {
28
30
  this.version = props.version;
29
31
  }
30
32
  apply(_existing) {
33
+ if (!this.userId) {
34
+ throw new Error('userId is required for UserModel');
35
+ }
31
36
  return {
32
- id: null,
33
37
  streamId: this.streamId,
34
38
  userId: this.userId,
35
39
  uid: this.firebaseUid,
@@ -37,7 +41,7 @@ class UserCreated {
37
41
  phoneNumber: this.phoneNumber,
38
42
  email: this.email,
39
43
  photoUrl: this.photoUrl,
40
- currency: null,
44
+ currency: undefined,
41
45
  emailVerified: this.emailVerified,
42
46
  isPlaceholder: false,
43
47
  createdAt: this.createdAt,
@@ -48,6 +52,26 @@ class UserCreated {
48
52
  deleted: false,
49
53
  };
50
54
  }
55
+ activityLog(_existing, actorName) {
56
+ if (!this.userId) {
57
+ return undefined;
58
+ }
59
+ const actor = actorName ?? 'You';
60
+ const possessive = actor === 'You' ? 'your' : `${actor}'s`;
61
+ const logMessage = `${actor} created ${possessive} profile as "${this.displayName}"`;
62
+ return {
63
+ userId: this.userId,
64
+ activityByUid: this.createdBy,
65
+ sourceStreamId: this.streamId,
66
+ sourceType: ActivityLogEvents_1.SourceType.User,
67
+ logMessage,
68
+ date: this.createdAt,
69
+ createdAt: this.createdAt,
70
+ createdBy: this.createdBy,
71
+ streamId: (0, uuid_1.v4)(),
72
+ version: 1,
73
+ };
74
+ }
51
75
  }
52
76
  exports.UserCreated = UserCreated;
53
77
  class PlaceholderUserCreated {
@@ -62,16 +86,18 @@ class PlaceholderUserCreated {
62
86
  this.version = props.version;
63
87
  }
64
88
  apply(_existing) {
89
+ if (!this.userId) {
90
+ throw new Error('userId is required for UserModel');
91
+ }
65
92
  return {
66
- id: null,
67
93
  streamId: this.streamId,
68
94
  userId: this.userId,
69
- uid: null,
95
+ uid: undefined,
70
96
  displayName: this.displayName,
71
97
  phoneNumber: this.phoneNumber,
72
98
  email: this.email,
73
- photoUrl: null,
74
- currency: null,
99
+ photoUrl: undefined,
100
+ currency: undefined,
75
101
  emailVerified: false,
76
102
  isPlaceholder: true,
77
103
  createdAt: this.createdAt,
@@ -106,6 +132,29 @@ class UserCurrencyChanged {
106
132
  version: this.version,
107
133
  };
108
134
  }
135
+ activityLog(existing, actorName) {
136
+ if (!existing) {
137
+ return undefined;
138
+ }
139
+ const existingUser = existing;
140
+ const actor = actorName ?? 'You';
141
+ const possessive = actor === 'You' ? 'your' : `${actor}'s`;
142
+ const oldValue = existingUser.currency ?? '';
143
+ const newValue = this.currency ?? '';
144
+ const logMessage = `${actor} changed ${possessive} currency from ${oldValue} to ${newValue}`;
145
+ return {
146
+ userId: existingUser.userId,
147
+ activityByUid: this.createdBy,
148
+ sourceStreamId: this.streamId,
149
+ sourceType: ActivityLogEvents_1.SourceType.User,
150
+ logMessage,
151
+ date: this.createdAt,
152
+ createdAt: this.createdAt,
153
+ createdBy: this.createdBy,
154
+ streamId: (0, uuid_1.v4)(),
155
+ version: 1,
156
+ };
157
+ }
109
158
  }
110
159
  exports.UserCurrencyChanged = UserCurrencyChanged;
111
160
  class UserPhoneNumberChanged {
@@ -130,6 +179,36 @@ class UserPhoneNumberChanged {
130
179
  version: this.version,
131
180
  };
132
181
  }
182
+ activityLog(existing, actorName) {
183
+ if (!existing) {
184
+ return undefined;
185
+ }
186
+ const existingUser = existing;
187
+ const actor = actorName ?? 'You';
188
+ const possessive = actor === 'You' ? 'your' : `${actor}'s`;
189
+ let logMessage;
190
+ if (existingUser.phoneNumber && this.phoneNumber) {
191
+ logMessage = `${actor} changed ${possessive} phone number from ${existingUser.phoneNumber} to ${this.phoneNumber}`;
192
+ }
193
+ else if (this.phoneNumber) {
194
+ logMessage = `${actor} added ${possessive} phone number ${this.phoneNumber}`;
195
+ }
196
+ else {
197
+ logMessage = `${actor} removed ${possessive} phone number`;
198
+ }
199
+ return {
200
+ userId: existingUser.userId,
201
+ activityByUid: this.createdBy,
202
+ sourceStreamId: this.streamId,
203
+ sourceType: ActivityLogEvents_1.SourceType.User,
204
+ logMessage,
205
+ date: this.createdAt,
206
+ createdAt: this.createdAt,
207
+ createdBy: this.createdBy,
208
+ streamId: (0, uuid_1.v4)(),
209
+ version: 1,
210
+ };
211
+ }
133
212
  }
134
213
  exports.UserPhoneNumberChanged = UserPhoneNumberChanged;
135
214
  class UserDisplayNameChanged {
@@ -154,6 +233,27 @@ class UserDisplayNameChanged {
154
233
  version: this.version,
155
234
  };
156
235
  }
236
+ activityLog(existing, actorName) {
237
+ if (!existing) {
238
+ return undefined;
239
+ }
240
+ const existingUser = existing;
241
+ const actor = actorName ?? 'You';
242
+ const possessive = actor === 'You' ? 'your' : `${actor}'s`;
243
+ const logMessage = `${actor} changed ${possessive} name from "${existingUser.displayName}" to "${this.displayName}"`;
244
+ return {
245
+ userId: existingUser.userId,
246
+ activityByUid: this.createdBy,
247
+ sourceStreamId: this.streamId,
248
+ sourceType: ActivityLogEvents_1.SourceType.User,
249
+ logMessage,
250
+ date: this.createdAt,
251
+ createdAt: this.createdAt,
252
+ createdBy: this.createdBy,
253
+ streamId: (0, uuid_1.v4)(),
254
+ version: 1,
255
+ };
256
+ }
157
257
  }
158
258
  exports.UserDisplayNameChanged = UserDisplayNameChanged;
159
259
  class UserDeleted {
@@ -235,9 +335,9 @@ class UserConvertedToPlaceholder {
235
335
  }
236
336
  return {
237
337
  ...existingUser,
238
- uid: null,
338
+ uid: undefined,
239
339
  isPlaceholder: true,
240
- photoUrl: null,
340
+ photoUrl: undefined,
241
341
  emailVerified: false,
242
342
  updatedAt: this.createdAt,
243
343
  updatedBy: this.createdBy,
@@ -1,10 +1,11 @@
1
1
  import { Model } from './Model';
2
+ import { ActivityLogCreatedProps } from '../ActivityLogEvents';
2
3
  export interface Event {
3
- userId: string;
4
4
  streamId: string;
5
5
  version: number;
6
6
  createdAt: Date;
7
7
  createdBy: string;
8
- apply(existing: Model | null): Model;
8
+ apply(existing?: Model): Model;
9
+ activityLog?(existingModel?: Model, actorName?: string): ActivityLogCreatedProps | undefined;
9
10
  }
10
11
  //# sourceMappingURL=Event.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Event.d.ts","sourceRoot":"","sources":["../../src/common/Event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,WAAW,KAAK;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,QAAQ,EAAE,KAAK,GAAG,IAAI,GAAG,KAAK,CAAC;CACtC"}
1
+ {"version":3,"file":"Event.d.ts","sourceRoot":"","sources":["../../src/common/Event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,MAAM,WAAW,KAAK;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAC/B,WAAW,CAAC,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,uBAAuB,GAAG,SAAS,CAAC;CAC9F"}
@@ -1,5 +1,4 @@
1
1
  export interface Model {
2
- id: string | null;
3
2
  userId: string;
4
3
  streamId: string;
5
4
  version: number;
@@ -1 +1 @@
1
- {"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../src/common/Model.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB"}
1
+ {"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../src/common/Model.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { Event } from './common/Event';
2
2
  export { Model } from './common/Model';
3
- export { TransactionCreated, TransactionCreatedProps, TransactionDeleted, TransactionDeletedProps, DescriptionChanged, DescriptionChangedProps, TotalAmountChanged, TotalAmountChangedProps, TransactionModel, SplitType, TransactionEventType, TransactionChangeType, ActivityType, ActivityLog, ChangeSummary, AmountDto, ChangeHistory, ChangeHistoryItem, DescriptionUpdated, AmountUpdated, CurrencyUpdated, SplitTypeUpdated, TransactionDateUpdated, } from './TransactionEvents';
3
+ export { TransactionCreated, TransactionCreatedProps, TransactionDeleted, TransactionDeletedProps, DescriptionChanged, DescriptionChangedProps, TotalAmountChanged, TotalAmountChangedProps, SplitTypeChanged, SplitTypeChangedProps, CurrencyChanged, CurrencyChangedProps, TransactionDateChanged, TransactionDateChangedProps, TransactionModel, SplitType, TransactionEventType, AmountDto, ChangeHistory, ChangeHistoryItem, DescriptionUpdated, AmountUpdated, CurrencyUpdated, SplitTypeUpdated, TransactionDateUpdated, } from './TransactionEvents';
4
4
  export { UserCreated, UserCreatedProps, PlaceholderUserCreated, PlaceholderUserCreatedProps, UserCurrencyChanged, UserCurrencyChangedProps, UserPhoneNumberChanged, UserPhoneNumberChangedProps, UserDisplayNameChanged, UserDisplayNameChangedProps, UserDeleted, UserDeletedProps, PlaceholderUserMerged, PlaceholderUserMergedProps, UserConvertedToPlaceholder, UserConvertedToPlaceholderProps, UserModel, UserEventType, } from './UserEvents';
5
+ export { FriendCreated, FriendCreatedProps, FriendUpdated, FriendUpdatedProps, FriendDeleted, FriendDeletedProps, FriendIdAdded, FriendIdAddedProps, FriendIdRemoved, FriendIdRemovedProps, FriendModel, FriendEventType, } from './FriendEvents';
6
+ export { ActivityLogCreated, ActivityLogCreatedProps, ActivityLogModel, SourceType, } from './ActivityLogEvents';
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,SAAS,EACT,oBAAoB,EACpB,qBAAqB,EACrB,YAAY,EACZ,WAAW,EACX,aAAa,EACb,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,2BAA2B,EAC3B,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,EAC1B,+BAA+B,EAC/B,SAAS,EACT,aAAa,GACd,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAGvC,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,oBAAoB,EACpB,sBAAsB,EACtB,2BAA2B,EAC3B,gBAAgB,EAChB,SAAS,EACT,oBAAoB,EACpB,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,sBAAsB,EACtB,2BAA2B,EAC3B,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,0BAA0B,EAC1B,0BAA0B,EAC1B,+BAA+B,EAC/B,SAAS,EACT,aAAa,GACd,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,WAAW,EACX,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,UAAU,GACX,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UserEventType = exports.UserConvertedToPlaceholder = exports.PlaceholderUserMerged = exports.UserDeleted = exports.UserDisplayNameChanged = exports.UserPhoneNumberChanged = exports.UserCurrencyChanged = exports.PlaceholderUserCreated = exports.UserCreated = exports.ChangeHistory = exports.ActivityType = exports.TransactionChangeType = exports.TransactionEventType = exports.SplitType = exports.TotalAmountChanged = exports.DescriptionChanged = exports.TransactionDeleted = exports.TransactionCreated = void 0;
3
+ exports.SourceType = exports.ActivityLogCreated = exports.FriendEventType = exports.FriendIdRemoved = exports.FriendIdAdded = exports.FriendDeleted = exports.FriendUpdated = exports.FriendCreated = exports.UserEventType = exports.UserConvertedToPlaceholder = exports.PlaceholderUserMerged = exports.UserDeleted = exports.UserDisplayNameChanged = exports.UserPhoneNumberChanged = exports.UserCurrencyChanged = exports.PlaceholderUserCreated = exports.UserCreated = exports.ChangeHistory = exports.TransactionEventType = exports.SplitType = exports.TransactionDateChanged = exports.CurrencyChanged = exports.SplitTypeChanged = exports.TotalAmountChanged = exports.DescriptionChanged = exports.TransactionDeleted = exports.TransactionCreated = void 0;
4
4
  // Transaction event types
5
5
  var TransactionEvents_1 = require("./TransactionEvents");
6
6
  Object.defineProperty(exports, "TransactionCreated", { enumerable: true, get: function () { return TransactionEvents_1.TransactionCreated; } });
7
7
  Object.defineProperty(exports, "TransactionDeleted", { enumerable: true, get: function () { return TransactionEvents_1.TransactionDeleted; } });
8
8
  Object.defineProperty(exports, "DescriptionChanged", { enumerable: true, get: function () { return TransactionEvents_1.DescriptionChanged; } });
9
9
  Object.defineProperty(exports, "TotalAmountChanged", { enumerable: true, get: function () { return TransactionEvents_1.TotalAmountChanged; } });
10
+ Object.defineProperty(exports, "SplitTypeChanged", { enumerable: true, get: function () { return TransactionEvents_1.SplitTypeChanged; } });
11
+ Object.defineProperty(exports, "CurrencyChanged", { enumerable: true, get: function () { return TransactionEvents_1.CurrencyChanged; } });
12
+ Object.defineProperty(exports, "TransactionDateChanged", { enumerable: true, get: function () { return TransactionEvents_1.TransactionDateChanged; } });
10
13
  Object.defineProperty(exports, "SplitType", { enumerable: true, get: function () { return TransactionEvents_1.SplitType; } });
11
14
  Object.defineProperty(exports, "TransactionEventType", { enumerable: true, get: function () { return TransactionEvents_1.TransactionEventType; } });
12
- Object.defineProperty(exports, "TransactionChangeType", { enumerable: true, get: function () { return TransactionEvents_1.TransactionChangeType; } });
13
- Object.defineProperty(exports, "ActivityType", { enumerable: true, get: function () { return TransactionEvents_1.ActivityType; } });
14
15
  Object.defineProperty(exports, "ChangeHistory", { enumerable: true, get: function () { return TransactionEvents_1.ChangeHistory; } });
15
16
  // User event types
16
17
  var UserEvents_1 = require("./UserEvents");
@@ -23,3 +24,15 @@ Object.defineProperty(exports, "UserDeleted", { enumerable: true, get: function
23
24
  Object.defineProperty(exports, "PlaceholderUserMerged", { enumerable: true, get: function () { return UserEvents_1.PlaceholderUserMerged; } });
24
25
  Object.defineProperty(exports, "UserConvertedToPlaceholder", { enumerable: true, get: function () { return UserEvents_1.UserConvertedToPlaceholder; } });
25
26
  Object.defineProperty(exports, "UserEventType", { enumerable: true, get: function () { return UserEvents_1.UserEventType; } });
27
+ // Friend event types
28
+ var FriendEvents_1 = require("./FriendEvents");
29
+ Object.defineProperty(exports, "FriendCreated", { enumerable: true, get: function () { return FriendEvents_1.FriendCreated; } });
30
+ Object.defineProperty(exports, "FriendUpdated", { enumerable: true, get: function () { return FriendEvents_1.FriendUpdated; } });
31
+ Object.defineProperty(exports, "FriendDeleted", { enumerable: true, get: function () { return FriendEvents_1.FriendDeleted; } });
32
+ Object.defineProperty(exports, "FriendIdAdded", { enumerable: true, get: function () { return FriendEvents_1.FriendIdAdded; } });
33
+ Object.defineProperty(exports, "FriendIdRemoved", { enumerable: true, get: function () { return FriendEvents_1.FriendIdRemoved; } });
34
+ Object.defineProperty(exports, "FriendEventType", { enumerable: true, get: function () { return FriendEvents_1.FriendEventType; } });
35
+ // Activity Log types
36
+ var ActivityLogEvents_1 = require("./ActivityLogEvents");
37
+ Object.defineProperty(exports, "ActivityLogCreated", { enumerable: true, get: function () { return ActivityLogEvents_1.ActivityLogCreated; } });
38
+ Object.defineProperty(exports, "SourceType", { enumerable: true, get: function () { return ActivityLogEvents_1.SourceType; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeeshan60/event-processor",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Shared event sourcing infrastructure for Loan Tracker projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,8 +26,12 @@
26
26
  "devDependencies": {
27
27
  "@types/jest": "^30.0.0",
28
28
  "@types/node": "^20.10.0",
29
+ "@types/uuid": "^10.0.0",
29
30
  "jest": "^30.2.0",
30
31
  "ts-jest": "^29.4.5",
31
32
  "typescript": "^5.3.3"
33
+ },
34
+ "dependencies": {
35
+ "uuid": "^13.0.0"
32
36
  }
33
37
  }