@zeeshan60/event-processor 1.0.15 → 1.0.16
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/README.md +29 -22
- package/dist/ActivityEventHandler.d.ts +3 -3
- package/dist/ActivityEventHandler.d.ts.map +1 -1
- package/dist/ActivityEventHandler.js +3 -8
- package/dist/BaseEventHandler.d.ts +5 -3
- package/dist/BaseEventHandler.d.ts.map +1 -1
- package/dist/BaseEventHandler.js +11 -0
- package/dist/EventProcessorSDK.d.ts +4 -0
- package/dist/EventProcessorSDK.d.ts.map +1 -1
- package/dist/EventProcessorSDK.js +7 -0
- package/dist/FriendEventHandler.d.ts +4 -2
- package/dist/FriendEventHandler.d.ts.map +1 -1
- package/dist/FriendEventHandler.js +50 -36
- package/dist/GroupEventHandler.d.ts +2 -2
- package/dist/GroupEventHandler.d.ts.map +1 -1
- package/dist/GroupEventHandler.js +235 -186
- package/dist/GroupTransactionEventHandler.d.ts +1 -2
- package/dist/GroupTransactionEventHandler.d.ts.map +1 -1
- package/dist/GroupTransactionEventHandler.js +4 -9
- package/dist/TransactionEventHandler.d.ts +1 -2
- package/dist/TransactionEventHandler.d.ts.map +1 -1
- package/dist/TransactionEventHandler.js +4 -9
- package/dist/UserEventHandler.d.ts +1 -2
- package/dist/UserEventHandler.d.ts.map +1 -1
- package/dist/UserEventHandler.js +4 -9
- package/dist/__tests__/test-helpers/IMCurrencyStore.d.ts +8 -0
- package/dist/__tests__/test-helpers/IMCurrencyStore.d.ts.map +1 -0
- package/dist/__tests__/test-helpers/IMCurrencyStore.js +16 -0
- package/dist/__tests__/test-helpers/IMTransactionModelStore.d.ts +2 -0
- package/dist/__tests__/test-helpers/IMTransactionModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMTransactionModelStore.js +20 -0
- package/dist/__tests__/test-helpers/IMUserModelStore.d.ts +3 -0
- package/dist/__tests__/test-helpers/IMUserModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMUserModelStore.js +10 -0
- package/dist/client/controllers/FriendController.d.ts +4 -0
- package/dist/client/controllers/FriendController.d.ts.map +1 -1
- package/dist/client/controllers/FriendController.js +45 -15
- package/dist/client/controllers/TransactionController.d.ts +7 -1
- package/dist/client/controllers/TransactionController.d.ts.map +1 -1
- package/dist/client/controllers/TransactionController.js +61 -0
- package/dist/common/CurrencyRate.d.ts +7 -0
- package/dist/common/CurrencyRate.d.ts.map +1 -0
- package/dist/common/CurrencyRate.js +2 -0
- package/dist/contracts/friends/index.d.ts +1 -9
- package/dist/contracts/friends/index.d.ts.map +1 -1
- package/dist/environment.d.ts +12 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +50 -0
- package/dist/events.d.ts +2 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +7 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/store/CurrencyStore.d.ts +5 -0
- package/dist/store/CurrencyStore.d.ts.map +1 -0
- package/dist/store/CurrencyStore.js +6 -0
- package/dist/store/TransactionModelStore.d.ts +2 -0
- package/dist/store/TransactionModelStore.d.ts.map +1 -1
- package/dist/store/UserModelStore.d.ts +1 -0
- package/dist/store/UserModelStore.d.ts.map +1 -1
- package/dist/utils/BalanceUtil.d.ts +13 -0
- package/dist/utils/BalanceUtil.d.ts.map +1 -0
- package/dist/utils/BalanceUtil.js +97 -0
- package/package.json +1 -1
- package/dist/client/handlers/UIFriendEventHandler.d.ts +0 -16
- package/dist/client/handlers/UIFriendEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UIFriendEventHandler.js +0 -27
- package/dist/client/handlers/UIGroupEventHandler.d.ts +0 -18
- package/dist/client/handlers/UIGroupEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UIGroupEventHandler.js +0 -28
- package/dist/client/handlers/UIGroupTransactionEventHandler.d.ts +0 -18
- package/dist/client/handlers/UIGroupTransactionEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UIGroupTransactionEventHandler.js +0 -28
- package/dist/client/handlers/UITransactionEventHandler.d.ts +0 -14
- package/dist/client/handlers/UITransactionEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UITransactionEventHandler.js +0 -26
- package/dist/client/handlers/UIUserEventHandler.d.ts +0 -12
- package/dist/client/handlers/UIUserEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UIUserEventHandler.js +0 -29
- package/dist/utils/userPathUtils.d.ts +0 -6
- package/dist/utils/userPathUtils.d.ts.map +0 -1
- package/dist/utils/userPathUtils.js +0 -16
|
@@ -2,24 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransactionEventHandler = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
|
+
const BaseEventHandler_1 = require("./BaseEventHandler");
|
|
5
6
|
const splitTypeUtils_1 = require("./utils/splitTypeUtils");
|
|
6
7
|
const uuid_1 = require("uuid");
|
|
7
8
|
const EventProcessorSDK_1 = require("./EventProcessorSDK");
|
|
8
|
-
class TransactionEventHandler {
|
|
9
|
+
class TransactionEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
9
10
|
constructor(modelStore, eventStore, activityEventHandler) {
|
|
11
|
+
super();
|
|
10
12
|
this.modelStore = modelStore;
|
|
11
13
|
this.eventStore = eventStore;
|
|
12
14
|
this.activityEventHandler = activityEventHandler;
|
|
13
15
|
}
|
|
14
|
-
shouldSkipSave(existingModel, updatedModel) {
|
|
15
|
-
if (!existingModel) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return (existingModel.streamId === updatedModel.streamId &&
|
|
19
|
-
existingModel.version === updatedModel.version);
|
|
20
|
-
}
|
|
21
16
|
async handleClientEventFromRemoteListener(event) {
|
|
22
|
-
const existingModel = await this.modelStore.
|
|
17
|
+
const existingModel = await this.modelStore.getByStreamId(event.streamId);
|
|
23
18
|
const model = event.apply(existingModel);
|
|
24
19
|
if (!this.shouldSkipSave(existingModel, model)) {
|
|
25
20
|
await this.modelStore.save(model);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { UserCreated, UserEvent, UserEventStore, UserModel, UserModelStore } from ".";
|
|
2
2
|
import { BaseEventHandler } from "./BaseEventHandler";
|
|
3
3
|
import { ActivityEventHandler } from "./ActivityEventHandler";
|
|
4
|
-
export declare class UserEventHandler
|
|
4
|
+
export declare class UserEventHandler extends BaseEventHandler<UserEvent> {
|
|
5
5
|
private modelStore;
|
|
6
6
|
private eventStore;
|
|
7
7
|
private activityEventHandler?;
|
|
8
8
|
constructor(modelStore: UserModelStore, eventStore: UserEventStore, activityEventHandler?: ActivityEventHandler | undefined);
|
|
9
|
-
private shouldSkipSave;
|
|
10
9
|
handleClientEventFromRemoteListener(event: UserEvent): Promise<void>;
|
|
11
10
|
handleEvent(event: UserEvent): Promise<UserModel>;
|
|
12
11
|
handleUserCreatedBackend(event: UserCreated): Promise<UserModel>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserEventHandler.d.ts","sourceRoot":"","sources":["../src/UserEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,WAAW,EACX,SAAS,EACT,cAAc,EACd,SAAS,EACT,cAAc,EACjB,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAI9D,qBAAa,gBAAiB,
|
|
1
|
+
{"version":3,"file":"UserEventHandler.d.ts","sourceRoot":"","sources":["../src/UserEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,WAAW,EACX,SAAS,EACT,cAAc,EACd,SAAS,EACT,cAAc,EACjB,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAI9D,qBAAa,gBAAiB,SAAQ,gBAAgB,CAAC,SAAS,CAAC;IAEzD,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,oBAAoB,CAAC;gBAFrB,UAAU,EAAE,cAAc,EAC1B,UAAU,EAAE,cAAc,EAC1B,oBAAoB,CAAC,EAAE,oBAAoB,YAAA;IAK1C,mCAAmC,CAC5C,KAAK,EAAE,SAAS,GACjB,OAAO,CAAC,IAAI,CAAC;IAcV,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IAgCjD,wBAAwB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC;CAuDzE"}
|
package/dist/UserEventHandler.js
CHANGED
|
@@ -2,23 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UserEventHandler = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
|
+
const BaseEventHandler_1 = require("./BaseEventHandler");
|
|
5
6
|
const uuid_1 = require("uuid");
|
|
6
7
|
const EventProcessorSDK_1 = require("./EventProcessorSDK");
|
|
7
|
-
class UserEventHandler {
|
|
8
|
+
class UserEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
8
9
|
constructor(modelStore, eventStore, activityEventHandler) {
|
|
10
|
+
super();
|
|
9
11
|
this.modelStore = modelStore;
|
|
10
12
|
this.eventStore = eventStore;
|
|
11
13
|
this.activityEventHandler = activityEventHandler;
|
|
12
14
|
}
|
|
13
|
-
shouldSkipSave(existingModel, updatedModel) {
|
|
14
|
-
if (!existingModel) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
return (existingModel.streamId === updatedModel.streamId &&
|
|
18
|
-
existingModel.version === updatedModel.version);
|
|
19
|
-
}
|
|
20
15
|
async handleClientEventFromRemoteListener(event) {
|
|
21
|
-
const existingModel = await this.modelStore.
|
|
16
|
+
const existingModel = await this.modelStore.getByStreamId(event.streamId);
|
|
22
17
|
const updatedModel = event.apply(existingModel);
|
|
23
18
|
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
24
19
|
await this.modelStore.save(updatedModel);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CurrencyRate, CurrencyStore } from "../..";
|
|
2
|
+
export declare class IMCurrencyStore extends CurrencyStore {
|
|
3
|
+
private currencyRate;
|
|
4
|
+
getCurrencyRates(): Promise<CurrencyRate | undefined>;
|
|
5
|
+
setCurrencyRates(rate: CurrencyRate): void;
|
|
6
|
+
clear(): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=IMCurrencyStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IMCurrencyStore.d.ts","sourceRoot":"","sources":["../../../src/__tests__/test-helpers/IMCurrencyStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEpD,qBAAa,eAAgB,SAAQ,aAAa;IAC9C,OAAO,CAAC,YAAY,CAA2B;IAEzC,gBAAgB,IAAI,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAI3D,gBAAgB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAI1C,KAAK,IAAI,IAAI;CAGhB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IMCurrencyStore = void 0;
|
|
4
|
+
const __1 = require("../..");
|
|
5
|
+
class IMCurrencyStore extends __1.CurrencyStore {
|
|
6
|
+
async getCurrencyRates() {
|
|
7
|
+
return this.currencyRate;
|
|
8
|
+
}
|
|
9
|
+
setCurrencyRates(rate) {
|
|
10
|
+
this.currencyRate = rate;
|
|
11
|
+
}
|
|
12
|
+
clear() {
|
|
13
|
+
this.currencyRate = undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.IMCurrencyStore = IMCurrencyStore;
|
|
@@ -5,6 +5,8 @@ export declare class IMTransactionModelStore implements TransactionModelStore {
|
|
|
5
5
|
getByStreamIdWhereDeletedIsFalse(streamId: string): Promise<TransactionModel | undefined>;
|
|
6
6
|
findByUserAndLogicalTransactionId(userId: string, recipientUserId: string, logicalTransactionId: string): Promise<TransactionModel | undefined>;
|
|
7
7
|
findByGroupTransactionId(userId: string, groupTransactionId: string): Promise<TransactionModel[]>;
|
|
8
|
+
findByUserIdAndRecipientUserIdWhereDeletedIsFalse(userId: string, recipientUserId: string): Promise<TransactionModel[]>;
|
|
9
|
+
findAllByUserIdWhereDeletedIsFalse(userId: string): Promise<TransactionModel[]>;
|
|
8
10
|
save(model: TransactionModel): Promise<void>;
|
|
9
11
|
getAll(): TransactionModel[];
|
|
10
12
|
getAllWhereDeletedIsFalse(): TransactionModel[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IMTransactionModelStore.d.ts","sourceRoot":"","sources":["../../../src/__tests__/test-helpers/IMTransactionModelStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AAEhE,qBAAa,uBAAwB,YAAW,qBAAqB;IACjE,OAAO,CAAC,MAAM,CAA4C;IAEpD,aAAa,CACf,QAAQ,EAAE,MAAM,GACjB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAKlC,gCAAgC,CAClC,QAAQ,EAAE,MAAM,GACjB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAQlC,iCAAiC,CACnC,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,EACvB,oBAAoB,EAAE,MAAM,GAC7B,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAclC,wBAAwB,CAC1B,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,MAAM,GAC3B,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAcxB,IAAI,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,MAAM,IAAI,gBAAgB,EAAE;IAI5B,yBAAyB,IAAI,gBAAgB,EAAE;IAM/C,KAAK,IAAI,IAAI;CAGhB"}
|
|
1
|
+
{"version":3,"file":"IMTransactionModelStore.d.ts","sourceRoot":"","sources":["../../../src/__tests__/test-helpers/IMTransactionModelStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAC;AAEhE,qBAAa,uBAAwB,YAAW,qBAAqB;IACjE,OAAO,CAAC,MAAM,CAA4C;IAEpD,aAAa,CACf,QAAQ,EAAE,MAAM,GACjB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAKlC,gCAAgC,CAClC,QAAQ,EAAE,MAAM,GACjB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAQlC,iCAAiC,CACnC,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,EACvB,oBAAoB,EAAE,MAAM,GAC7B,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAclC,wBAAwB,CAC1B,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,MAAM,GAC3B,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAcxB,iDAAiD,CACnD,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,GACxB,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAcxB,kCAAkC,CACpC,MAAM,EAAE,MAAM,GACf,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAUxB,IAAI,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,MAAM,IAAI,gBAAgB,EAAE;IAI5B,yBAAyB,IAAI,gBAAgB,EAAE;IAM/C,KAAK,IAAI,IAAI;CAGhB"}
|
|
@@ -38,6 +38,26 @@ class IMTransactionModelStore {
|
|
|
38
38
|
}
|
|
39
39
|
return results;
|
|
40
40
|
}
|
|
41
|
+
async findByUserIdAndRecipientUserIdWhereDeletedIsFalse(userId, recipientUserId) {
|
|
42
|
+
const results = [];
|
|
43
|
+
for (const model of this.models.values()) {
|
|
44
|
+
if (model.userId === userId &&
|
|
45
|
+
model.recipientUserId === recipientUserId &&
|
|
46
|
+
!model.deleted) {
|
|
47
|
+
results.push(model);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return results;
|
|
51
|
+
}
|
|
52
|
+
async findAllByUserIdWhereDeletedIsFalse(userId) {
|
|
53
|
+
const results = [];
|
|
54
|
+
for (const model of this.models.values()) {
|
|
55
|
+
if (model.userId === userId && !model.deleted) {
|
|
56
|
+
results.push(model);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return results;
|
|
60
|
+
}
|
|
41
61
|
async save(model) {
|
|
42
62
|
this.models.set(model.streamId, model);
|
|
43
63
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UserModel, UserModelStore } from "../..";
|
|
2
2
|
export declare class IMUserModelStore implements UserModelStore {
|
|
3
3
|
private models;
|
|
4
|
+
private currentUser;
|
|
4
5
|
getByStreamId(streamId: string): Promise<UserModel | undefined>;
|
|
5
6
|
getByStreamIdWhereDeletedIsFalse(streamId: string): Promise<UserModel | undefined>;
|
|
6
7
|
save(model: UserModel): Promise<void>;
|
|
@@ -10,5 +11,7 @@ export declare class IMUserModelStore implements UserModelStore {
|
|
|
10
11
|
getAll(): UserModel[];
|
|
11
12
|
getAllWhereDeletedIsFalse(): UserModel[];
|
|
12
13
|
clear(): void;
|
|
14
|
+
setCurrentUser(user: UserModel): void;
|
|
15
|
+
appUser(): Promise<UserModel>;
|
|
13
16
|
}
|
|
14
17
|
//# sourceMappingURL=IMUserModelStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IMUserModelStore.d.ts","sourceRoot":"","sources":["../../../src/__tests__/test-helpers/IMUserModelStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAElD,qBAAa,gBAAiB,YAAW,cAAc;IACnD,OAAO,CAAC,MAAM,CAAqC;
|
|
1
|
+
{"version":3,"file":"IMUserModelStore.d.ts","sourceRoot":"","sources":["../../../src/__tests__/test-helpers/IMUserModelStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAElD,qBAAa,gBAAiB,YAAW,cAAc;IACnD,OAAO,CAAC,MAAM,CAAqC;IACnD,OAAO,CAAC,WAAW,CAAwB;IAErC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAK/D,gCAAgC,CAClC,QAAQ,EAAE,MAAM,GACjB,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAQ3B,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAS1D,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAS1D,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IASpE,MAAM,IAAI,SAAS,EAAE;IAIrB,yBAAyB,IAAI,SAAS,EAAE;IAMxC,KAAK,IAAI,IAAI;IAIb,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAI/B,OAAO,IAAI,OAAO,CAAC,SAAS,CAAC;CAOtC"}
|
|
@@ -52,5 +52,15 @@ class IMUserModelStore {
|
|
|
52
52
|
clear() {
|
|
53
53
|
this.models.clear();
|
|
54
54
|
}
|
|
55
|
+
setCurrentUser(user) {
|
|
56
|
+
this.currentUser = user;
|
|
57
|
+
}
|
|
58
|
+
async appUser() {
|
|
59
|
+
const users = this.getAllWhereDeletedIsFalse();
|
|
60
|
+
if (users.length === 0) {
|
|
61
|
+
throw new Error("No user found in store.");
|
|
62
|
+
}
|
|
63
|
+
return users[0];
|
|
64
|
+
}
|
|
55
65
|
}
|
|
56
66
|
exports.IMUserModelStore = IMUserModelStore;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { FriendRequest, FriendResponse, FriendsResponse, UpdateFriendRequest } from "../../contracts/friends";
|
|
2
2
|
export declare class FriendController {
|
|
3
3
|
private get modelStore();
|
|
4
|
+
private get transactionModelStore();
|
|
5
|
+
private get userModelStore();
|
|
6
|
+
private get currencyStore();
|
|
4
7
|
private get friendEventHandler();
|
|
8
|
+
private get balanceUtil();
|
|
5
9
|
addFriend(userId: string, request: FriendRequest): Promise<string>;
|
|
6
10
|
updateFriend(userId: string, friendId: string, request: UpdateFriendRequest): Promise<void>;
|
|
7
11
|
deleteFriend(userId: string, friendId: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FriendController.d.ts","sourceRoot":"","sources":["../../../src/client/controllers/FriendController.ts"],"names":[],"mappings":"AAMA,OAAO,EACH,aAAa,EACb,cAAc,EACd,eAAe,EACf,mBAAmB,EACtB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"FriendController.d.ts","sourceRoot":"","sources":["../../../src/client/controllers/FriendController.ts"],"names":[],"mappings":"AAMA,OAAO,EACH,aAAa,EACb,cAAc,EACd,eAAe,EACf,mBAAmB,EACtB,MAAM,yBAAyB,CAAC;AAMjC,qBAAa,gBAAgB;IACzB,OAAO,KAAK,UAAU,GAGrB;IAED,OAAO,KAAK,qBAAqB,GAGhC;IAED,OAAO,KAAK,cAAc,GAEzB;IAED,OAAO,KAAK,aAAa,GAExB;IAED,OAAO,KAAK,kBAAkB,GAE7B;IAED,OAAO,KAAK,WAAW,GAEtB;IAEK,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC;IA2BlE,YAAY,CACd,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,mBAAmB,GAC7B,OAAO,CAAC,IAAI,CAAC;IAuDV,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiC7D,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAiCpE,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAU9D,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAuC7D,OAAO,CAAC,gBAAgB;CAmB3B"}
|
|
@@ -4,14 +4,28 @@ exports.FriendController = void 0;
|
|
|
4
4
|
const FriendEvents_1 = require("../../FriendEvents");
|
|
5
5
|
const uuid_1 = require("uuid");
|
|
6
6
|
const EventProcessorSDK_1 = require("../../EventProcessorSDK");
|
|
7
|
+
const BalanceUtil_1 = require("../../utils/BalanceUtil");
|
|
7
8
|
class FriendController {
|
|
8
9
|
get modelStore() {
|
|
9
10
|
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig()
|
|
10
11
|
.friendModelStore;
|
|
11
12
|
}
|
|
13
|
+
get transactionModelStore() {
|
|
14
|
+
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig()
|
|
15
|
+
.transactionModelStore;
|
|
16
|
+
}
|
|
17
|
+
get userModelStore() {
|
|
18
|
+
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig().userModelStore;
|
|
19
|
+
}
|
|
20
|
+
get currencyStore() {
|
|
21
|
+
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig().currencyStore;
|
|
22
|
+
}
|
|
12
23
|
get friendEventHandler() {
|
|
13
24
|
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getFriendEventHandler();
|
|
14
25
|
}
|
|
26
|
+
get balanceUtil() {
|
|
27
|
+
return new BalanceUtil_1.BalanceUtil(this.userModelStore, this.currencyStore);
|
|
28
|
+
}
|
|
15
29
|
async addFriend(userId, request) {
|
|
16
30
|
if (!request.email && !request.phoneNumber) {
|
|
17
31
|
throw new Error("Either email or phoneNumber must be provided");
|
|
@@ -36,7 +50,11 @@ class FriendController {
|
|
|
36
50
|
return streamId;
|
|
37
51
|
}
|
|
38
52
|
async updateFriend(userId, friendId, request) {
|
|
39
|
-
|
|
53
|
+
let friendModel = await this.modelStore.findByUserIdAndFriendIdAndDeletedIsFalse(userId, friendId);
|
|
54
|
+
if (!friendModel) {
|
|
55
|
+
//fallback to find by streamId
|
|
56
|
+
friendModel = await this.modelStore.findByUserIdAndStreamIdAndDeletedIsFalse(userId, friendId);
|
|
57
|
+
}
|
|
40
58
|
if (!friendModel) {
|
|
41
59
|
throw new Error(`Friend not found: ${friendId}`);
|
|
42
60
|
}
|
|
@@ -70,7 +88,11 @@ class FriendController {
|
|
|
70
88
|
await this.friendEventHandler.handleEvent(event);
|
|
71
89
|
}
|
|
72
90
|
async deleteFriend(userId, friendId) {
|
|
73
|
-
|
|
91
|
+
let friendModel = await this.modelStore.findByUserIdAndFriendIdAndDeletedIsFalse(userId, friendId);
|
|
92
|
+
if (!friendModel) {
|
|
93
|
+
//fallback to find by streamId
|
|
94
|
+
friendModel = await this.modelStore.findByUserIdAndStreamIdAndDeletedIsFalse(userId, friendId);
|
|
95
|
+
}
|
|
74
96
|
if (!friendModel) {
|
|
75
97
|
throw new Error(`Friend not found: ${friendId}`);
|
|
76
98
|
}
|
|
@@ -87,11 +109,18 @@ class FriendController {
|
|
|
87
109
|
await this.friendEventHandler.handleEvent(event);
|
|
88
110
|
}
|
|
89
111
|
async getFriend(userId, friendId) {
|
|
90
|
-
|
|
112
|
+
let friendModel = await this.modelStore.findByUserIdAndFriendIdAndDeletedIsFalse(userId, friendId);
|
|
113
|
+
if (!friendModel) {
|
|
114
|
+
//fallback to find by streamId
|
|
115
|
+
friendModel = await this.modelStore.findByUserIdAndStreamIdAndDeletedIsFalse(userId, friendId);
|
|
116
|
+
}
|
|
91
117
|
if (!friendModel) {
|
|
92
118
|
throw new Error(`Friend not found: ${friendId}`);
|
|
93
119
|
}
|
|
94
|
-
|
|
120
|
+
const recipientUserId = friendModel.friendId ?? friendModel.streamId;
|
|
121
|
+
const transactions = await this.transactionModelStore.findByUserIdAndRecipientUserIdWhereDeletedIsFalse(userId, recipientUserId);
|
|
122
|
+
const balance = await this.balanceUtil.calculateBalance(transactions, userId);
|
|
123
|
+
return this.toFriendResponse(friendModel, balance);
|
|
95
124
|
}
|
|
96
125
|
async getFriendByStreamId(streamId) {
|
|
97
126
|
const friendModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(streamId);
|
|
@@ -102,17 +131,20 @@ class FriendController {
|
|
|
102
131
|
}
|
|
103
132
|
async getAllFriends(userId) {
|
|
104
133
|
const friendModels = await this.modelStore.findAllByUserIdWhereDeletedIsFalse(userId);
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
134
|
+
const allTransactions = await this.transactionModelStore.findAllByUserIdWhereDeletedIsFalse(userId);
|
|
135
|
+
const mainBalance = await this.balanceUtil.calculateBalance(allTransactions, userId);
|
|
136
|
+
const friendsWithBalance = await Promise.all(friendModels.map(async (friendModel) => {
|
|
137
|
+
const recipientUserId = friendModel.friendId ?? friendModel.streamId;
|
|
138
|
+
const friendTransactions = await this.transactionModelStore.findByUserIdAndRecipientUserIdWhereDeletedIsFalse(userId, recipientUserId);
|
|
139
|
+
const friendBalance = await this.balanceUtil.calculateBalance(friendTransactions, userId);
|
|
140
|
+
return this.toFriendResponse(friendModel, friendBalance);
|
|
141
|
+
}));
|
|
110
142
|
return {
|
|
111
|
-
friends,
|
|
112
|
-
balance:
|
|
143
|
+
friends: friendsWithBalance,
|
|
144
|
+
balance: mainBalance,
|
|
113
145
|
};
|
|
114
146
|
}
|
|
115
|
-
toFriendResponse(friendModel) {
|
|
147
|
+
toFriendResponse(friendModel, balance) {
|
|
116
148
|
const emptyBalance = {
|
|
117
149
|
main: undefined,
|
|
118
150
|
other: [],
|
|
@@ -124,9 +156,7 @@ class FriendController {
|
|
|
124
156
|
settled: false,
|
|
125
157
|
email: friendModel.friendEmail,
|
|
126
158
|
phone: friendModel.friendPhoneNumber,
|
|
127
|
-
|
|
128
|
-
otherBalances: [],
|
|
129
|
-
balance: emptyBalance,
|
|
159
|
+
balance: balance ?? emptyBalance,
|
|
130
160
|
};
|
|
131
161
|
}
|
|
132
162
|
}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import { TransactionCreateRequest, TransactionResponse, TransactionUpdateRequest } from "../../contracts/transactions";
|
|
1
|
+
import { TransactionCreateRequest, TransactionResponse, TransactionUpdateRequest, TransactionsResponse } from "../../contracts/transactions";
|
|
2
2
|
export declare class TransactionController {
|
|
3
3
|
private get modelStore();
|
|
4
4
|
private get transactionEventHandler();
|
|
5
|
+
private get userModelStore();
|
|
6
|
+
private get currencyStore();
|
|
7
|
+
private get balanceUtil();
|
|
5
8
|
private calculateAmount;
|
|
6
9
|
addTransaction(userId: string, request: TransactionCreateRequest): Promise<string>;
|
|
7
10
|
updateTransaction(userId: string, transactionId: string, request: TransactionUpdateRequest): Promise<void>;
|
|
8
11
|
deleteTransaction(userId: string, transactionId: string): Promise<void>;
|
|
9
12
|
getTransaction(userId: string, transactionId: string): Promise<TransactionResponse>;
|
|
13
|
+
getTransactionsByMonth(userId: string, friendId: string, timeZone: string): Promise<TransactionsResponse>;
|
|
14
|
+
private groupTransactionsByMonth;
|
|
15
|
+
private startOfMonth;
|
|
10
16
|
private toTransactionResponse;
|
|
11
17
|
}
|
|
12
18
|
//# sourceMappingURL=TransactionController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../../../src/client/controllers/TransactionController.ts"],"names":[],"mappings":"AAWA,OAAO,EACH,wBAAwB,EACxB,mBAAmB,EACnB,wBAAwB,
|
|
1
|
+
{"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../../../src/client/controllers/TransactionController.ts"],"names":[],"mappings":"AAWA,OAAO,EACH,wBAAwB,EACxB,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EAEvB,MAAM,8BAA8B,CAAC;AAKtC,qBAAa,qBAAqB;IAC9B,OAAO,KAAK,UAAU,GAGrB;IAED,OAAO,KAAK,uBAAuB,GAElC;IAED,OAAO,KAAK,cAAc,GAEzB;IAED,OAAO,KAAK,aAAa,GAExB;IAED,OAAO,KAAK,WAAW,GAEtB;IAED,OAAO,CAAC,eAAe;IAYjB,cAAc,CAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,MAAM,CAAC;IAgCZ,iBAAiB,CACnB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,IAAI,CAAC;IAuHV,iBAAiB,CACnB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC;IA6BV,cAAc,CAChB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,GACtB,OAAO,CAAC,mBAAmB,CAAC;IAkBzB,sBAAsB,CACxB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACjB,OAAO,CAAC,oBAAoB,CAAC;IAyChC,OAAO,CAAC,wBAAwB;IAwBhC,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,qBAAqB;CAuChC"}
|
|
@@ -4,6 +4,7 @@ exports.TransactionController = void 0;
|
|
|
4
4
|
const TransactionEvents_1 = require("../../TransactionEvents");
|
|
5
5
|
const EventProcessorSDK_1 = require("../../EventProcessorSDK");
|
|
6
6
|
const uuid_1 = require("uuid");
|
|
7
|
+
const BalanceUtil_1 = require("../../utils/BalanceUtil");
|
|
7
8
|
class TransactionController {
|
|
8
9
|
get modelStore() {
|
|
9
10
|
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig()
|
|
@@ -12,6 +13,15 @@ class TransactionController {
|
|
|
12
13
|
get transactionEventHandler() {
|
|
13
14
|
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getTransactionEventHandler();
|
|
14
15
|
}
|
|
16
|
+
get userModelStore() {
|
|
17
|
+
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig().userModelStore;
|
|
18
|
+
}
|
|
19
|
+
get currencyStore() {
|
|
20
|
+
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig().currencyStore;
|
|
21
|
+
}
|
|
22
|
+
get balanceUtil() {
|
|
23
|
+
return new BalanceUtil_1.BalanceUtil(this.userModelStore, this.currencyStore);
|
|
24
|
+
}
|
|
15
25
|
calculateAmount(splitType, totalAmount) {
|
|
16
26
|
if (splitType === TransactionEvents_1.SplitType.TheyOweYouAll ||
|
|
17
27
|
splitType === TransactionEvents_1.SplitType.YouOweThemAll ||
|
|
@@ -173,6 +183,57 @@ class TransactionController {
|
|
|
173
183
|
}
|
|
174
184
|
return this.toTransactionResponse(transactionModel);
|
|
175
185
|
}
|
|
186
|
+
async getTransactionsByMonth(userId, friendId, timeZone) {
|
|
187
|
+
if (!timeZone || timeZone.trim() === "") {
|
|
188
|
+
throw new Error("Invalid timezone");
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
new Date().toLocaleString("en-US", { timeZone });
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
throw new Error("Invalid timezone");
|
|
195
|
+
}
|
|
196
|
+
const transactions = await this.modelStore.findByUserIdAndRecipientUserIdWhereDeletedIsFalse(userId, friendId);
|
|
197
|
+
const balance = await this.balanceUtil.calculateBalance(transactions, userId);
|
|
198
|
+
const sortedTransactions = transactions
|
|
199
|
+
.sort((a, b) => new Date(b.transactionDate).getTime() -
|
|
200
|
+
new Date(a.transactionDate).getTime())
|
|
201
|
+
.map((t) => this.toTransactionResponse(t));
|
|
202
|
+
const groupedByMonth = this.groupTransactionsByMonth(sortedTransactions, timeZone);
|
|
203
|
+
return {
|
|
204
|
+
balance,
|
|
205
|
+
perMonth: groupedByMonth,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
groupTransactionsByMonth(transactions, timeZone) {
|
|
209
|
+
const grouped = new Map();
|
|
210
|
+
for (const transaction of transactions) {
|
|
211
|
+
const monthStart = this.startOfMonth(transaction.date, timeZone);
|
|
212
|
+
const key = monthStart;
|
|
213
|
+
if (!grouped.has(key)) {
|
|
214
|
+
grouped.set(key, []);
|
|
215
|
+
}
|
|
216
|
+
grouped.get(key).push(transaction);
|
|
217
|
+
}
|
|
218
|
+
return Array.from(grouped.entries())
|
|
219
|
+
.sort((a, b) => new Date(b[0]).getTime() - new Date(a[0]).getTime())
|
|
220
|
+
.map(([date, transactions]) => ({
|
|
221
|
+
date,
|
|
222
|
+
transactions,
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
startOfMonth(dateString, timeZone) {
|
|
226
|
+
const date = new Date(dateString);
|
|
227
|
+
const year = date.toLocaleString("en-US", {
|
|
228
|
+
year: "numeric",
|
|
229
|
+
timeZone,
|
|
230
|
+
});
|
|
231
|
+
const month = date.toLocaleString("en-US", {
|
|
232
|
+
month: "2-digit",
|
|
233
|
+
timeZone,
|
|
234
|
+
});
|
|
235
|
+
return new Date(`${year}-${month}-01T00:00:00.000Z`).toISOString();
|
|
236
|
+
}
|
|
176
237
|
toTransactionResponse(transactionModel) {
|
|
177
238
|
return {
|
|
178
239
|
date: transactionModel.transactionDate.toISOString(),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CurrencyRate.d.ts","sourceRoot":"","sources":["../../src/common/CurrencyRate.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,WAAW,EAAE,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AmountDto,
|
|
1
|
+
import { AmountDto, BalanceResponse } from "../shared";
|
|
2
2
|
export interface FriendRequest {
|
|
3
3
|
email?: string;
|
|
4
4
|
phoneNumber?: string;
|
|
@@ -65,14 +65,6 @@ export interface FriendResponse {
|
|
|
65
65
|
settled: boolean;
|
|
66
66
|
email?: string;
|
|
67
67
|
phone?: string;
|
|
68
|
-
/**
|
|
69
|
-
* @deprecated Should not use this property anymore, use balance.main instead
|
|
70
|
-
*/
|
|
71
|
-
mainBalance?: AmountResponse;
|
|
72
|
-
/**
|
|
73
|
-
* @deprecated Should not use this property anymore, use balance.other instead
|
|
74
|
-
*/
|
|
75
|
-
otherBalances: OtherBalanceResponse[];
|
|
76
68
|
balance: BalanceResponse;
|
|
77
69
|
}
|
|
78
70
|
export interface FriendsResponse {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/contracts/friends/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/contracts/friends/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EAET,eAAe,EAElB,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,aAAa;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,eAAgB,SAAQ,aAAa;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAgB,SAAQ,aAAa;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC5B,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,SAAS,CAAC;IAClB,eAAe,EAAE,SAAS,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,eAAe,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,6BAA6B;IAC1C,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,OAAO,EAAE,iBAAiB,CAAC;CAC9B;AAED,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,eAAe,CAAC;CAC5B;AAED,MAAM,WAAW,eAAe;IAC5B,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,OAAO,EAAE,eAAe,CAAC;CAC5B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum EventProcessorSource {
|
|
2
|
+
GOOGLE_CLOUD_FUNCTION = "GOOGLE_CLOUD_FUNCTION",
|
|
3
|
+
CLIENT = "CLIENT",
|
|
4
|
+
UNKNOWN = "UNKNOWN"
|
|
5
|
+
}
|
|
6
|
+
export declare function setEventProcessorSource(source: EventProcessorSource): void;
|
|
7
|
+
export declare function getEventProcessorSource(): EventProcessorSource;
|
|
8
|
+
export declare function isGCFun(): boolean;
|
|
9
|
+
export declare function isClient(): boolean;
|
|
10
|
+
export declare function isUnknown(): boolean;
|
|
11
|
+
export declare function resetEventProcessorSource(): void;
|
|
12
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,oBAAY,oBAAoB;IAC5B,qBAAqB,0BAA0B;IAC/C,MAAM,WAAW;IACjB,OAAO,YAAY;CACtB;AAWD,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAE1E;AAED,wBAAgB,uBAAuB,IAAI,oBAAoB,CAE9D;AAED,wBAAgB,OAAO,IAAI,OAAO,CAEjC;AAED,wBAAgB,QAAQ,IAAI,OAAO,CAElC;AAED,wBAAgB,SAAS,IAAI,OAAO,CAEnC;AAED,wBAAgB,yBAAyB,IAAI,IAAI,CAShD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventProcessorSource = void 0;
|
|
4
|
+
exports.setEventProcessorSource = setEventProcessorSource;
|
|
5
|
+
exports.getEventProcessorSource = getEventProcessorSource;
|
|
6
|
+
exports.isGCFun = isGCFun;
|
|
7
|
+
exports.isClient = isClient;
|
|
8
|
+
exports.isUnknown = isUnknown;
|
|
9
|
+
exports.resetEventProcessorSource = resetEventProcessorSource;
|
|
10
|
+
var EventProcessorSource;
|
|
11
|
+
(function (EventProcessorSource) {
|
|
12
|
+
EventProcessorSource["GOOGLE_CLOUD_FUNCTION"] = "GOOGLE_CLOUD_FUNCTION";
|
|
13
|
+
EventProcessorSource["CLIENT"] = "CLIENT";
|
|
14
|
+
EventProcessorSource["UNKNOWN"] = "UNKNOWN";
|
|
15
|
+
})(EventProcessorSource || (exports.EventProcessorSource = EventProcessorSource = {}));
|
|
16
|
+
let currentSource = EventProcessorSource.UNKNOWN;
|
|
17
|
+
const envSource = process.env.EVENT_PROCESSOR_SOURCE;
|
|
18
|
+
if (envSource === "GOOGLE_CLOUD_FUNCTION") {
|
|
19
|
+
currentSource = EventProcessorSource.GOOGLE_CLOUD_FUNCTION;
|
|
20
|
+
}
|
|
21
|
+
else if (envSource === "CLIENT") {
|
|
22
|
+
currentSource = EventProcessorSource.CLIENT;
|
|
23
|
+
}
|
|
24
|
+
function setEventProcessorSource(source) {
|
|
25
|
+
currentSource = source;
|
|
26
|
+
}
|
|
27
|
+
function getEventProcessorSource() {
|
|
28
|
+
return currentSource;
|
|
29
|
+
}
|
|
30
|
+
function isGCFun() {
|
|
31
|
+
return currentSource === EventProcessorSource.GOOGLE_CLOUD_FUNCTION;
|
|
32
|
+
}
|
|
33
|
+
function isClient() {
|
|
34
|
+
return currentSource === EventProcessorSource.CLIENT;
|
|
35
|
+
}
|
|
36
|
+
function isUnknown() {
|
|
37
|
+
return currentSource === EventProcessorSource.UNKNOWN;
|
|
38
|
+
}
|
|
39
|
+
function resetEventProcessorSource() {
|
|
40
|
+
const envSource = process.env.EVENT_PROCESSOR_SOURCE;
|
|
41
|
+
if (envSource === "GOOGLE_CLOUD_FUNCTION") {
|
|
42
|
+
currentSource = EventProcessorSource.GOOGLE_CLOUD_FUNCTION;
|
|
43
|
+
}
|
|
44
|
+
else if (envSource === "CLIENT") {
|
|
45
|
+
currentSource = EventProcessorSource.CLIENT;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
currentSource = EventProcessorSource.UNKNOWN;
|
|
49
|
+
}
|
|
50
|
+
}
|
package/dist/events.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./GroupTransactionEvents";
|
|
|
6
6
|
export * from "./ActivityLogEvents";
|
|
7
7
|
export * from "./common/Event";
|
|
8
8
|
export * from "./common/Model";
|
|
9
|
+
export { BaseEventHandler } from "./BaseEventHandler";
|
|
9
10
|
export * from "./store/ModelStore";
|
|
10
11
|
export * from "./store/TransactionEventStore";
|
|
11
12
|
export * from "./store/TransactionModelStore";
|
|
@@ -26,4 +27,5 @@ export { GroupEventHandler } from "./GroupEventHandler";
|
|
|
26
27
|
export { GroupTransactionEventHandler } from "./GroupTransactionEventHandler";
|
|
27
28
|
export { ActivityEventHandler } from "./ActivityEventHandler";
|
|
28
29
|
export { reverseSplitType, calculateMirrorAmountAndIsOwed, } from "./utils/splitTypeUtils";
|
|
30
|
+
export { BalanceUtil } from "./utils/BalanceUtil";
|
|
29
31
|
//# sourceMappingURL=events.d.ts.map
|
package/dist/events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAG9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,OAAO,EACH,gBAAgB,EAChB,8BAA8B,GACjC,MAAM,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AACA,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAG/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAG9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,OAAO,EACH,gBAAgB,EAChB,8BAA8B,GACjC,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/events.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.calculateMirrorAmountAndIsOwed = exports.reverseSplitType = exports.ActivityEventHandler = exports.GroupTransactionEventHandler = exports.GroupEventHandler = exports.FriendEventHandler = exports.UserEventHandler = exports.TransactionEventHandler = void 0;
|
|
17
|
+
exports.BalanceUtil = exports.calculateMirrorAmountAndIsOwed = exports.reverseSplitType = exports.ActivityEventHandler = exports.GroupTransactionEventHandler = exports.GroupEventHandler = exports.FriendEventHandler = exports.UserEventHandler = exports.TransactionEventHandler = exports.BaseEventHandler = void 0;
|
|
18
18
|
// Re-export all event types
|
|
19
19
|
__exportStar(require("./TransactionEvents"), exports);
|
|
20
20
|
__exportStar(require("./UserEvents"), exports);
|
|
@@ -25,6 +25,9 @@ __exportStar(require("./ActivityLogEvents"), exports);
|
|
|
25
25
|
// Re-export common types
|
|
26
26
|
__exportStar(require("./common/Event"), exports);
|
|
27
27
|
__exportStar(require("./common/Model"), exports);
|
|
28
|
+
// Re-export base event handler
|
|
29
|
+
var BaseEventHandler_1 = require("./BaseEventHandler");
|
|
30
|
+
Object.defineProperty(exports, "BaseEventHandler", { enumerable: true, get: function () { return BaseEventHandler_1.BaseEventHandler; } });
|
|
28
31
|
// Re-export store classes
|
|
29
32
|
__exportStar(require("./store/ModelStore"), exports);
|
|
30
33
|
__exportStar(require("./store/TransactionEventStore"), exports);
|
|
@@ -56,3 +59,6 @@ Object.defineProperty(exports, "ActivityEventHandler", { enumerable: true, get:
|
|
|
56
59
|
var splitTypeUtils_1 = require("./utils/splitTypeUtils");
|
|
57
60
|
Object.defineProperty(exports, "reverseSplitType", { enumerable: true, get: function () { return splitTypeUtils_1.reverseSplitType; } });
|
|
58
61
|
Object.defineProperty(exports, "calculateMirrorAmountAndIsOwed", { enumerable: true, get: function () { return splitTypeUtils_1.calculateMirrorAmountAndIsOwed; } });
|
|
62
|
+
// Re-export utility classes
|
|
63
|
+
var BalanceUtil_1 = require("./utils/BalanceUtil");
|
|
64
|
+
Object.defineProperty(exports, "BalanceUtil", { enumerable: true, get: function () { return BalanceUtil_1.BalanceUtil; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,11 @@ export { UserController } from "./client/controllers/UserController";
|
|
|
5
5
|
export { FriendController } from "./client/controllers/FriendController";
|
|
6
6
|
export { TransactionController } from "./client/controllers/TransactionController";
|
|
7
7
|
export { UIEventHandler } from "./client/handlers/UIEventHandler";
|
|
8
|
-
export { EventProcessorSDK, initializeSDK, getUserController, getFriendController, getTransactionController, getUIEventHandler, getUserEventHandler, getFriendEventHandler, getTransactionEventHandler, getGroupEventHandler, getGroupTransactionEventHandler, getActivityEventHandler, getFirebaseAdapter, getModelChangeObservable, eventToFirestore, firestoreToEvent, isSDKInitialized, StoreConfig, } from "./EventProcessorSDK";
|
|
8
|
+
export { EventProcessorSDK, initializeSDK, getUserController, getFriendController, getTransactionController, getUIEventHandler, getUserEventHandler, getFriendEventHandler, getTransactionEventHandler, getGroupEventHandler, getGroupTransactionEventHandler, getActivityEventHandler, getFirebaseAdapter, getCurrencyStore, getModelChangeObservable, eventToFirestore, firestoreToEvent, isSDKInitialized, StoreConfig, } from "./EventProcessorSDK";
|
|
9
9
|
export { ModelChangeEmitter, ModelChange } from "./ModelChangeEmitter";
|
|
10
10
|
export { FirebaseAdapter } from "./adapters/FirebaseAdapter";
|
|
11
|
+
export { CurrencyStore } from "./store/CurrencyStore";
|
|
12
|
+
export type { CurrencyRate } from "./common/CurrencyRate";
|
|
11
13
|
export type { FirestoreEventData } from "./converters/eventConverter";
|
|
12
14
|
export { EventConverterFactory } from "./converters/eventConverter";
|
|
13
15
|
export { __resetSDKForTesting } from "./EventProcessorSDK";
|