monorise 1.1.0-dev.9 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base/index.d.ts +54 -162
- package/dist/base/index.js +1 -51
- package/dist/base/index.js.map +1 -1
- package/dist/cli/cli.js +2 -8
- package/dist/cli/cli.js.map +1 -1
- package/dist/core/index.d.ts +60 -147
- package/dist/core/index.js +294 -1761
- package/dist/core/index.js.map +1 -1
- package/dist/react/actions/core.action.d.ts.map +1 -1
- package/dist/react/index.d.ts +4 -53
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +140 -624
- package/dist/react/index.js.map +1 -1
- package/dist/react/lib/entity.d.ts +1 -1
- package/dist/react/lib/entity.d.ts.map +1 -1
- package/dist/react/services/core.service.d.ts +1 -11
- package/dist/react/services/core.service.d.ts.map +1 -1
- package/dist/sst/components/monorise-core.d.ts +0 -12
- package/dist/sst/components/monorise-core.d.ts.map +1 -1
- package/dist/sst/components/single-table.d.ts +3 -3
- package/dist/sst/components/single-table.d.ts.map +1 -1
- package/dist/sst/index.js +13 -77
- package/dist/sst/index.js.map +1 -1
- package/package.json +6 -11
- package/dist/core/chunk-QV4Q5377.js +0 -76
- package/dist/core/chunk-QV4Q5377.js.map +0 -1
- package/dist/core/service.config-ZJEZ6EKA.js +0 -13
- package/dist/core/service.config-ZJEZ6EKA.js.map +0 -1
- package/dist/proxy/index.d.ts +0 -35
- package/dist/proxy/index.js +0 -75
- package/dist/proxy/index.js.map +0 -1
- package/dist/react/actions/websocket.action.d.ts +0 -71
- package/dist/react/actions/websocket.action.d.ts.map +0 -1
- package/dist/react/chunk-BIXAYYE4.js +0 -432
- package/dist/react/chunk-BIXAYYE4.js.map +0 -1
- package/dist/react/websocket/WebSocketManager.d.ts +0 -68
- package/dist/react/websocket/WebSocketManager.d.ts.map +0 -1
- package/dist/react/websocket/index.d.ts +0 -3
- package/dist/react/websocket/index.d.ts.map +0 -1
- package/dist/react/websocket/optimistic.d.ts +0 -51
- package/dist/react/websocket/optimistic.d.ts.map +0 -1
- package/dist/react/websocket-7MZ3ENOC.js +0 -9
- package/dist/react/websocket-7MZ3ENOC.js.map +0 -1
package/dist/core/index.js
CHANGED
|
@@ -1,14 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
var __export = (target, all) => {
|
|
33
|
+
for (var name in all)
|
|
34
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
35
|
+
};
|
|
36
|
+
var __async = (__this, __arguments, generator) => {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
var fulfilled = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.next(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var rejected = (value) => {
|
|
46
|
+
try {
|
|
47
|
+
step(generator.throw(value));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject(e);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
53
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
54
|
+
});
|
|
55
|
+
};
|
|
12
56
|
|
|
13
57
|
// controllers/setupRoutes.ts
|
|
14
58
|
import { Hono } from "hono";
|
|
@@ -96,11 +140,6 @@ var setupCommonRoutes = (container) => {
|
|
|
96
140
|
container.deleteEntityController.controller
|
|
97
141
|
);
|
|
98
142
|
app.get("/tag/:entityType/:tagName", container.listTagsController.controller);
|
|
99
|
-
app.post("/transaction", container.executeTransactionController.controller);
|
|
100
|
-
app.post(
|
|
101
|
-
"/ws/ticket/:entityType/:entityId",
|
|
102
|
-
container.createTicketController.controller
|
|
103
|
-
);
|
|
104
143
|
return app;
|
|
105
144
|
};
|
|
106
145
|
|
|
@@ -136,7 +175,6 @@ var StandardErrorCode = {
|
|
|
136
175
|
ENTITY_ID_IS_UNDEFINED: "ENTITY_ID_IS_UNDEFINED",
|
|
137
176
|
ENTITY_IS_UNDEFINED: "ENTITY_IS_UNDEFINED",
|
|
138
177
|
ENTITY_NOT_FOUND: "ENTITY_NOT_FOUND",
|
|
139
|
-
INVALID_CONDITION: "INVALID_CONDITION",
|
|
140
178
|
INVALID_ENTITY_TYPE: "INVALID_ENTITY_TYPE",
|
|
141
179
|
INVALID_MUTUAL: "INVALID_MUTUAL",
|
|
142
180
|
INVALID_QUERY: "INVALID_QUERY",
|
|
@@ -149,10 +187,7 @@ var StandardErrorCode = {
|
|
|
149
187
|
REPLICATION_ERROR: "REPLICATION_ERROR",
|
|
150
188
|
RETRYABLE_MUTUAL_LOCK_CONFLICT: "RETRYABLE_MUTUAL_LOCK_CONFLICT",
|
|
151
189
|
TAG_IS_UNDEFINED: "TAG_IS_UNDEFINED",
|
|
152
|
-
TRANSACTION_EMPTY: "TRANSACTION_EMPTY",
|
|
153
190
|
TRANSACTION_FAILED: "TRANSACTION_FAILED",
|
|
154
|
-
TRANSACTION_ITEM_LIMIT_EXCEEDED: "TRANSACTION_ITEM_LIMIT_EXCEEDED",
|
|
155
|
-
TRANSACTION_UNIQUE_FIELD_UPDATE: "TRANSACTION_UNIQUE_FIELD_UPDATE",
|
|
156
191
|
UNIQUE_VALUE_EXISTS: "UNIQUE_VALUE_EXISTS"
|
|
157
192
|
};
|
|
158
193
|
|
|
@@ -276,13 +311,14 @@ var Repository = class {
|
|
|
276
311
|
|
|
277
312
|
// data/Entity.ts
|
|
278
313
|
var Entity = class _Entity extends Item {
|
|
279
|
-
constructor(entityType, entityId, data = {}, _createdAt, _updatedAt) {
|
|
314
|
+
constructor(entityType, entityId, data = {}, _createdAt, _updatedAt, _expiresAt) {
|
|
280
315
|
super();
|
|
281
316
|
this.entityType = entityType;
|
|
282
317
|
this.entityId = entityId;
|
|
283
318
|
this.data = data;
|
|
284
319
|
this._createdAt = _createdAt;
|
|
285
320
|
this._updatedAt = _updatedAt;
|
|
321
|
+
this._expiresAt = _expiresAt;
|
|
286
322
|
this.fullId = this.pk;
|
|
287
323
|
}
|
|
288
324
|
static fromItem(item) {
|
|
@@ -297,7 +333,9 @@ var Entity = class _Entity extends Item {
|
|
|
297
333
|
parsedItem.entityId,
|
|
298
334
|
parsedItem.data,
|
|
299
335
|
parsedItem.createdAt ? new Date(parsedItem.createdAt) : void 0,
|
|
300
|
-
parsedItem.updatedAt ? new Date(parsedItem.updatedAt) : void 0
|
|
336
|
+
parsedItem.updatedAt ? new Date(parsedItem.updatedAt) : void 0,
|
|
337
|
+
// expiresAt is stored as epoch seconds (DynamoDB TTL requires type N)
|
|
338
|
+
parsedItem.expiresAt ? new Date(parsedItem.expiresAt * 1e3) : void 0
|
|
301
339
|
);
|
|
302
340
|
}
|
|
303
341
|
get pk() {
|
|
@@ -327,6 +365,9 @@ var Entity = class _Entity extends Item {
|
|
|
327
365
|
var _a;
|
|
328
366
|
return (_a = this._updatedAt) == null ? void 0 : _a.toISOString();
|
|
329
367
|
}
|
|
368
|
+
get expiresAt() {
|
|
369
|
+
return this._expiresAt ? Math.floor(this._expiresAt.getTime() / 1e3) : void 0;
|
|
370
|
+
}
|
|
330
371
|
toItem() {
|
|
331
372
|
return __spreadValues(__spreadValues({}, marshall2(this.toJSON(), { removeUndefinedValues: true })), this.keys());
|
|
332
373
|
}
|
|
@@ -336,7 +377,8 @@ var Entity = class _Entity extends Item {
|
|
|
336
377
|
entityId: this.entityId,
|
|
337
378
|
data: this.data,
|
|
338
379
|
createdAt: this.createdAt,
|
|
339
|
-
updatedAt: this.updatedAt
|
|
380
|
+
updatedAt: this.updatedAt,
|
|
381
|
+
expiresAt: this.expiresAt
|
|
340
382
|
};
|
|
341
383
|
}
|
|
342
384
|
};
|
|
@@ -348,6 +390,46 @@ var EntityRepository = class extends Repository {
|
|
|
348
390
|
this.dynamodbClient = dynamodbClient;
|
|
349
391
|
this.EmailAuthEnabledEntities = EmailAuthEnabledEntities;
|
|
350
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* Computes the `expiresAt` Date for an entity via its `ttl.processor` config, if any.
|
|
395
|
+
* When `mergeWithExisting` is true, the processor receives the previous entity's data
|
|
396
|
+
* merged with `incomingData` (falls back to `incomingData` alone if no previous entity
|
|
397
|
+
* exists yet, eg. an upsert-as-create).
|
|
398
|
+
*/
|
|
399
|
+
computeExpiresAt(entityType, entityId, incomingData, updatedAt, opts) {
|
|
400
|
+
return __async(this, null, function* () {
|
|
401
|
+
var _a, _b;
|
|
402
|
+
const processor = (_b = (_a = this.EntityConfig[entityType]) == null ? void 0 : _a.ttl) == null ? void 0 : _b.processor;
|
|
403
|
+
if (!processor) return void 0;
|
|
404
|
+
let data = incomingData;
|
|
405
|
+
let createdAt = updatedAt;
|
|
406
|
+
if (opts.mergeWithExisting) {
|
|
407
|
+
let previous = opts.previousEntity;
|
|
408
|
+
if (!previous) {
|
|
409
|
+
try {
|
|
410
|
+
previous = yield this.getEntity(entityType, entityId);
|
|
411
|
+
} catch (err) {
|
|
412
|
+
if (!(err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED)) {
|
|
413
|
+
throw err;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (previous) {
|
|
418
|
+
data = __spreadValues(__spreadValues({}, previous.data), incomingData);
|
|
419
|
+
createdAt = previous.createdAt || updatedAt;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const result = processor({
|
|
423
|
+
entityId,
|
|
424
|
+
entityType,
|
|
425
|
+
data,
|
|
426
|
+
createdAt,
|
|
427
|
+
updatedAt
|
|
428
|
+
});
|
|
429
|
+
if (result === void 0) return void 0;
|
|
430
|
+
return result instanceof Date ? result : new Date(result * 1e3);
|
|
431
|
+
});
|
|
432
|
+
}
|
|
351
433
|
listEntities(_0) {
|
|
352
434
|
return __async(this, arguments, function* ({
|
|
353
435
|
entityType,
|
|
@@ -571,12 +653,21 @@ var EntityRepository = class extends Repository {
|
|
|
571
653
|
return __async(this, null, function* () {
|
|
572
654
|
var _a, _b;
|
|
573
655
|
const currentDatetime = (_a = opts == null ? void 0 : opts.createAndUpdateDatetime) != null ? _a : /* @__PURE__ */ new Date();
|
|
656
|
+
const finalEntityId = entityId || ulid();
|
|
657
|
+
const expiresAt = yield this.computeExpiresAt(
|
|
658
|
+
entityType,
|
|
659
|
+
finalEntityId,
|
|
660
|
+
entityPayload,
|
|
661
|
+
currentDatetime.toISOString(),
|
|
662
|
+
{ mergeWithExisting: false }
|
|
663
|
+
);
|
|
574
664
|
const entity = new Entity(
|
|
575
665
|
entityType,
|
|
576
|
-
|
|
666
|
+
finalEntityId,
|
|
577
667
|
entityPayload,
|
|
578
668
|
currentDatetime,
|
|
579
|
-
currentDatetime
|
|
669
|
+
currentDatetime,
|
|
670
|
+
expiresAt
|
|
580
671
|
);
|
|
581
672
|
const uniqueFields = this.EntityConfig[entityType].uniqueFields || [];
|
|
582
673
|
const uniqueFieldValues = {};
|
|
@@ -621,26 +712,47 @@ var EntityRepository = class extends Repository {
|
|
|
621
712
|
upsertEntity(entityType, entityId, payload) {
|
|
622
713
|
return __async(this, null, function* () {
|
|
623
714
|
const currentDatetime = (/* @__PURE__ */ new Date()).toISOString();
|
|
624
|
-
const
|
|
715
|
+
const expiresAtForUpdate = yield this.computeExpiresAt(
|
|
716
|
+
entityType,
|
|
717
|
+
entityId,
|
|
718
|
+
payload,
|
|
719
|
+
currentDatetime,
|
|
720
|
+
{ mergeWithExisting: true }
|
|
721
|
+
);
|
|
722
|
+
const toUpdateExpressions = this.toUpdate(__spreadValues({
|
|
625
723
|
entityType,
|
|
626
724
|
entityId,
|
|
627
725
|
data: payload,
|
|
628
726
|
updatedAt: currentDatetime
|
|
629
|
-
}
|
|
727
|
+
}, expiresAtForUpdate && {
|
|
728
|
+
expiresAt: Math.floor(expiresAtForUpdate.getTime() / 1e3)
|
|
729
|
+
}));
|
|
630
730
|
const params = {
|
|
631
731
|
TableName: this.TABLE_NAME,
|
|
632
732
|
ReturnValues: "ALL_NEW",
|
|
733
|
+
ConditionExpression: "attribute_exists(PK)",
|
|
633
734
|
Key: new Entity(entityType, entityId).keys(),
|
|
634
735
|
UpdateExpression: toUpdateExpressions.UpdateExpression,
|
|
635
736
|
ExpressionAttributeNames: __spreadValues({}, toUpdateExpressions.ExpressionAttributeNames),
|
|
636
737
|
ExpressionAttributeValues: __spreadValues({}, toUpdateExpressions.ExpressionAttributeValues)
|
|
637
738
|
};
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
739
|
+
try {
|
|
740
|
+
const resp = yield this.dynamodbClient.updateItem(params);
|
|
741
|
+
return Entity.fromItem(resp.Attributes);
|
|
742
|
+
} catch (err) {
|
|
743
|
+
if (!(err instanceof ConditionalCheckFailedException)) {
|
|
744
|
+
throw err;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
return this.createEntity(
|
|
748
|
+
entityType,
|
|
749
|
+
payload,
|
|
750
|
+
entityId,
|
|
751
|
+
{ createAndUpdateDatetime: new Date(currentDatetime) }
|
|
752
|
+
);
|
|
641
753
|
});
|
|
642
754
|
}
|
|
643
|
-
updateEntityTransactItems(entity, updateParams, previousUniqueFieldValues, previousEntity) {
|
|
755
|
+
updateEntityTransactItems(entity, updateParams, previousUniqueFieldValues, previousEntity, expiresAt) {
|
|
644
756
|
const transactItems = [
|
|
645
757
|
{
|
|
646
758
|
Update: __spreadProps(__spreadValues({}, updateParams), {
|
|
@@ -663,7 +775,7 @@ var EntityRepository = class extends Repository {
|
|
|
663
775
|
Put: {
|
|
664
776
|
TableName: this.TABLE_NAME,
|
|
665
777
|
ConditionExpression: "attribute_not_exists(PK)",
|
|
666
|
-
Item: __spreadProps(__spreadValues({}, entity.toItem()), {
|
|
778
|
+
Item: __spreadValues(__spreadProps(__spreadValues({}, entity.toItem()), {
|
|
667
779
|
data: {
|
|
668
780
|
M: __spreadValues(__spreadValues({}, previousEntity.toItem().data.M), entity.toItem().data.M)
|
|
669
781
|
},
|
|
@@ -677,6 +789,10 @@ var EntityRepository = class extends Repository {
|
|
|
677
789
|
S: previousEntity.createdAt || entity.createdAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
678
790
|
},
|
|
679
791
|
updatedAt: { S: entity.updatedAt || (/* @__PURE__ */ new Date()).toISOString() }
|
|
792
|
+
}), expiresAt && {
|
|
793
|
+
expiresAt: {
|
|
794
|
+
N: String(Math.floor(expiresAt.getTime() / 1e3))
|
|
795
|
+
}
|
|
680
796
|
})
|
|
681
797
|
}
|
|
682
798
|
}
|
|
@@ -686,11 +802,42 @@ var EntityRepository = class extends Repository {
|
|
|
686
802
|
}
|
|
687
803
|
updateEntity(entityType, entityId, toUpdate, opts) {
|
|
688
804
|
return __async(this, null, function* () {
|
|
805
|
+
var _a, _b;
|
|
689
806
|
try {
|
|
690
807
|
const currentDatetime = (/* @__PURE__ */ new Date()).toISOString();
|
|
691
|
-
const
|
|
808
|
+
const uniqueFields = this.EntityConfig[entityType].uniqueFields || [];
|
|
809
|
+
const hasUniqueFields = Object.keys(toUpdate.data).some(
|
|
810
|
+
(field) => uniqueFields.includes(field)
|
|
811
|
+
);
|
|
812
|
+
const hasTtlProcessor = !!((_b = (_a = this.EntityConfig[entityType]) == null ? void 0 : _a.ttl) == null ? void 0 : _b.processor);
|
|
813
|
+
let previousEntity;
|
|
814
|
+
if (hasUniqueFields || hasTtlProcessor) {
|
|
815
|
+
try {
|
|
816
|
+
previousEntity = yield this.getEntity(entityType, entityId);
|
|
817
|
+
} catch (err) {
|
|
818
|
+
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
819
|
+
throw new StandardError(
|
|
820
|
+
StandardErrorCode.ENTITY_NOT_FOUND,
|
|
821
|
+
"Entity not found",
|
|
822
|
+
err,
|
|
823
|
+
{ entityId, toUpdate }
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
throw err;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
const expiresAtDate = yield this.computeExpiresAt(
|
|
830
|
+
entityType,
|
|
831
|
+
entityId,
|
|
832
|
+
toUpdate.data,
|
|
833
|
+
currentDatetime,
|
|
834
|
+
{ mergeWithExisting: true, previousEntity }
|
|
835
|
+
);
|
|
836
|
+
const toUpdateExpressions = this.toUpdate(__spreadValues(__spreadValues({
|
|
692
837
|
updatedAt: currentDatetime
|
|
693
|
-
}, toUpdate)
|
|
838
|
+
}, toUpdate), expiresAtDate && {
|
|
839
|
+
expiresAt: Math.floor(expiresAtDate.getTime() / 1e3)
|
|
840
|
+
}));
|
|
694
841
|
const params = {
|
|
695
842
|
TableName: this.TABLE_NAME,
|
|
696
843
|
ReturnValues: "ALL_NEW",
|
|
@@ -701,15 +848,9 @@ var EntityRepository = class extends Repository {
|
|
|
701
848
|
ExpressionAttributeValues: __spreadValues(__spreadValues({}, toUpdateExpressions.ExpressionAttributeValues), opts == null ? void 0 : opts.ExpressionAttributeValues)
|
|
702
849
|
};
|
|
703
850
|
const entity = new Entity(entityType, entityId, toUpdate.data);
|
|
704
|
-
const uniqueFields = this.EntityConfig[entityType].uniqueFields || [];
|
|
705
|
-
const hasUniqueFields = Object.keys(toUpdate.data).some(
|
|
706
|
-
(field) => uniqueFields.includes(field)
|
|
707
|
-
);
|
|
708
851
|
let updatedUniqueFields = [];
|
|
709
852
|
let previousUniqueFieldValues = {};
|
|
710
|
-
|
|
711
|
-
if (hasUniqueFields) {
|
|
712
|
-
previousEntity = yield this.getEntity(entityType, entityId);
|
|
853
|
+
if (hasUniqueFields && previousEntity) {
|
|
713
854
|
updatedUniqueFields = uniqueFields.filter(
|
|
714
855
|
(field) => toUpdate.data[field] !== void 0 && toUpdate.data[field] !== previousEntity.data[field]
|
|
715
856
|
);
|
|
@@ -728,11 +869,13 @@ var EntityRepository = class extends Repository {
|
|
|
728
869
|
}
|
|
729
870
|
}
|
|
730
871
|
if (updatedUniqueFields.length > 0) {
|
|
872
|
+
const effectiveExpiresAtDate = expiresAtDate != null ? expiresAtDate : previousEntity.expiresAt !== void 0 ? new Date(previousEntity.expiresAt * 1e3) : void 0;
|
|
731
873
|
const TransactItems = this.updateEntityTransactItems(
|
|
732
874
|
entity,
|
|
733
875
|
params,
|
|
734
876
|
previousUniqueFieldValues,
|
|
735
|
-
previousEntity
|
|
877
|
+
previousEntity,
|
|
878
|
+
effectiveExpiresAtDate
|
|
736
879
|
);
|
|
737
880
|
try {
|
|
738
881
|
yield this.dynamodbClient.transactWriteItems({ TransactItems });
|
|
@@ -767,7 +910,14 @@ var EntityRepository = class extends Repository {
|
|
|
767
910
|
}
|
|
768
911
|
throw err;
|
|
769
912
|
}
|
|
770
|
-
return
|
|
913
|
+
return new Entity(
|
|
914
|
+
entityType,
|
|
915
|
+
entityId,
|
|
916
|
+
__spreadValues(__spreadValues({}, previousEntity.data), toUpdate.data),
|
|
917
|
+
previousEntity.createdAt ? new Date(previousEntity.createdAt) : void 0,
|
|
918
|
+
new Date(currentDatetime),
|
|
919
|
+
effectiveExpiresAtDate
|
|
920
|
+
);
|
|
771
921
|
}
|
|
772
922
|
}
|
|
773
923
|
const resp = yield this.dynamodbClient.updateItem(params);
|
|
@@ -797,22 +947,22 @@ var EntityRepository = class extends Repository {
|
|
|
797
947
|
}
|
|
798
948
|
});
|
|
799
949
|
}
|
|
800
|
-
adjustEntity(entityType, entityId, adjustments,
|
|
950
|
+
adjustEntity(entityType, entityId, adjustments, constraints) {
|
|
801
951
|
return __async(this, null, function* () {
|
|
802
952
|
const entity = new Entity(entityType, entityId);
|
|
803
|
-
const { UpdateExpression, ExpressionAttributeNames, ExpressionAttributeValues } = this.toAdjustUpdate(adjustments);
|
|
953
|
+
const { UpdateExpression, ConditionExpression, ExpressionAttributeNames, ExpressionAttributeValues } = this.toAdjustUpdate(adjustments, constraints);
|
|
804
954
|
const updatedAtExpression = ", #updatedAt = :updatedAt";
|
|
805
955
|
ExpressionAttributeNames["#updatedAt"] = "updatedAt";
|
|
806
956
|
ExpressionAttributeValues[":updatedAt"] = { S: (/* @__PURE__ */ new Date()).toISOString() };
|
|
807
|
-
const resp = yield this.dynamodbClient.updateItem({
|
|
957
|
+
const resp = yield this.dynamodbClient.updateItem(__spreadProps(__spreadValues({
|
|
808
958
|
TableName: this.TABLE_NAME,
|
|
809
959
|
Key: entity.keys(),
|
|
810
|
-
UpdateExpression: UpdateExpression + updatedAtExpression
|
|
811
|
-
|
|
812
|
-
ExpressionAttributeNames
|
|
813
|
-
ExpressionAttributeValues
|
|
960
|
+
UpdateExpression: UpdateExpression + updatedAtExpression
|
|
961
|
+
}, ConditionExpression && { ConditionExpression }), {
|
|
962
|
+
ExpressionAttributeNames,
|
|
963
|
+
ExpressionAttributeValues,
|
|
814
964
|
ReturnValues: "ALL_NEW"
|
|
815
|
-
});
|
|
965
|
+
}));
|
|
816
966
|
return Entity.fromItem(resp.Attributes);
|
|
817
967
|
});
|
|
818
968
|
}
|
|
@@ -932,7 +1082,8 @@ var Mutual = class _Mutual {
|
|
|
932
1082
|
parsedItem.createdAt ? new Date(parsedItem.createdAt) : void 0,
|
|
933
1083
|
parsedItem.updatedAt ? new Date(parsedItem.updatedAt) : void 0,
|
|
934
1084
|
parsedItem.mutualUpdatedAt ? new Date(parsedItem.mutualUpdatedAt) : void 0,
|
|
935
|
-
|
|
1085
|
+
// expiresAt is stored as epoch seconds (DynamoDB TTL requires type N)
|
|
1086
|
+
parsedItem.expiresAt ? new Date(parsedItem.expiresAt * 1e3) : void 0
|
|
936
1087
|
);
|
|
937
1088
|
}
|
|
938
1089
|
mainKeys() {
|
|
@@ -975,8 +1126,7 @@ var Mutual = class _Mutual {
|
|
|
975
1126
|
return (_a = this._mutualUpdatedAt) == null ? void 0 : _a.toISOString();
|
|
976
1127
|
}
|
|
977
1128
|
get expiresAt() {
|
|
978
|
-
|
|
979
|
-
return (_a = this._expiresAt) == null ? void 0 : _a.toISOString();
|
|
1129
|
+
return this._expiresAt ? Math.floor(this._expiresAt.getTime() / 1e3) : void 0;
|
|
980
1130
|
}
|
|
981
1131
|
toItem() {
|
|
982
1132
|
return __spreadValues(__spreadValues({}, marshall3(this.toJSON(), { removeUndefinedValues: true })), this.mainKeys());
|
|
@@ -1075,14 +1225,7 @@ var MutualRepository = class extends Repository {
|
|
|
1075
1225
|
}
|
|
1076
1226
|
getMutual(byEntityType, byEntityId, entityType, entityId, opts) {
|
|
1077
1227
|
return __async(this, null, function* () {
|
|
1078
|
-
var _a, _b
|
|
1079
|
-
console.log("[MONORISE_DEBUG] getMutual start:", {
|
|
1080
|
-
byEntityType,
|
|
1081
|
-
byEntityId,
|
|
1082
|
-
entityType,
|
|
1083
|
-
entityId,
|
|
1084
|
-
opts
|
|
1085
|
-
});
|
|
1228
|
+
var _a, _b;
|
|
1086
1229
|
const mutual = new Mutual(
|
|
1087
1230
|
byEntityType,
|
|
1088
1231
|
byEntityId,
|
|
@@ -1092,11 +1235,6 @@ var MutualRepository = class extends Repository {
|
|
|
1092
1235
|
{},
|
|
1093
1236
|
{}
|
|
1094
1237
|
);
|
|
1095
|
-
console.log("[MONORISE_DEBUG] getMutual querying:", {
|
|
1096
|
-
byFullEntityId: mutual.byFullEntityId,
|
|
1097
|
-
fullEntityId: mutual.fullEntityId,
|
|
1098
|
-
tableName: this.TABLE_NAME
|
|
1099
|
-
});
|
|
1100
1238
|
const resp = yield this.dynamodbClient.query({
|
|
1101
1239
|
TableName: this.TABLE_NAME,
|
|
1102
1240
|
KeyConditionExpression: "#PK = :PK and begins_with(#SK, :SK)",
|
|
@@ -1113,14 +1251,9 @@ var MutualRepository = class extends Repository {
|
|
|
1113
1251
|
},
|
|
1114
1252
|
Limit: 1
|
|
1115
1253
|
});
|
|
1116
|
-
console.log("[MONORISE_DEBUG] getMutual query result:", {
|
|
1117
|
-
hasItems: !!((_a = resp.Items) == null ? void 0 : _a.length),
|
|
1118
|
-
itemCount: (_c = (_b = resp.Items) == null ? void 0 : _b.length) != null ? _c : 0,
|
|
1119
|
-
hasLastEvaluatedKey: !!resp.LastEvaluatedKey
|
|
1120
|
-
});
|
|
1121
1254
|
let mutualMetadata = null;
|
|
1122
1255
|
if (opts == null ? void 0 : opts.isFromMetadata) {
|
|
1123
|
-
const tempMutual = Mutual.fromItem((
|
|
1256
|
+
const tempMutual = Mutual.fromItem((_a = resp.Items) == null ? void 0 : _a[0]);
|
|
1124
1257
|
const respMetadataMutual = yield this.dynamodbClient.getItem({
|
|
1125
1258
|
TableName: this.TABLE_NAME,
|
|
1126
1259
|
Key: tempMutual.mainKeys(),
|
|
@@ -1128,28 +1261,12 @@ var MutualRepository = class extends Repository {
|
|
|
1128
1261
|
});
|
|
1129
1262
|
mutualMetadata = Mutual.fromItem(respMetadataMutual.Item);
|
|
1130
1263
|
}
|
|
1131
|
-
|
|
1132
|
-
hasMutualMetadata: !!mutualMetadata,
|
|
1133
|
-
hasFirstItem: !!((_e = resp.Items) == null ? void 0 : _e[0])
|
|
1134
|
-
});
|
|
1135
|
-
const result = mutualMetadata || Mutual.fromItem((_f = resp.Items) == null ? void 0 : _f[0]);
|
|
1136
|
-
console.log("[MONORISE_DEBUG] getMutual complete:", {
|
|
1137
|
-
mutualId: result.mutualId,
|
|
1138
|
-
byEntityType: result.byEntityType,
|
|
1139
|
-
entityType: result.entityType
|
|
1140
|
-
});
|
|
1141
|
-
return result;
|
|
1264
|
+
return mutualMetadata || Mutual.fromItem((_b = resp.Items) == null ? void 0 : _b[0]);
|
|
1142
1265
|
});
|
|
1143
1266
|
}
|
|
1144
1267
|
checkMutualExist(byEntityType, byEntityId, entityType, entityId) {
|
|
1145
1268
|
return __async(this, null, function* () {
|
|
1146
|
-
var _a
|
|
1147
|
-
console.log("[MONORISE_DEBUG] checkMutualExist:", {
|
|
1148
|
-
byEntityType,
|
|
1149
|
-
byEntityId,
|
|
1150
|
-
entityType,
|
|
1151
|
-
entityId
|
|
1152
|
-
});
|
|
1269
|
+
var _a;
|
|
1153
1270
|
const mutual = new Mutual(
|
|
1154
1271
|
byEntityType,
|
|
1155
1272
|
byEntityId,
|
|
@@ -1164,11 +1281,7 @@ var MutualRepository = class extends Repository {
|
|
|
1164
1281
|
Key: mutual.subKeys(),
|
|
1165
1282
|
ProjectionExpression: "PK, SK, expiresAt"
|
|
1166
1283
|
});
|
|
1167
|
-
|
|
1168
|
-
hasItem: !!resp.Item,
|
|
1169
|
-
hasExpiresAt: !!((_a = resp.Item) == null ? void 0 : _a.expiresAt)
|
|
1170
|
-
});
|
|
1171
|
-
if (resp.Item && !((_b = resp.Item) == null ? void 0 : _b.expiresAt)) {
|
|
1284
|
+
if (resp.Item && !((_a = resp.Item) == null ? void 0 : _a.expiresAt)) {
|
|
1172
1285
|
throw new StandardError(
|
|
1173
1286
|
StandardErrorCode.MUTUAL_EXISTS,
|
|
1174
1287
|
"Entities are already linked"
|
|
@@ -1178,14 +1291,6 @@ var MutualRepository = class extends Repository {
|
|
|
1178
1291
|
});
|
|
1179
1292
|
}
|
|
1180
1293
|
createMutualTransactItems(mutual, opts) {
|
|
1181
|
-
console.log("[MONORISE_DEBUG] createMutualTransactItems:", {
|
|
1182
|
-
mutualId: mutual.mutualId,
|
|
1183
|
-
byEntityType: mutual.byEntityType,
|
|
1184
|
-
byEntityId: mutual.byEntityId,
|
|
1185
|
-
entityType: mutual.entityType,
|
|
1186
|
-
entityId: mutual.entityId,
|
|
1187
|
-
hasOpts: !!opts
|
|
1188
|
-
});
|
|
1189
1294
|
const TransactItems = [
|
|
1190
1295
|
{
|
|
1191
1296
|
Put: {
|
|
@@ -1260,19 +1365,10 @@ var MutualRepository = class extends Repository {
|
|
|
1260
1365
|
}
|
|
1261
1366
|
updateMutual(byEntityType, byEntityId, entityType, entityId, toUpdate, opts) {
|
|
1262
1367
|
return __async(this, null, function* () {
|
|
1263
|
-
var _a
|
|
1264
|
-
console.log("[MONORISE_DEBUG] updateMutual repository start:", {
|
|
1265
|
-
byEntityType,
|
|
1266
|
-
byEntityId,
|
|
1267
|
-
entityType,
|
|
1268
|
-
entityId,
|
|
1269
|
-
toUpdateKeys: Object.keys(toUpdate),
|
|
1270
|
-
opts
|
|
1271
|
-
});
|
|
1368
|
+
var _a;
|
|
1272
1369
|
const returnUpdatedValue = (_a = opts == null ? void 0 : opts.returnUpdatedValue) != null ? _a : false;
|
|
1273
1370
|
const errorContext = {};
|
|
1274
1371
|
try {
|
|
1275
|
-
console.log("[MONORISE_DEBUG] updateMutual fetching mutual...");
|
|
1276
1372
|
const mutual = yield this.getMutual(
|
|
1277
1373
|
byEntityType,
|
|
1278
1374
|
byEntityId,
|
|
@@ -1280,12 +1376,6 @@ var MutualRepository = class extends Repository {
|
|
|
1280
1376
|
entityId,
|
|
1281
1377
|
{ ProjectionExpression: PROJECTION_EXPRESSION.NO_DATA }
|
|
1282
1378
|
);
|
|
1283
|
-
console.log("[MONORISE_DEBUG] updateMutual mutual found:", {
|
|
1284
|
-
mutualId: mutual.mutualId,
|
|
1285
|
-
mainPk: mutual.mainPk,
|
|
1286
|
-
byFullEntityId: mutual.byFullEntityId,
|
|
1287
|
-
fullEntityId: mutual.fullEntityId
|
|
1288
|
-
});
|
|
1289
1379
|
const currentDatetime = (/* @__PURE__ */ new Date()).toISOString();
|
|
1290
1380
|
const toUpdateExpressions = this.toUpdate(
|
|
1291
1381
|
__spreadValues({
|
|
@@ -1293,11 +1383,6 @@ var MutualRepository = class extends Repository {
|
|
|
1293
1383
|
}, toUpdate),
|
|
1294
1384
|
{ maxLevel: opts == null ? void 0 : opts.maxObjectUpdateLevel }
|
|
1295
1385
|
);
|
|
1296
|
-
console.log("[MONORISE_DEBUG] updateMutual update expression:", {
|
|
1297
|
-
UpdateExpression: toUpdateExpressions.UpdateExpression,
|
|
1298
|
-
ExpressionAttributeNames: toUpdateExpressions.ExpressionAttributeNames,
|
|
1299
|
-
hasExpressionAttributeValues: !!toUpdateExpressions.ExpressionAttributeValues
|
|
1300
|
-
});
|
|
1301
1386
|
const updateExpression = {
|
|
1302
1387
|
ConditionExpression: (opts == null ? void 0 : opts.ConditionExpression) || "attribute_exists(PK)",
|
|
1303
1388
|
UpdateExpression: toUpdateExpressions.UpdateExpression,
|
|
@@ -1331,33 +1416,18 @@ var MutualRepository = class extends Repository {
|
|
|
1331
1416
|
}
|
|
1332
1417
|
];
|
|
1333
1418
|
errorContext.TransactItems = TransactItems;
|
|
1334
|
-
console.log("[MONORISE_DEBUG] updateMutual transact items prepared:", {
|
|
1335
|
-
itemCount: TransactItems.length,
|
|
1336
|
-
tableName: this.TABLE_NAME
|
|
1337
|
-
});
|
|
1338
|
-
console.log("[MONORISE_DEBUG] updateMutual executing transaction...");
|
|
1339
1419
|
yield this.ddbUtils.executeTransactWrite({ TransactItems });
|
|
1340
|
-
console.log("[MONORISE_DEBUG] updateMutual transaction succeeded");
|
|
1341
1420
|
if (!returnUpdatedValue) {
|
|
1342
|
-
console.log("[MONORISE_DEBUG] updateMutual returning (no value)");
|
|
1343
1421
|
return;
|
|
1344
1422
|
}
|
|
1345
|
-
console.log("[MONORISE_DEBUG] updateMutual fetching updated mutual...");
|
|
1346
1423
|
const updatedMutual = yield this.getMutual(
|
|
1347
1424
|
byEntityType,
|
|
1348
1425
|
byEntityId,
|
|
1349
1426
|
entityType,
|
|
1350
1427
|
entityId
|
|
1351
1428
|
);
|
|
1352
|
-
console.log("[MONORISE_DEBUG] updateMutual repository complete");
|
|
1353
1429
|
return updatedMutual;
|
|
1354
1430
|
} catch (err) {
|
|
1355
|
-
console.error("[MONORISE_DEBUG] updateMutual repository error:", {
|
|
1356
|
-
errorName: (_b = err == null ? void 0 : err.constructor) == null ? void 0 : _b.name,
|
|
1357
|
-
errorMessage: err == null ? void 0 : err.message,
|
|
1358
|
-
errorCode: err == null ? void 0 : err.code,
|
|
1359
|
-
isStandardError: err instanceof StandardError
|
|
1360
|
-
});
|
|
1361
1431
|
if (err instanceof StandardError && err.code === StandardErrorCode.CONDITIONAL_CHECK_FAILED) {
|
|
1362
1432
|
throw new StandardError(
|
|
1363
1433
|
StandardErrorCode.MUTUAL_NOT_FOUND,
|
|
@@ -1902,217 +1972,6 @@ var TagRepository = class extends Repository {
|
|
|
1902
1972
|
}
|
|
1903
1973
|
};
|
|
1904
1974
|
|
|
1905
|
-
// data/WebSocket.ts
|
|
1906
|
-
import {
|
|
1907
|
-
DeleteCommand,
|
|
1908
|
-
DynamoDBDocumentClient,
|
|
1909
|
-
PutCommand,
|
|
1910
|
-
QueryCommand
|
|
1911
|
-
} from "@aws-sdk/lib-dynamodb";
|
|
1912
|
-
var WebSocketRepository = class extends Repository {
|
|
1913
|
-
constructor(tableName, dynamodbClient) {
|
|
1914
|
-
super();
|
|
1915
|
-
this.tableName = tableName;
|
|
1916
|
-
this.dynamodbClient = dynamodbClient;
|
|
1917
|
-
this.docClient = DynamoDBDocumentClient.from(dynamodbClient);
|
|
1918
|
-
}
|
|
1919
|
-
createConnection(connectionId, metadata, expiresAt) {
|
|
1920
|
-
return __async(this, null, function* () {
|
|
1921
|
-
yield this.docClient.send(
|
|
1922
|
-
new PutCommand({
|
|
1923
|
-
TableName: this.tableName,
|
|
1924
|
-
Item: __spreadProps(__spreadValues({
|
|
1925
|
-
PK: `CONN#${connectionId}`,
|
|
1926
|
-
SK: "#METADATA#",
|
|
1927
|
-
connectionId
|
|
1928
|
-
}, metadata), {
|
|
1929
|
-
expiresAt
|
|
1930
|
-
})
|
|
1931
|
-
})
|
|
1932
|
-
);
|
|
1933
|
-
});
|
|
1934
|
-
}
|
|
1935
|
-
getConnection(connectionId) {
|
|
1936
|
-
return __async(this, null, function* () {
|
|
1937
|
-
var _a;
|
|
1938
|
-
const result = yield this.docClient.send(
|
|
1939
|
-
new QueryCommand({
|
|
1940
|
-
TableName: this.tableName,
|
|
1941
|
-
KeyConditionExpression: "PK = :pk",
|
|
1942
|
-
ExpressionAttributeValues: {
|
|
1943
|
-
":pk": `CONN#${connectionId}`
|
|
1944
|
-
}
|
|
1945
|
-
})
|
|
1946
|
-
);
|
|
1947
|
-
return (_a = result.Items) == null ? void 0 : _a[0];
|
|
1948
|
-
});
|
|
1949
|
-
}
|
|
1950
|
-
deleteConnection(connectionId) {
|
|
1951
|
-
return __async(this, null, function* () {
|
|
1952
|
-
yield this.docClient.send(
|
|
1953
|
-
new DeleteCommand({
|
|
1954
|
-
TableName: this.tableName,
|
|
1955
|
-
Key: {
|
|
1956
|
-
PK: `CONN#${connectionId}`,
|
|
1957
|
-
SK: "#METADATA#"
|
|
1958
|
-
}
|
|
1959
|
-
})
|
|
1960
|
-
);
|
|
1961
|
-
});
|
|
1962
|
-
}
|
|
1963
|
-
createSubscription(subKey, connectionId, data) {
|
|
1964
|
-
return __async(this, null, function* () {
|
|
1965
|
-
yield this.docClient.send(
|
|
1966
|
-
new PutCommand({
|
|
1967
|
-
TableName: this.tableName,
|
|
1968
|
-
Item: __spreadValues({
|
|
1969
|
-
PK: subKey,
|
|
1970
|
-
SK: `CONN#${connectionId}`,
|
|
1971
|
-
R1PK: `CONN#${connectionId}`,
|
|
1972
|
-
R1SK: subKey,
|
|
1973
|
-
connectionId
|
|
1974
|
-
}, data)
|
|
1975
|
-
})
|
|
1976
|
-
);
|
|
1977
|
-
});
|
|
1978
|
-
}
|
|
1979
|
-
deleteSubscription(subKey, connectionId) {
|
|
1980
|
-
return __async(this, null, function* () {
|
|
1981
|
-
yield this.docClient.send(
|
|
1982
|
-
new DeleteCommand({
|
|
1983
|
-
TableName: this.tableName,
|
|
1984
|
-
Key: {
|
|
1985
|
-
PK: subKey,
|
|
1986
|
-
SK: `CONN#${connectionId}`
|
|
1987
|
-
}
|
|
1988
|
-
})
|
|
1989
|
-
);
|
|
1990
|
-
});
|
|
1991
|
-
}
|
|
1992
|
-
querySubscriptionsByKey(subKey) {
|
|
1993
|
-
return __async(this, null, function* () {
|
|
1994
|
-
const result = yield this.docClient.send(
|
|
1995
|
-
new QueryCommand({
|
|
1996
|
-
TableName: this.tableName,
|
|
1997
|
-
KeyConditionExpression: "PK = :pk",
|
|
1998
|
-
ExpressionAttributeValues: {
|
|
1999
|
-
":pk": subKey
|
|
2000
|
-
},
|
|
2001
|
-
ConsistentRead: true
|
|
2002
|
-
})
|
|
2003
|
-
);
|
|
2004
|
-
return result.Items || [];
|
|
2005
|
-
});
|
|
2006
|
-
}
|
|
2007
|
-
querySubscriptionsByConnectionId(connectionId) {
|
|
2008
|
-
return __async(this, null, function* () {
|
|
2009
|
-
const { ENTITY_REPLICATION_INDEX: ENTITY_REPLICATION_INDEX2 } = yield import("./service.config-ZJEZ6EKA.js");
|
|
2010
|
-
const result = yield this.docClient.send(
|
|
2011
|
-
new QueryCommand({
|
|
2012
|
-
TableName: this.tableName,
|
|
2013
|
-
IndexName: ENTITY_REPLICATION_INDEX2,
|
|
2014
|
-
KeyConditionExpression: "R1PK = :r1pk",
|
|
2015
|
-
ExpressionAttributeValues: {
|
|
2016
|
-
":r1pk": `CONN#${connectionId}`
|
|
2017
|
-
}
|
|
2018
|
-
})
|
|
2019
|
-
);
|
|
2020
|
-
return result.Items || [];
|
|
2021
|
-
});
|
|
2022
|
-
}
|
|
2023
|
-
createTicket(ticket, entityType, entityId, feedTypes, expiresAt) {
|
|
2024
|
-
return __async(this, null, function* () {
|
|
2025
|
-
yield this.docClient.send(
|
|
2026
|
-
new PutCommand({
|
|
2027
|
-
TableName: this.tableName,
|
|
2028
|
-
Item: {
|
|
2029
|
-
PK: `TICKET#${ticket}`,
|
|
2030
|
-
SK: "#METADATA#",
|
|
2031
|
-
entityType,
|
|
2032
|
-
entityId,
|
|
2033
|
-
feedTypes,
|
|
2034
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2035
|
-
expiresAt
|
|
2036
|
-
}
|
|
2037
|
-
})
|
|
2038
|
-
);
|
|
2039
|
-
});
|
|
2040
|
-
}
|
|
2041
|
-
consumeTicket(ticket) {
|
|
2042
|
-
return __async(this, null, function* () {
|
|
2043
|
-
try {
|
|
2044
|
-
const result = yield this.docClient.send(
|
|
2045
|
-
new DeleteCommand({
|
|
2046
|
-
TableName: this.tableName,
|
|
2047
|
-
Key: {
|
|
2048
|
-
PK: `TICKET#${ticket}`,
|
|
2049
|
-
SK: "#METADATA#"
|
|
2050
|
-
},
|
|
2051
|
-
ConditionExpression: "attribute_exists(PK)",
|
|
2052
|
-
ReturnValues: "ALL_OLD"
|
|
2053
|
-
})
|
|
2054
|
-
);
|
|
2055
|
-
const item = result.Attributes;
|
|
2056
|
-
if (!item) return null;
|
|
2057
|
-
const expiresAt = item.expiresAt;
|
|
2058
|
-
if (expiresAt && expiresAt < Math.floor(Date.now() / 1e3)) {
|
|
2059
|
-
return null;
|
|
2060
|
-
}
|
|
2061
|
-
return {
|
|
2062
|
-
entityType: item.entityType,
|
|
2063
|
-
entityId: item.entityId,
|
|
2064
|
-
feedTypes: item.feedTypes || []
|
|
2065
|
-
};
|
|
2066
|
-
} catch (error) {
|
|
2067
|
-
if (error instanceof Error && error.name === "ConditionalCheckFailedException") {
|
|
2068
|
-
return null;
|
|
2069
|
-
}
|
|
2070
|
-
throw error;
|
|
2071
|
-
}
|
|
2072
|
-
});
|
|
2073
|
-
}
|
|
2074
|
-
queryMutualConnections(byEntityType, byEntityId) {
|
|
2075
|
-
return __async(this, null, function* () {
|
|
2076
|
-
const result = yield this.docClient.send(
|
|
2077
|
-
new QueryCommand({
|
|
2078
|
-
TableName: this.tableName,
|
|
2079
|
-
KeyConditionExpression: "PK = :pk",
|
|
2080
|
-
ExpressionAttributeValues: {
|
|
2081
|
-
":pk": `${byEntityType}#${byEntityId}`
|
|
2082
|
-
},
|
|
2083
|
-
ProjectionExpression: "SK",
|
|
2084
|
-
ConsistentRead: true
|
|
2085
|
-
})
|
|
2086
|
-
);
|
|
2087
|
-
const connections = [];
|
|
2088
|
-
for (const item of result.Items || []) {
|
|
2089
|
-
const sk = item.SK;
|
|
2090
|
-
if (!sk || sk === "#METADATA#" || sk.startsWith("#")) continue;
|
|
2091
|
-
const parts = sk.split("#");
|
|
2092
|
-
if (parts.length >= 2) {
|
|
2093
|
-
connections.push({ entityType: parts[0], entityId: parts[1] });
|
|
2094
|
-
}
|
|
2095
|
-
}
|
|
2096
|
-
return connections;
|
|
2097
|
-
});
|
|
2098
|
-
}
|
|
2099
|
-
queryFeedSubscriptions(entityType, entityId) {
|
|
2100
|
-
return __async(this, null, function* () {
|
|
2101
|
-
const result = yield this.docClient.send(
|
|
2102
|
-
new QueryCommand({
|
|
2103
|
-
TableName: this.tableName,
|
|
2104
|
-
KeyConditionExpression: "PK = :pk",
|
|
2105
|
-
ExpressionAttributeValues: {
|
|
2106
|
-
":pk": `SUB#FEED#${entityType}#${entityId}`
|
|
2107
|
-
},
|
|
2108
|
-
ConsistentRead: true
|
|
2109
|
-
})
|
|
2110
|
-
);
|
|
2111
|
-
return result.Items || [];
|
|
2112
|
-
});
|
|
2113
|
-
}
|
|
2114
|
-
};
|
|
2115
|
-
|
|
2116
1975
|
// handles/app.ts
|
|
2117
1976
|
import { Hono as Hono2 } from "hono";
|
|
2118
1977
|
import { handle } from "hono/aws-lambda";
|
|
@@ -2152,6 +2011,14 @@ import {
|
|
|
2152
2011
|
PutEventsCommand
|
|
2153
2012
|
} from "@aws-sdk/client-eventbridge";
|
|
2154
2013
|
|
|
2014
|
+
// constants/table.ts
|
|
2015
|
+
var ENTITY_REPLICATION_INDEX = "ENTITY_REPLICATION_INDEX";
|
|
2016
|
+
var MUTUAL_REPLICATION_INDEX = "MUTUAL_REPLICATION_INDEX";
|
|
2017
|
+
|
|
2018
|
+
// configs/service.config.ts
|
|
2019
|
+
var CORE_TABLE = process.env.CORE_TABLE || "";
|
|
2020
|
+
var CORE_EVENT_BUS = process.env.CORE_EVENT_BUS || "";
|
|
2021
|
+
|
|
2155
2022
|
// types/event.ts
|
|
2156
2023
|
var SOURCE = {
|
|
2157
2024
|
CORE: "core-service",
|
|
@@ -2295,7 +2162,6 @@ var getDependencies = () => {
|
|
|
2295
2162
|
// middlewares/general-error-handler.ts
|
|
2296
2163
|
var factory2 = createFactory2();
|
|
2297
2164
|
var generalErrorHandler = (dependencies = getDependencies()) => factory2.createMiddleware((c) => __async(null, null, function* () {
|
|
2298
|
-
var _a, _b, _c, _d;
|
|
2299
2165
|
if (c.error) {
|
|
2300
2166
|
const { nanoid: nanoid2, publishErrorEvent: publishErrorEvent2 } = dependencies;
|
|
2301
2167
|
const errorId = nanoid2();
|
|
@@ -2308,21 +2174,12 @@ var generalErrorHandler = (dependencies = getDependencies()) => factory2.createM
|
|
|
2308
2174
|
body,
|
|
2309
2175
|
error: c.error
|
|
2310
2176
|
});
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
errorMessage: error == null ? void 0 : error.message,
|
|
2318
|
-
errorCode: error == null ? void 0 : error.code,
|
|
2319
|
-
errorStack: error == null ? void 0 : error.stack,
|
|
2320
|
-
errorConstructor: (_a = error == null ? void 0 : error.constructor) == null ? void 0 : _a.name,
|
|
2321
|
-
hasLastError: !!(error == null ? void 0 : error.lastError),
|
|
2322
|
-
lastErrorName: (_c = (_b = error == null ? void 0 : error.lastError) == null ? void 0 : _b.constructor) == null ? void 0 : _c.name,
|
|
2323
|
-
lastErrorMessage: (_d = error == null ? void 0 : error.lastError) == null ? void 0 : _d.message,
|
|
2324
|
-
context: error == null ? void 0 : error.context
|
|
2325
|
-
});
|
|
2177
|
+
console.warn(
|
|
2178
|
+
JSON.stringify({
|
|
2179
|
+
message: "INTERNAL_SERVER_EXCEPTION",
|
|
2180
|
+
details: c.error
|
|
2181
|
+
})
|
|
2182
|
+
);
|
|
2326
2183
|
c.status(500);
|
|
2327
2184
|
c.json({
|
|
2328
2185
|
code: "INTERNAL_SERVER_EXCEPTION",
|
|
@@ -2405,7 +2262,7 @@ var handler2 = (container) => (ev) => __async(null, null, function* () {
|
|
|
2405
2262
|
const { entityRepository, mutualRepository, publishEvent: publishEvent2 } = container;
|
|
2406
2263
|
yield Promise.allSettled(
|
|
2407
2264
|
ev.Records.map((record) => __async(null, null, function* () {
|
|
2408
|
-
var _a, _b, _c, _d
|
|
2265
|
+
var _a, _b, _c, _d;
|
|
2409
2266
|
const errorContext = {};
|
|
2410
2267
|
const body = parseSQSBusEvent(record.body);
|
|
2411
2268
|
const { detail } = body;
|
|
@@ -2428,7 +2285,6 @@ var handler2 = (container) => (ev) => __async(null, null, function* () {
|
|
|
2428
2285
|
);
|
|
2429
2286
|
}
|
|
2430
2287
|
const mutualDataProcessor = (_d = config.mutualDataProcessor) != null ? _d : (() => ({}));
|
|
2431
|
-
const mutualDataSchema = (_e = config.mutual) == null ? void 0 : _e.mutualDataSchema;
|
|
2432
2288
|
yield mutualRepository.createMutualLock({
|
|
2433
2289
|
byEntityType,
|
|
2434
2290
|
byEntityId,
|
|
@@ -2464,20 +2320,6 @@ var handler2 = (container) => (ev) => __async(null, null, function* () {
|
|
|
2464
2320
|
addedEntityIds,
|
|
2465
2321
|
(id) => __async(null, null, function* () {
|
|
2466
2322
|
const entity = yield entityRepository.getEntity(entityType, id);
|
|
2467
|
-
const processedMutualData = mutualDataProcessor(
|
|
2468
|
-
mutualIds,
|
|
2469
|
-
new Mutual(
|
|
2470
|
-
byEntityType,
|
|
2471
|
-
byEntityId,
|
|
2472
|
-
byEntity.data,
|
|
2473
|
-
entityType,
|
|
2474
|
-
id,
|
|
2475
|
-
entity.data,
|
|
2476
|
-
{}
|
|
2477
|
-
),
|
|
2478
|
-
customContext
|
|
2479
|
-
);
|
|
2480
|
-
const parsedMutualData = mutualDataSchema ? mutualDataSchema.parse(processedMutualData) : processedMutualData;
|
|
2481
2323
|
yield mutualRepository.createMutual(
|
|
2482
2324
|
byEntityType,
|
|
2483
2325
|
byEntityId,
|
|
@@ -2485,7 +2327,19 @@ var handler2 = (container) => (ev) => __async(null, null, function* () {
|
|
|
2485
2327
|
entityType,
|
|
2486
2328
|
id,
|
|
2487
2329
|
entity.data,
|
|
2488
|
-
|
|
2330
|
+
mutualDataProcessor(
|
|
2331
|
+
mutualIds,
|
|
2332
|
+
new Mutual(
|
|
2333
|
+
byEntityType,
|
|
2334
|
+
byEntityId,
|
|
2335
|
+
byEntity.data,
|
|
2336
|
+
entityType,
|
|
2337
|
+
id,
|
|
2338
|
+
entity.data,
|
|
2339
|
+
{}
|
|
2340
|
+
),
|
|
2341
|
+
customContext
|
|
2342
|
+
),
|
|
2489
2343
|
{
|
|
2490
2344
|
ConditionExpression: "attribute_not_exists(#mutualUpdatedAt) OR #mutualUpdatedAt < :publishedAt",
|
|
2491
2345
|
ExpressionAttributeNames: {
|
|
@@ -2522,27 +2376,25 @@ var handler2 = (container) => (ev) => __async(null, null, function* () {
|
|
|
2522
2376
|
const updateEntities = yield processEntities(
|
|
2523
2377
|
toUpdateEntityIds,
|
|
2524
2378
|
(id) => __async(null, null, function* () {
|
|
2525
|
-
const processedMutualData = mutualDataProcessor(
|
|
2526
|
-
mutualIds,
|
|
2527
|
-
new Mutual(
|
|
2528
|
-
byEntityType,
|
|
2529
|
-
byEntityId,
|
|
2530
|
-
byEntity.data,
|
|
2531
|
-
entityType,
|
|
2532
|
-
id,
|
|
2533
|
-
{},
|
|
2534
|
-
{}
|
|
2535
|
-
),
|
|
2536
|
-
customContext
|
|
2537
|
-
);
|
|
2538
|
-
const parsedMutualData = mutualDataSchema ? mutualDataSchema.parse(processedMutualData) : processedMutualData;
|
|
2539
2379
|
yield mutualRepository.updateMutual(
|
|
2540
2380
|
byEntityType,
|
|
2541
2381
|
byEntityId,
|
|
2542
2382
|
entityType,
|
|
2543
2383
|
id,
|
|
2544
2384
|
{
|
|
2545
|
-
mutualData:
|
|
2385
|
+
mutualData: mutualDataProcessor(
|
|
2386
|
+
mutualIds,
|
|
2387
|
+
new Mutual(
|
|
2388
|
+
byEntityType,
|
|
2389
|
+
byEntityId,
|
|
2390
|
+
byEntity.data,
|
|
2391
|
+
entityType,
|
|
2392
|
+
id,
|
|
2393
|
+
{},
|
|
2394
|
+
{}
|
|
2395
|
+
),
|
|
2396
|
+
customContext
|
|
2397
|
+
),
|
|
2546
2398
|
mutualUpdatedAt: publishedAt
|
|
2547
2399
|
},
|
|
2548
2400
|
{
|
|
@@ -3118,458 +2970,6 @@ var handler5 = (container) => (ev) => __async(null, null, function* () {
|
|
|
3118
2970
|
return { batchItemFailures };
|
|
3119
2971
|
});
|
|
3120
2972
|
|
|
3121
|
-
// processors/websocket-processor.ts
|
|
3122
|
-
import {
|
|
3123
|
-
ApiGatewayManagementApiClient,
|
|
3124
|
-
PostToConnectionCommand
|
|
3125
|
-
} from "@aws-sdk/client-apigatewaymanagementapi";
|
|
3126
|
-
import { unmarshall as unmarshall4 } from "@aws-sdk/util-dynamodb";
|
|
3127
|
-
import { ulid as ulid3 } from "ulid";
|
|
3128
|
-
var SUB_ENTITY_TYPE = "SUB#ENTITY#";
|
|
3129
|
-
var SUB_MUTUAL_TYPE = "SUB#MUTUAL#";
|
|
3130
|
-
var SUB_EPHEMERAL = "SUB#EPHEMERAL#";
|
|
3131
|
-
var SUB_FEED = "SUB#FEED#";
|
|
3132
|
-
var getWsEndpoint = () => process.env.WEBSOCKET_MANAGEMENT_ENDPOINT || "";
|
|
3133
|
-
var connect = (container) => (event) => __async(null, null, function* () {
|
|
3134
|
-
var _a, _b, _c, _d;
|
|
3135
|
-
const connectionId = event.requestContext.connectionId;
|
|
3136
|
-
if (!connectionId) {
|
|
3137
|
-
return { statusCode: 400, body: "Missing connection ID" };
|
|
3138
|
-
}
|
|
3139
|
-
const expiresAt = Math.floor(Date.now() / 1e3) + 2 * 60 * 60;
|
|
3140
|
-
const ticket = (_a = event.queryStringParameters) == null ? void 0 : _a.ticket;
|
|
3141
|
-
const token = ((_b = event.queryStringParameters) == null ? void 0 : _b.token) || ((_c = event.headers) == null ? void 0 : _c.authorization) || ((_d = event.headers) == null ? void 0 : _d.Authorization);
|
|
3142
|
-
if (!ticket && !token) {
|
|
3143
|
-
return { statusCode: 401, body: "Unauthorized" };
|
|
3144
|
-
}
|
|
3145
|
-
const wsRepo = container.websocketRepository;
|
|
3146
|
-
try {
|
|
3147
|
-
let entityType;
|
|
3148
|
-
let entityId;
|
|
3149
|
-
let feedTypes;
|
|
3150
|
-
if (ticket) {
|
|
3151
|
-
const ticketData = yield wsRepo.consumeTicket(ticket);
|
|
3152
|
-
if (!ticketData) {
|
|
3153
|
-
return { statusCode: 401, body: "Invalid or expired ticket" };
|
|
3154
|
-
}
|
|
3155
|
-
entityType = ticketData.entityType;
|
|
3156
|
-
entityId = ticketData.entityId;
|
|
3157
|
-
feedTypes = ticketData.feedTypes;
|
|
3158
|
-
} else {
|
|
3159
|
-
entityId = token;
|
|
3160
|
-
}
|
|
3161
|
-
yield wsRepo.createConnection(
|
|
3162
|
-
connectionId,
|
|
3163
|
-
__spreadProps(__spreadValues(__spreadValues({}, entityType && { entityType }), entityId && { entityId }), {
|
|
3164
|
-
connectedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3165
|
-
}),
|
|
3166
|
-
expiresAt
|
|
3167
|
-
);
|
|
3168
|
-
if (entityType && entityId && feedTypes) {
|
|
3169
|
-
yield wsRepo.createSubscription(
|
|
3170
|
-
`${SUB_FEED}${entityType}#${entityId}`,
|
|
3171
|
-
connectionId,
|
|
3172
|
-
{
|
|
3173
|
-
subscriptionType: "feed",
|
|
3174
|
-
entityType,
|
|
3175
|
-
entityId,
|
|
3176
|
-
feedTypes,
|
|
3177
|
-
subscribedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3178
|
-
expiresAt
|
|
3179
|
-
}
|
|
3180
|
-
);
|
|
3181
|
-
}
|
|
3182
|
-
return { statusCode: 200, body: "Connected" };
|
|
3183
|
-
} catch (error) {
|
|
3184
|
-
console.error("Error in $connect:", error);
|
|
3185
|
-
return { statusCode: 500, body: "Failed to connect" };
|
|
3186
|
-
}
|
|
3187
|
-
});
|
|
3188
|
-
var disconnect = (container) => (event) => __async(null, null, function* () {
|
|
3189
|
-
const connectionId = event.requestContext.connectionId;
|
|
3190
|
-
if (!connectionId) {
|
|
3191
|
-
return { statusCode: 400, body: "Missing connection ID" };
|
|
3192
|
-
}
|
|
3193
|
-
const wsRepo = container.websocketRepository;
|
|
3194
|
-
try {
|
|
3195
|
-
const subscriptions = yield wsRepo.querySubscriptionsByConnectionId(connectionId);
|
|
3196
|
-
const deletePromises = [];
|
|
3197
|
-
for (const item of subscriptions) {
|
|
3198
|
-
if (item.PK && item.SK) {
|
|
3199
|
-
deletePromises.push(
|
|
3200
|
-
wsRepo.deleteSubscription(item.PK, item.connectionId).catch(
|
|
3201
|
-
(e) => console.warn("Failed to delete subscription on disconnect:", e)
|
|
3202
|
-
)
|
|
3203
|
-
);
|
|
3204
|
-
}
|
|
3205
|
-
}
|
|
3206
|
-
deletePromises.push(wsRepo.deleteConnection(connectionId));
|
|
3207
|
-
yield Promise.all(deletePromises);
|
|
3208
|
-
return { statusCode: 200, body: "Disconnected" };
|
|
3209
|
-
} catch (error) {
|
|
3210
|
-
console.error("Error cleaning up connection:", error);
|
|
3211
|
-
return { statusCode: 500, body: "Failed to disconnect" };
|
|
3212
|
-
}
|
|
3213
|
-
});
|
|
3214
|
-
var $default = (container) => (event) => __async(null, null, function* () {
|
|
3215
|
-
const connectionId = event.requestContext.connectionId;
|
|
3216
|
-
if (!connectionId || !event.body) {
|
|
3217
|
-
return { statusCode: 400, body: "Invalid message" };
|
|
3218
|
-
}
|
|
3219
|
-
let message;
|
|
3220
|
-
try {
|
|
3221
|
-
message = JSON.parse(event.body);
|
|
3222
|
-
} catch (e) {
|
|
3223
|
-
return { statusCode: 400, body: "Invalid JSON" };
|
|
3224
|
-
}
|
|
3225
|
-
const wsRepo = container.websocketRepository;
|
|
3226
|
-
const wsEndpoint = getWsEndpoint();
|
|
3227
|
-
const managementApi = new ApiGatewayManagementApiClient({
|
|
3228
|
-
endpoint: wsEndpoint
|
|
3229
|
-
});
|
|
3230
|
-
try {
|
|
3231
|
-
switch (message.action) {
|
|
3232
|
-
case "subscribe": {
|
|
3233
|
-
const {
|
|
3234
|
-
entityType,
|
|
3235
|
-
byEntityType,
|
|
3236
|
-
byEntityId,
|
|
3237
|
-
mutualEntityType,
|
|
3238
|
-
channel
|
|
3239
|
-
} = message.payload;
|
|
3240
|
-
if (entityType && !byEntityType) {
|
|
3241
|
-
yield wsRepo.createSubscription(
|
|
3242
|
-
`${SUB_ENTITY_TYPE}${entityType}`,
|
|
3243
|
-
connectionId,
|
|
3244
|
-
{
|
|
3245
|
-
subscriptionType: "entity-type",
|
|
3246
|
-
entityType,
|
|
3247
|
-
subscribedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3248
|
-
}
|
|
3249
|
-
);
|
|
3250
|
-
} else if (byEntityType && byEntityId && mutualEntityType) {
|
|
3251
|
-
yield wsRepo.createSubscription(
|
|
3252
|
-
`${SUB_MUTUAL_TYPE}${byEntityType}#${byEntityId}#${mutualEntityType}`,
|
|
3253
|
-
connectionId,
|
|
3254
|
-
{
|
|
3255
|
-
subscriptionType: "mutual-type",
|
|
3256
|
-
byEntityType,
|
|
3257
|
-
byEntityId,
|
|
3258
|
-
entityType: mutualEntityType,
|
|
3259
|
-
subscribedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3260
|
-
}
|
|
3261
|
-
);
|
|
3262
|
-
} else if (channel) {
|
|
3263
|
-
yield wsRepo.createSubscription(
|
|
3264
|
-
`${SUB_EPHEMERAL}${channel}`,
|
|
3265
|
-
connectionId,
|
|
3266
|
-
{
|
|
3267
|
-
subscriptionType: "ephemeral",
|
|
3268
|
-
channel,
|
|
3269
|
-
subscribedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3270
|
-
}
|
|
3271
|
-
);
|
|
3272
|
-
} else {
|
|
3273
|
-
return { statusCode: 400, body: "Invalid subscription parameters" };
|
|
3274
|
-
}
|
|
3275
|
-
const ackMessage = {
|
|
3276
|
-
type: "ack",
|
|
3277
|
-
id: message.id,
|
|
3278
|
-
payload: { action: "subscribe", success: true }
|
|
3279
|
-
};
|
|
3280
|
-
yield managementApi.send(
|
|
3281
|
-
new PostToConnectionCommand({
|
|
3282
|
-
ConnectionId: connectionId,
|
|
3283
|
-
Data: JSON.stringify(ackMessage)
|
|
3284
|
-
})
|
|
3285
|
-
);
|
|
3286
|
-
return { statusCode: 200, body: "Subscribed" };
|
|
3287
|
-
}
|
|
3288
|
-
case "unsubscribe": {
|
|
3289
|
-
const {
|
|
3290
|
-
entityType,
|
|
3291
|
-
byEntityType,
|
|
3292
|
-
byEntityId,
|
|
3293
|
-
mutualEntityType,
|
|
3294
|
-
channel
|
|
3295
|
-
} = message.payload;
|
|
3296
|
-
if (entityType && !byEntityType) {
|
|
3297
|
-
yield wsRepo.deleteSubscription(
|
|
3298
|
-
`${SUB_ENTITY_TYPE}${entityType}`,
|
|
3299
|
-
connectionId
|
|
3300
|
-
);
|
|
3301
|
-
} else if (byEntityType && byEntityId && mutualEntityType) {
|
|
3302
|
-
yield wsRepo.deleteSubscription(
|
|
3303
|
-
`${SUB_MUTUAL_TYPE}${byEntityType}#${byEntityId}#${mutualEntityType}`,
|
|
3304
|
-
connectionId
|
|
3305
|
-
);
|
|
3306
|
-
} else if (channel) {
|
|
3307
|
-
yield wsRepo.deleteSubscription(
|
|
3308
|
-
`${SUB_EPHEMERAL}${channel}`,
|
|
3309
|
-
connectionId
|
|
3310
|
-
);
|
|
3311
|
-
}
|
|
3312
|
-
const ackMessage = {
|
|
3313
|
-
type: "ack",
|
|
3314
|
-
id: message.id,
|
|
3315
|
-
payload: { action: "unsubscribe", success: true }
|
|
3316
|
-
};
|
|
3317
|
-
yield managementApi.send(
|
|
3318
|
-
new PostToConnectionCommand({
|
|
3319
|
-
ConnectionId: connectionId,
|
|
3320
|
-
Data: JSON.stringify(ackMessage)
|
|
3321
|
-
})
|
|
3322
|
-
);
|
|
3323
|
-
return { statusCode: 200, body: "Unsubscribed" };
|
|
3324
|
-
}
|
|
3325
|
-
case "ping": {
|
|
3326
|
-
const pongMessage = {
|
|
3327
|
-
type: "pong",
|
|
3328
|
-
id: message.id,
|
|
3329
|
-
payload: { timestamp: Date.now() }
|
|
3330
|
-
};
|
|
3331
|
-
yield managementApi.send(
|
|
3332
|
-
new PostToConnectionCommand({
|
|
3333
|
-
ConnectionId: connectionId,
|
|
3334
|
-
Data: JSON.stringify(pongMessage)
|
|
3335
|
-
})
|
|
3336
|
-
);
|
|
3337
|
-
return { statusCode: 200, body: "Pong" };
|
|
3338
|
-
}
|
|
3339
|
-
case "ephemeral": {
|
|
3340
|
-
const { channel, data } = message.payload;
|
|
3341
|
-
if (!channel) {
|
|
3342
|
-
return { statusCode: 400, body: "Missing channel" };
|
|
3343
|
-
}
|
|
3344
|
-
const conn = yield wsRepo.getConnection(connectionId);
|
|
3345
|
-
const senderId = conn == null ? void 0 : conn.entityId;
|
|
3346
|
-
const subKey = `${SUB_EPHEMERAL}${channel}`;
|
|
3347
|
-
const ephemeralMessage = {
|
|
3348
|
-
type: "ephemeral",
|
|
3349
|
-
id: ulid3(),
|
|
3350
|
-
payload: { channel, data, senderId }
|
|
3351
|
-
};
|
|
3352
|
-
yield broadcastToSubscribers(
|
|
3353
|
-
managementApi,
|
|
3354
|
-
wsRepo,
|
|
3355
|
-
subKey,
|
|
3356
|
-
ephemeralMessage,
|
|
3357
|
-
connectionId
|
|
3358
|
-
// Exclude sender
|
|
3359
|
-
);
|
|
3360
|
-
return { statusCode: 200, body: "Broadcasted" };
|
|
3361
|
-
}
|
|
3362
|
-
default:
|
|
3363
|
-
return { statusCode: 400, body: "Unknown action" };
|
|
3364
|
-
}
|
|
3365
|
-
} catch (error) {
|
|
3366
|
-
console.error("Error handling message:", error);
|
|
3367
|
-
try {
|
|
3368
|
-
const errorMessage = {
|
|
3369
|
-
type: "error",
|
|
3370
|
-
id: message.id,
|
|
3371
|
-
payload: { message: "Internal server error" }
|
|
3372
|
-
};
|
|
3373
|
-
yield managementApi.send(
|
|
3374
|
-
new PostToConnectionCommand({
|
|
3375
|
-
ConnectionId: connectionId,
|
|
3376
|
-
Data: JSON.stringify(errorMessage)
|
|
3377
|
-
})
|
|
3378
|
-
);
|
|
3379
|
-
} catch (e) {
|
|
3380
|
-
}
|
|
3381
|
-
return { statusCode: 500, body: "Internal server error" };
|
|
3382
|
-
}
|
|
3383
|
-
});
|
|
3384
|
-
var broadcast = (container) => (event) => __async(null, null, function* () {
|
|
3385
|
-
var _a, _b, _c, _d;
|
|
3386
|
-
const wsRepo = container.websocketRepository;
|
|
3387
|
-
const wsEndpoint = getWsEndpoint();
|
|
3388
|
-
const managementApi = new ApiGatewayManagementApiClient({
|
|
3389
|
-
endpoint: wsEndpoint
|
|
3390
|
-
});
|
|
3391
|
-
for (const record of event.Records) {
|
|
3392
|
-
const isInsert = record.eventName === "INSERT";
|
|
3393
|
-
const isModify = record.eventName === "MODIFY";
|
|
3394
|
-
const isRemove = record.eventName === "REMOVE";
|
|
3395
|
-
if (!isInsert && !isModify && !isRemove) continue;
|
|
3396
|
-
const newImage = (_a = record.dynamodb) == null ? void 0 : _a.NewImage;
|
|
3397
|
-
const oldImage = (_b = record.dynamodb) == null ? void 0 : _b.OldImage;
|
|
3398
|
-
const image = newImage || oldImage;
|
|
3399
|
-
if (!image) continue;
|
|
3400
|
-
const pk = ((_c = image.PK) == null ? void 0 : _c.S) || "";
|
|
3401
|
-
const sk = ((_d = image.SK) == null ? void 0 : _d.S) || "";
|
|
3402
|
-
const pkParts = pk.split("#");
|
|
3403
|
-
if (pkParts.length < 2) continue;
|
|
3404
|
-
const firstPart = pkParts[0];
|
|
3405
|
-
if (firstPart === firstPart.toUpperCase() || firstPart.includes(":")) {
|
|
3406
|
-
continue;
|
|
3407
|
-
}
|
|
3408
|
-
const entityType = pkParts[0];
|
|
3409
|
-
const entityId = pkParts[1];
|
|
3410
|
-
const isMutual = !sk.startsWith("#METADATA#") && sk.includes("#");
|
|
3411
|
-
try {
|
|
3412
|
-
if (isMutual) {
|
|
3413
|
-
const skParts = sk.split("#");
|
|
3414
|
-
const mutualEntityType = skParts[0];
|
|
3415
|
-
const byEntityId = entityId;
|
|
3416
|
-
const subKey = `${SUB_MUTUAL_TYPE}${entityType}#${byEntityId}#${mutualEntityType}`;
|
|
3417
|
-
const subscribers = yield wsRepo.querySubscriptionsByKey(subKey);
|
|
3418
|
-
if (subscribers.length) {
|
|
3419
|
-
let eventType;
|
|
3420
|
-
if (isInsert) eventType = "mutual.created";
|
|
3421
|
-
else if (isModify) eventType = "mutual.updated";
|
|
3422
|
-
else eventType = "mutual.deleted";
|
|
3423
|
-
const message = {
|
|
3424
|
-
type: eventType,
|
|
3425
|
-
id: ulid3(),
|
|
3426
|
-
payload: {
|
|
3427
|
-
byEntityType: entityType,
|
|
3428
|
-
byEntityId,
|
|
3429
|
-
mutualEntityType,
|
|
3430
|
-
entityId: skParts[1],
|
|
3431
|
-
data: isRemove ? void 0 : unmarshall4(image)
|
|
3432
|
-
}
|
|
3433
|
-
};
|
|
3434
|
-
yield broadcastToSubscribers(
|
|
3435
|
-
managementApi,
|
|
3436
|
-
wsRepo,
|
|
3437
|
-
subKey,
|
|
3438
|
-
message
|
|
3439
|
-
);
|
|
3440
|
-
}
|
|
3441
|
-
} else {
|
|
3442
|
-
const subKey = `${SUB_ENTITY_TYPE}${entityType}`;
|
|
3443
|
-
const subscribers = yield wsRepo.querySubscriptionsByKey(subKey);
|
|
3444
|
-
if (subscribers.length) {
|
|
3445
|
-
let eventType;
|
|
3446
|
-
if (isInsert) eventType = "entity.created";
|
|
3447
|
-
else if (isModify) eventType = "entity.updated";
|
|
3448
|
-
else eventType = "entity.deleted";
|
|
3449
|
-
const message = {
|
|
3450
|
-
type: eventType,
|
|
3451
|
-
id: ulid3(),
|
|
3452
|
-
payload: {
|
|
3453
|
-
entityType,
|
|
3454
|
-
entityId,
|
|
3455
|
-
data: isRemove ? void 0 : unmarshall4(image)
|
|
3456
|
-
}
|
|
3457
|
-
};
|
|
3458
|
-
yield broadcastToSubscribers(
|
|
3459
|
-
managementApi,
|
|
3460
|
-
wsRepo,
|
|
3461
|
-
subKey,
|
|
3462
|
-
message
|
|
3463
|
-
);
|
|
3464
|
-
}
|
|
3465
|
-
}
|
|
3466
|
-
yield broadcastToFeedSubscribers(
|
|
3467
|
-
managementApi,
|
|
3468
|
-
wsRepo,
|
|
3469
|
-
entityType,
|
|
3470
|
-
entityId,
|
|
3471
|
-
isMutual ? sk.split("#")[0] : entityType,
|
|
3472
|
-
// the changed entity type
|
|
3473
|
-
isMutual ? {
|
|
3474
|
-
type: isInsert ? "mutual.created" : isModify ? "mutual.updated" : "mutual.deleted",
|
|
3475
|
-
id: ulid3(),
|
|
3476
|
-
payload: {
|
|
3477
|
-
byEntityType: entityType,
|
|
3478
|
-
byEntityId: entityId,
|
|
3479
|
-
mutualEntityType: sk.split("#")[0],
|
|
3480
|
-
entityId: sk.split("#")[1],
|
|
3481
|
-
data: isRemove ? void 0 : unmarshall4(image)
|
|
3482
|
-
}
|
|
3483
|
-
} : {
|
|
3484
|
-
type: isInsert ? "entity.created" : isModify ? "entity.updated" : "entity.deleted",
|
|
3485
|
-
id: ulid3(),
|
|
3486
|
-
payload: {
|
|
3487
|
-
entityType,
|
|
3488
|
-
entityId,
|
|
3489
|
-
data: isRemove ? void 0 : unmarshall4(image)
|
|
3490
|
-
}
|
|
3491
|
-
}
|
|
3492
|
-
);
|
|
3493
|
-
} catch (error) {
|
|
3494
|
-
console.error("Error broadcasting:", error);
|
|
3495
|
-
}
|
|
3496
|
-
}
|
|
3497
|
-
});
|
|
3498
|
-
function broadcastToSubscribers(managementApi, wsRepo, subKey, message, excludeConnectionId) {
|
|
3499
|
-
return __async(this, null, function* () {
|
|
3500
|
-
const subscribers = yield wsRepo.querySubscriptionsByKey(subKey);
|
|
3501
|
-
if (!subscribers.length) return;
|
|
3502
|
-
const messageData = JSON.stringify(message);
|
|
3503
|
-
const sends = subscribers.filter((subscriber) => {
|
|
3504
|
-
const id = subscriber.connectionId;
|
|
3505
|
-
return !excludeConnectionId || id !== excludeConnectionId;
|
|
3506
|
-
}).map((subscriber) => __async(null, null, function* () {
|
|
3507
|
-
var _a;
|
|
3508
|
-
try {
|
|
3509
|
-
yield managementApi.send(
|
|
3510
|
-
new PostToConnectionCommand({
|
|
3511
|
-
ConnectionId: subscriber.connectionId,
|
|
3512
|
-
Data: messageData
|
|
3513
|
-
})
|
|
3514
|
-
);
|
|
3515
|
-
} catch (error) {
|
|
3516
|
-
const isGone = (error == null ? void 0 : error.name) === "GoneException" || ((_a = error == null ? void 0 : error.$metadata) == null ? void 0 : _a.httpStatusCode) === 410;
|
|
3517
|
-
if (isGone) {
|
|
3518
|
-
yield wsRepo.deleteSubscription(subKey, subscriber.connectionId).catch(
|
|
3519
|
-
(e) => console.warn("Failed to clean up stale subscription:", e)
|
|
3520
|
-
);
|
|
3521
|
-
}
|
|
3522
|
-
}
|
|
3523
|
-
}));
|
|
3524
|
-
yield Promise.allSettled(sends);
|
|
3525
|
-
});
|
|
3526
|
-
}
|
|
3527
|
-
function broadcastToFeedSubscribers(managementApi, wsRepo, byEntityType, byEntityId, changedEntityType, message) {
|
|
3528
|
-
return __async(this, null, function* () {
|
|
3529
|
-
var _a;
|
|
3530
|
-
const connections = yield wsRepo.queryMutualConnections(
|
|
3531
|
-
byEntityType,
|
|
3532
|
-
byEntityId
|
|
3533
|
-
);
|
|
3534
|
-
if (!connections.length) return;
|
|
3535
|
-
const connectedEntities = new Set(
|
|
3536
|
-
connections.map((c) => `${c.entityType}:${c.entityId}`)
|
|
3537
|
-
);
|
|
3538
|
-
connectedEntities.add(`${byEntityType}:${byEntityId}`);
|
|
3539
|
-
const sentConnections = /* @__PURE__ */ new Set();
|
|
3540
|
-
for (const connEntity of connectedEntities) {
|
|
3541
|
-
const [entityType, entityId] = connEntity.split(":");
|
|
3542
|
-
const feedSubs = yield wsRepo.queryFeedSubscriptions(entityType, entityId);
|
|
3543
|
-
if (!feedSubs.length) continue;
|
|
3544
|
-
for (const feedSub of feedSubs) {
|
|
3545
|
-
const feedTypes = feedSub.feedTypes;
|
|
3546
|
-
const connectionId = feedSub.connectionId;
|
|
3547
|
-
if (feedTypes && !feedTypes.includes(changedEntityType)) continue;
|
|
3548
|
-
if (sentConnections.has(connectionId)) continue;
|
|
3549
|
-
sentConnections.add(connectionId);
|
|
3550
|
-
try {
|
|
3551
|
-
yield managementApi.send(
|
|
3552
|
-
new PostToConnectionCommand({
|
|
3553
|
-
ConnectionId: connectionId,
|
|
3554
|
-
Data: JSON.stringify(message)
|
|
3555
|
-
})
|
|
3556
|
-
);
|
|
3557
|
-
} catch (error) {
|
|
3558
|
-
const isGone = (error == null ? void 0 : error.name) === "GoneException" || ((_a = error == null ? void 0 : error.$metadata) == null ? void 0 : _a.httpStatusCode) === 410;
|
|
3559
|
-
if (isGone) {
|
|
3560
|
-
yield wsRepo.deleteSubscription(
|
|
3561
|
-
`SUB#FEED#${entityType}#${entityId}`,
|
|
3562
|
-
connectionId
|
|
3563
|
-
).catch(
|
|
3564
|
-
(e) => console.warn("Failed to clean up stale feed subscription:", e)
|
|
3565
|
-
);
|
|
3566
|
-
}
|
|
3567
|
-
}
|
|
3568
|
-
}
|
|
3569
|
-
}
|
|
3570
|
-
});
|
|
3571
|
-
}
|
|
3572
|
-
|
|
3573
2973
|
// services/DependencyContainer.ts
|
|
3574
2974
|
import { DynamoDB } from "@aws-sdk/client-dynamodb";
|
|
3575
2975
|
|
|
@@ -7806,16 +7206,7 @@ var UpdateEntityController = class {
|
|
|
7806
7206
|
const accountId = c.req.header("account-id");
|
|
7807
7207
|
const { entityType, entityId } = c.req.param();
|
|
7808
7208
|
const body = yield c.req.json();
|
|
7809
|
-
const _a = body, { $
|
|
7810
|
-
if (condition !== void 0) {
|
|
7811
|
-
if (typeof condition !== "string" || condition.trim().length === 0) {
|
|
7812
|
-
c.status(httpStatus8.BAD_REQUEST);
|
|
7813
|
-
return c.json({
|
|
7814
|
-
code: "API_VALIDATION_ERROR",
|
|
7815
|
-
message: "$condition must be a non-empty string"
|
|
7816
|
-
});
|
|
7817
|
-
}
|
|
7818
|
-
}
|
|
7209
|
+
const _a = body, { $where: where } = _a, entityPayload = __objRest(_a, ["$where"]);
|
|
7819
7210
|
const errorContext = {
|
|
7820
7211
|
accountId,
|
|
7821
7212
|
"req.params": c.req.param(),
|
|
@@ -7827,7 +7218,6 @@ var UpdateEntityController = class {
|
|
|
7827
7218
|
entityId,
|
|
7828
7219
|
entityPayload,
|
|
7829
7220
|
accountId,
|
|
7830
|
-
condition,
|
|
7831
7221
|
where
|
|
7832
7222
|
});
|
|
7833
7223
|
errorContext.entity = entity;
|
|
@@ -7846,10 +7236,6 @@ var UpdateEntityController = class {
|
|
|
7846
7236
|
c.status(httpStatus8.NOT_FOUND);
|
|
7847
7237
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
7848
7238
|
}
|
|
7849
|
-
if (err instanceof StandardError && err.code === StandardErrorCode.INVALID_CONDITION) {
|
|
7850
|
-
c.status(httpStatus8.BAD_REQUEST);
|
|
7851
|
-
return c.json(__spreadValues({}, err.toJSON()));
|
|
7852
|
-
}
|
|
7853
7239
|
if (err instanceof StandardError && err.code === StandardErrorCode.UNIQUE_VALUE_EXISTS) {
|
|
7854
7240
|
c.status(httpStatus8.BAD_REQUEST);
|
|
7855
7241
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
@@ -7876,21 +7262,11 @@ var AdjustEntityController = class {
|
|
|
7876
7262
|
constructor(entityService) {
|
|
7877
7263
|
this.entityService = entityService;
|
|
7878
7264
|
this.controller = createMiddleware9((c) => __async(this, null, function* () {
|
|
7879
|
-
var
|
|
7265
|
+
var _a;
|
|
7880
7266
|
const accountId = c.req.header("account-id") || "";
|
|
7881
7267
|
const { entityType, entityId } = c.req.param();
|
|
7882
7268
|
const body = yield c.req.json();
|
|
7883
|
-
const
|
|
7884
|
-
if (condition !== void 0) {
|
|
7885
|
-
if (typeof condition !== "string" || condition.trim().length === 0) {
|
|
7886
|
-
c.status(httpStatus9.BAD_REQUEST);
|
|
7887
|
-
return c.json({
|
|
7888
|
-
code: "API_VALIDATION_ERROR",
|
|
7889
|
-
message: "$condition must be a non-empty string"
|
|
7890
|
-
});
|
|
7891
|
-
}
|
|
7892
|
-
}
|
|
7893
|
-
for (const [key, value] of Object.entries(adjustments)) {
|
|
7269
|
+
for (const [key, value] of Object.entries(body)) {
|
|
7894
7270
|
if (typeof value !== "number") {
|
|
7895
7271
|
c.status(httpStatus9.BAD_REQUEST);
|
|
7896
7272
|
return c.json({
|
|
@@ -7903,9 +7279,8 @@ var AdjustEntityController = class {
|
|
|
7903
7279
|
const entity = yield this.entityService.adjustEntity({
|
|
7904
7280
|
entityType,
|
|
7905
7281
|
entityId,
|
|
7906
|
-
adjustments,
|
|
7907
|
-
accountId
|
|
7908
|
-
condition
|
|
7282
|
+
adjustments: body,
|
|
7283
|
+
accountId
|
|
7909
7284
|
});
|
|
7910
7285
|
c.status(httpStatus9.OK);
|
|
7911
7286
|
return c.json(entity.toJSON());
|
|
@@ -7914,11 +7289,7 @@ var AdjustEntityController = class {
|
|
|
7914
7289
|
c.status(httpStatus9.NOT_FOUND);
|
|
7915
7290
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
7916
7291
|
}
|
|
7917
|
-
if (err
|
|
7918
|
-
c.status(httpStatus9.BAD_REQUEST);
|
|
7919
|
-
return c.json(__spreadValues({}, err.toJSON()));
|
|
7920
|
-
}
|
|
7921
|
-
if ((err == null ? void 0 : err.name) === "ConditionalCheckFailedException" || ((_b = err == null ? void 0 : err.__type) == null ? void 0 : _b.includes("ConditionalCheckFailed"))) {
|
|
7292
|
+
if ((err == null ? void 0 : err.name) === "ConditionalCheckFailedException" || ((_a = err == null ? void 0 : err.__type) == null ? void 0 : _a.includes("ConditionalCheckFailed"))) {
|
|
7922
7293
|
c.status(httpStatus9.CONFLICT);
|
|
7923
7294
|
return c.json({
|
|
7924
7295
|
code: "ADJUSTMENT_CONSTRAINT_VIOLATED",
|
|
@@ -8020,7 +7391,6 @@ var CreateMutualController = class {
|
|
|
8020
7391
|
constructor(mutualService) {
|
|
8021
7392
|
this.mutualService = mutualService;
|
|
8022
7393
|
this.controller = createMiddleware11((c) => __async(this, null, function* () {
|
|
8023
|
-
var _a;
|
|
8024
7394
|
const accountId = c.req.header("account-id");
|
|
8025
7395
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
8026
7396
|
const asEntity = c.req.query("asEntity");
|
|
@@ -8039,7 +7409,7 @@ var CreateMutualController = class {
|
|
|
8039
7409
|
});
|
|
8040
7410
|
return c.json(mutual);
|
|
8041
7411
|
} catch (err) {
|
|
8042
|
-
if (
|
|
7412
|
+
if (err instanceof ZodError) {
|
|
8043
7413
|
c.status(httpStatus11.BAD_REQUEST);
|
|
8044
7414
|
return c.json({
|
|
8045
7415
|
code: "API_VALIDATION_ERROR",
|
|
@@ -8047,15 +7417,15 @@ var CreateMutualController = class {
|
|
|
8047
7417
|
details: err.flatten()
|
|
8048
7418
|
});
|
|
8049
7419
|
}
|
|
8050
|
-
if (err instanceof StandardError) {
|
|
7420
|
+
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_EXISTS) {
|
|
8051
7421
|
c.status(httpStatus11.BAD_REQUEST);
|
|
8052
7422
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
8053
7423
|
}
|
|
8054
|
-
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
7424
|
+
if (err instanceof StandardError && err.code === StandardErrorCode.ENTITY_IS_UNDEFINED) {
|
|
7425
|
+
c.status(httpStatus11.BAD_REQUEST);
|
|
7426
|
+
return c.json(__spreadValues({}, err.toJSON()));
|
|
7427
|
+
}
|
|
7428
|
+
throw err;
|
|
8059
7429
|
}
|
|
8060
7430
|
}));
|
|
8061
7431
|
}
|
|
@@ -8189,7 +7559,6 @@ var UpdateMutualController = class {
|
|
|
8189
7559
|
constructor(mutualService) {
|
|
8190
7560
|
this.mutualService = mutualService;
|
|
8191
7561
|
this.controller = createMiddleware15((c) => __async(this, null, function* () {
|
|
8192
|
-
var _a;
|
|
8193
7562
|
const accountId = c.req.header("account-id");
|
|
8194
7563
|
const { byEntityType, byEntityId, entityType, entityId } = c.req.param();
|
|
8195
7564
|
const body = yield c.req.json();
|
|
@@ -8207,7 +7576,7 @@ var UpdateMutualController = class {
|
|
|
8207
7576
|
});
|
|
8208
7577
|
return c.json(mutual);
|
|
8209
7578
|
} catch (err) {
|
|
8210
|
-
if (
|
|
7579
|
+
if (err instanceof ZodError) {
|
|
8211
7580
|
c.status(httpStatus14.BAD_REQUEST);
|
|
8212
7581
|
return c.json({
|
|
8213
7582
|
code: "API_VALIDATION_ERROR",
|
|
@@ -8215,23 +7584,16 @@ var UpdateMutualController = class {
|
|
|
8215
7584
|
details: err.flatten()
|
|
8216
7585
|
});
|
|
8217
7586
|
}
|
|
8218
|
-
if (err instanceof StandardError) {
|
|
7587
|
+
if (err instanceof StandardError && err.code === StandardErrorCode.MUTUAL_NOT_FOUND) {
|
|
8219
7588
|
c.status(httpStatus14.BAD_REQUEST);
|
|
8220
7589
|
return c.json(__spreadValues({}, err.toJSON()));
|
|
8221
7590
|
}
|
|
8222
|
-
|
|
8223
|
-
return c.json({
|
|
8224
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
8225
|
-
message: (err == null ? void 0 : err.message) || "An unexpected error occurred"
|
|
8226
|
-
});
|
|
7591
|
+
throw err;
|
|
8227
7592
|
}
|
|
8228
7593
|
}));
|
|
8229
7594
|
}
|
|
8230
7595
|
};
|
|
8231
7596
|
|
|
8232
|
-
// services/entity.service.ts
|
|
8233
|
-
import { marshall as marshall6 } from "@aws-sdk/util-dynamodb";
|
|
8234
|
-
|
|
8235
7597
|
// data/utils/build-condition-expression.ts
|
|
8236
7598
|
import { marshall as marshall5 } from "@aws-sdk/util-dynamodb";
|
|
8237
7599
|
function buildConditionExpression(where) {
|
|
@@ -8293,55 +7655,6 @@ function buildConditionExpression(where) {
|
|
|
8293
7655
|
};
|
|
8294
7656
|
}
|
|
8295
7657
|
|
|
8296
|
-
// services/resolve-condition.ts
|
|
8297
|
-
function resolveAdjustmentCondition(_0) {
|
|
8298
|
-
return __async(this, arguments, function* ({
|
|
8299
|
-
conditionName,
|
|
8300
|
-
conditions,
|
|
8301
|
-
adjustments,
|
|
8302
|
-
getEntityData
|
|
8303
|
-
}) {
|
|
8304
|
-
if (!Object.hasOwn(conditions, conditionName)) {
|
|
8305
|
-
throw new StandardError(
|
|
8306
|
-
StandardErrorCode.INVALID_CONDITION,
|
|
8307
|
-
`Unknown adjustment condition: '${conditionName}'`
|
|
8308
|
-
);
|
|
8309
|
-
}
|
|
8310
|
-
const condition = conditions[conditionName];
|
|
8311
|
-
let resolved;
|
|
8312
|
-
if (typeof condition === "function") {
|
|
8313
|
-
const data = yield getEntityData();
|
|
8314
|
-
resolved = condition(data, adjustments);
|
|
8315
|
-
} else {
|
|
8316
|
-
resolved = condition;
|
|
8317
|
-
}
|
|
8318
|
-
return buildConditionExpression(resolved);
|
|
8319
|
-
});
|
|
8320
|
-
}
|
|
8321
|
-
function resolveUpdateCondition(_0) {
|
|
8322
|
-
return __async(this, arguments, function* ({
|
|
8323
|
-
conditionName,
|
|
8324
|
-
conditions,
|
|
8325
|
-
getEntityData
|
|
8326
|
-
}) {
|
|
8327
|
-
if (!Object.hasOwn(conditions, conditionName)) {
|
|
8328
|
-
throw new StandardError(
|
|
8329
|
-
StandardErrorCode.INVALID_CONDITION,
|
|
8330
|
-
`Unknown update condition: '${conditionName}'`
|
|
8331
|
-
);
|
|
8332
|
-
}
|
|
8333
|
-
const condition = conditions[conditionName];
|
|
8334
|
-
let resolved;
|
|
8335
|
-
if (typeof condition === "function") {
|
|
8336
|
-
const data = yield getEntityData();
|
|
8337
|
-
resolved = condition(data);
|
|
8338
|
-
} else {
|
|
8339
|
-
resolved = condition;
|
|
8340
|
-
}
|
|
8341
|
-
return buildConditionExpression(resolved);
|
|
8342
|
-
});
|
|
8343
|
-
}
|
|
8344
|
-
|
|
8345
7658
|
// services/entity.service.ts
|
|
8346
7659
|
var EntityService = class {
|
|
8347
7660
|
constructor(EntityConfig, EmailAuthEnabledEntities, entityRepository, publishEvent2, entityServiceLifeCycle) {
|
|
@@ -8397,59 +7710,34 @@ var EntityService = class {
|
|
|
8397
7710
|
entityType,
|
|
8398
7711
|
entityId,
|
|
8399
7712
|
adjustments,
|
|
8400
|
-
accountId
|
|
8401
|
-
condition
|
|
7713
|
+
accountId
|
|
8402
7714
|
}) {
|
|
8403
|
-
var _a, _b, _c;
|
|
8404
|
-
const
|
|
8405
|
-
|
|
8406
|
-
|
|
8407
|
-
let opts;
|
|
8408
|
-
if (adjustmentConditions) {
|
|
8409
|
-
if (!condition) {
|
|
8410
|
-
throw new StandardError(
|
|
8411
|
-
StandardErrorCode.INVALID_CONDITION,
|
|
8412
|
-
"Entity has adjustmentConditions defined; $condition is required for adjustEntity"
|
|
8413
|
-
);
|
|
8414
|
-
}
|
|
8415
|
-
opts = yield resolveAdjustmentCondition({
|
|
8416
|
-
conditionName: condition,
|
|
8417
|
-
conditions: adjustmentConditions,
|
|
8418
|
-
adjustments,
|
|
8419
|
-
getEntityData: () => __async(this, null, function* () {
|
|
8420
|
-
var _a2;
|
|
8421
|
-
const entity2 = yield this.entityRepository.getEntity(entityType, entityId);
|
|
8422
|
-
return (_a2 = entity2 == null ? void 0 : entity2.data) != null ? _a2 : {};
|
|
8423
|
-
})
|
|
8424
|
-
});
|
|
8425
|
-
} else if (rawConstraints) {
|
|
8426
|
-
console.warn(
|
|
8427
|
-
"[monorise] adjustmentConstraints is deprecated. Use adjustmentConditions instead."
|
|
8428
|
-
);
|
|
8429
|
-
let resolvedConstraints = rawConstraints;
|
|
7715
|
+
var _a, _b, _c, _d;
|
|
7716
|
+
const rawConstraints = (_a = this.EntityConfig[entityType]) == null ? void 0 : _a.adjustmentConstraints;
|
|
7717
|
+
let resolvedConstraints = rawConstraints;
|
|
7718
|
+
if (rawConstraints) {
|
|
8430
7719
|
const hasDynamicFields = Object.values(rawConstraints).some(
|
|
8431
7720
|
(c) => c.minField || c.maxField
|
|
8432
7721
|
);
|
|
8433
7722
|
if (hasDynamicFields) {
|
|
8434
7723
|
const currentEntity = yield this.entityRepository.getEntity(entityType, entityId);
|
|
8435
|
-
const data = (
|
|
7724
|
+
const data = (_b = currentEntity == null ? void 0 : currentEntity.data) != null ? _b : {};
|
|
8436
7725
|
resolvedConstraints = {};
|
|
8437
7726
|
for (const [field, constraint] of Object.entries(rawConstraints)) {
|
|
8438
7727
|
const resolved = {};
|
|
8439
7728
|
if (constraint.min !== void 0) resolved.min = constraint.min;
|
|
8440
7729
|
if (constraint.max !== void 0) resolved.max = constraint.max;
|
|
8441
|
-
if (constraint.minField) resolved.min = (
|
|
8442
|
-
if (constraint.maxField) resolved.max = (
|
|
7730
|
+
if (constraint.minField) resolved.min = (_c = data[constraint.minField]) != null ? _c : 0;
|
|
7731
|
+
if (constraint.maxField) resolved.max = (_d = data[constraint.maxField]) != null ? _d : Number.MAX_SAFE_INTEGER;
|
|
8443
7732
|
resolvedConstraints[field] = resolved;
|
|
8444
7733
|
}
|
|
8445
7734
|
}
|
|
8446
|
-
opts = this.buildLegacyAdjustCondition(adjustments, resolvedConstraints);
|
|
8447
7735
|
}
|
|
8448
7736
|
const entity = yield this.entityRepository.adjustEntity(
|
|
8449
7737
|
entityType,
|
|
8450
7738
|
entityId,
|
|
8451
7739
|
adjustments,
|
|
8452
|
-
|
|
7740
|
+
resolvedConstraints
|
|
8453
7741
|
);
|
|
8454
7742
|
yield this.publishEvent({
|
|
8455
7743
|
event: EVENT.CORE.ENTITY_UPDATED,
|
|
@@ -8468,10 +7756,9 @@ var EntityService = class {
|
|
|
8468
7756
|
entityId,
|
|
8469
7757
|
entityPayload,
|
|
8470
7758
|
accountId,
|
|
8471
|
-
condition,
|
|
8472
7759
|
where
|
|
8473
7760
|
}) {
|
|
8474
|
-
var _a, _b
|
|
7761
|
+
var _a, _b;
|
|
8475
7762
|
const errorContext = {};
|
|
8476
7763
|
try {
|
|
8477
7764
|
const entitySchema = this.EntityConfig[entityType].baseSchema;
|
|
@@ -8485,30 +7772,7 @@ var EntityService = class {
|
|
|
8485
7772
|
const parsedEntityPayload = entitySchema.parse(entityPayload);
|
|
8486
7773
|
const parsedMutualPayload = mutualSchema == null ? void 0 : mutualSchema.parse(entityPayload);
|
|
8487
7774
|
errorContext.parsedMutualPayload = parsedMutualPayload;
|
|
8488
|
-
|
|
8489
|
-
if (condition) {
|
|
8490
|
-
const updateConditions = (_b = this.EntityConfig[entityType]) == null ? void 0 : _b.updateConditions;
|
|
8491
|
-
if (!updateConditions) {
|
|
8492
|
-
throw new StandardError(
|
|
8493
|
-
StandardErrorCode.INVALID_CONDITION,
|
|
8494
|
-
`Entity '${entityType}' has no updateConditions defined`
|
|
8495
|
-
);
|
|
8496
|
-
}
|
|
8497
|
-
opts = yield resolveUpdateCondition({
|
|
8498
|
-
conditionName: condition,
|
|
8499
|
-
conditions: updateConditions,
|
|
8500
|
-
getEntityData: () => __async(this, null, function* () {
|
|
8501
|
-
var _a2;
|
|
8502
|
-
const entity2 = yield this.entityRepository.getEntity(entityType, entityId);
|
|
8503
|
-
return (_a2 = entity2 == null ? void 0 : entity2.data) != null ? _a2 : {};
|
|
8504
|
-
})
|
|
8505
|
-
});
|
|
8506
|
-
} else if (where && Object.keys(where).length > 0) {
|
|
8507
|
-
console.warn(
|
|
8508
|
-
"[monorise] $where is deprecated. Use named conditions via $condition instead."
|
|
8509
|
-
);
|
|
8510
|
-
opts = buildConditionExpression(where);
|
|
8511
|
-
}
|
|
7775
|
+
const opts = where && Object.keys(where).length > 0 ? buildConditionExpression(where) : void 0;
|
|
8512
7776
|
const entity = yield this.entityRepository.updateEntity(
|
|
8513
7777
|
entityType,
|
|
8514
7778
|
entityId,
|
|
@@ -8521,7 +7785,7 @@ var EntityService = class {
|
|
|
8521
7785
|
const byEntityId = entityId;
|
|
8522
7786
|
const publishEventPromises = [];
|
|
8523
7787
|
for (const [fieldKey, config] of Object.entries(
|
|
8524
|
-
((
|
|
7788
|
+
((_b = this.EntityConfig[entityType].mutual) == null ? void 0 : _b.mutualFields) || {}
|
|
8525
7789
|
)) {
|
|
8526
7790
|
const toMutualIds = config.toMutualIds;
|
|
8527
7791
|
const mutualPayload = parsedMutualPayload[fieldKey];
|
|
@@ -8577,42 +7841,12 @@ var EntityService = class {
|
|
|
8577
7841
|
});
|
|
8578
7842
|
});
|
|
8579
7843
|
}
|
|
8580
|
-
/** @deprecated Converts legacy adjustmentConstraints to condition expression opts. */
|
|
8581
|
-
buildLegacyAdjustCondition(adjustments, constraints) {
|
|
8582
|
-
const conditionParts = [];
|
|
8583
|
-
const names = { "#data": "data" };
|
|
8584
|
-
const values = {};
|
|
8585
|
-
for (const [field, constraint] of Object.entries(constraints)) {
|
|
8586
|
-
const delta = adjustments[field];
|
|
8587
|
-
if (delta === void 0) continue;
|
|
8588
|
-
const namePlaceholder = `#where_${field}`;
|
|
8589
|
-
names[namePlaceholder] = field;
|
|
8590
|
-
const fieldRef = `#data.${namePlaceholder}`;
|
|
8591
|
-
if (constraint.min !== void 0 && delta < 0) {
|
|
8592
|
-
const valKey = `:where_${field}_min_threshold`;
|
|
8593
|
-
conditionParts.push(`${fieldRef} >= ${valKey}`);
|
|
8594
|
-
values[valKey] = constraint.min - delta;
|
|
8595
|
-
}
|
|
8596
|
-
if (constraint.max !== void 0 && delta > 0) {
|
|
8597
|
-
const valKey = `:where_${field}_max_threshold`;
|
|
8598
|
-
conditionParts.push(`${fieldRef} <= ${valKey}`);
|
|
8599
|
-
values[valKey] = constraint.max - delta;
|
|
8600
|
-
}
|
|
8601
|
-
}
|
|
8602
|
-
if (conditionParts.length === 0) return void 0;
|
|
8603
|
-
return {
|
|
8604
|
-
ConditionExpression: conditionParts.join(" AND "),
|
|
8605
|
-
ExpressionAttributeNames: names,
|
|
8606
|
-
ExpressionAttributeValues: marshall6(values)
|
|
8607
|
-
};
|
|
8608
|
-
}
|
|
8609
7844
|
};
|
|
8610
7845
|
|
|
8611
7846
|
// services/mutual.service.ts
|
|
8612
|
-
import { ulid as
|
|
7847
|
+
import { ulid as ulid3 } from "ulid";
|
|
8613
7848
|
var MutualService = class {
|
|
8614
|
-
constructor(
|
|
8615
|
-
this.EntityConfig = EntityConfig;
|
|
7849
|
+
constructor(entityRepository, mutualRepository, publishEvent2, ddbUtils, entityServiceLifeCycle) {
|
|
8616
7850
|
this.entityRepository = entityRepository;
|
|
8617
7851
|
this.mutualRepository = mutualRepository;
|
|
8618
7852
|
this.publishEvent = publishEvent2;
|
|
@@ -8627,7 +7861,6 @@ var MutualService = class {
|
|
|
8627
7861
|
accountId,
|
|
8628
7862
|
options = {}
|
|
8629
7863
|
}) {
|
|
8630
|
-
var _a;
|
|
8631
7864
|
const {
|
|
8632
7865
|
ensureEntityStrongConsistentWrite = false,
|
|
8633
7866
|
asEntity,
|
|
@@ -8648,37 +7881,20 @@ var MutualService = class {
|
|
|
8648
7881
|
options
|
|
8649
7882
|
}
|
|
8650
7883
|
};
|
|
8651
|
-
|
|
8652
|
-
byEntityType,
|
|
8653
|
-
byEntityId,
|
|
8654
|
-
entityType,
|
|
8655
|
-
entityId,
|
|
8656
|
-
mutualPayload,
|
|
8657
|
-
options
|
|
8658
|
-
});
|
|
8659
|
-
const schema = (_a = this.getMutualDataSchema(byEntityType, entityType)) != null ? _a : external_exports.record(external_exports.string(), external_exports.any());
|
|
8660
|
-
console.log("[MONORISE_DEBUG] createMutual schema resolved");
|
|
7884
|
+
const schema = external_exports.record(external_exports.string(), external_exports.any());
|
|
8661
7885
|
const parsedMutualPayload = schema.parse(mutualPayload);
|
|
8662
|
-
console.log("[MONORISE_DEBUG] createMutual payload parsed:", parsedMutualPayload);
|
|
8663
|
-
console.log("[MONORISE_DEBUG] createMutual fetching entities...");
|
|
8664
7886
|
const [{ data: byEntityData }, { data: entityData }] = yield Promise.all([
|
|
8665
7887
|
this.entityRepository.getEntity(byEntityType, byEntityId),
|
|
8666
7888
|
this.entityRepository.getEntity(entityType, entityId)
|
|
8667
7889
|
]);
|
|
8668
|
-
console.log("[MONORISE_DEBUG] createMutual entities fetched:", {
|
|
8669
|
-
hasByEntityData: !!byEntityData,
|
|
8670
|
-
hasEntityData: !!entityData
|
|
8671
|
-
});
|
|
8672
7890
|
errorContext.byEntityData = byEntityData;
|
|
8673
7891
|
errorContext.entityData = entityData;
|
|
8674
|
-
console.log("[MONORISE_DEBUG] createMutual checking mutual exist...");
|
|
8675
7892
|
yield this.mutualRepository.checkMutualExist(
|
|
8676
7893
|
byEntityType,
|
|
8677
7894
|
byEntityId,
|
|
8678
7895
|
entityType,
|
|
8679
7896
|
entityId
|
|
8680
7897
|
);
|
|
8681
|
-
console.log("[MONORISE_DEBUG] createMutual mutual does not exist (ok)");
|
|
8682
7898
|
const currentDatetime = createAndUpdateDatetime || /* @__PURE__ */ new Date();
|
|
8683
7899
|
const mutual = new Mutual(
|
|
8684
7900
|
byEntityType,
|
|
@@ -8688,14 +7904,11 @@ var MutualService = class {
|
|
|
8688
7904
|
entityId,
|
|
8689
7905
|
entityData,
|
|
8690
7906
|
parsedMutualPayload,
|
|
8691
|
-
mutualId ||
|
|
7907
|
+
mutualId || ulid3(),
|
|
8692
7908
|
currentDatetime,
|
|
8693
7909
|
currentDatetime,
|
|
8694
7910
|
currentDatetime
|
|
8695
7911
|
);
|
|
8696
|
-
console.log("[MONORISE_DEBUG] createMutual mutual object created:", {
|
|
8697
|
-
mutualId: mutual.mutualId
|
|
8698
|
-
});
|
|
8699
7912
|
const mutualTransactions = skipMutualCreation ? [] : this.mutualRepository.createMutualTransactItems(mutual, {
|
|
8700
7913
|
ConditionExpression,
|
|
8701
7914
|
ExpressionAttributeNames,
|
|
@@ -8719,13 +7932,9 @@ var MutualService = class {
|
|
|
8719
7932
|
}
|
|
8720
7933
|
const createTransactItems = [...mutualTransactions, ...entityTransactions];
|
|
8721
7934
|
errorContext.createTransactItems = createTransactItems;
|
|
8722
|
-
console.log("[MONORISE_DEBUG] createMutual executing transaction:", {
|
|
8723
|
-
transactItemCount: createTransactItems.length
|
|
8724
|
-
});
|
|
8725
7935
|
yield this.ddbUtils.executeTransactWrite({
|
|
8726
7936
|
TransactItems: createTransactItems
|
|
8727
7937
|
});
|
|
8728
|
-
console.log("[MONORISE_DEBUG] createMutual transaction succeeded");
|
|
8729
7938
|
if (asEntity && entity && ensureEntityStrongConsistentWrite) {
|
|
8730
7939
|
yield this.entityServiceLifeCycle.afterCreateEntityHook(
|
|
8731
7940
|
entity,
|
|
@@ -8764,7 +7973,6 @@ var MutualService = class {
|
|
|
8764
7973
|
})
|
|
8765
7974
|
];
|
|
8766
7975
|
yield Promise.all(eventPromises);
|
|
8767
|
-
console.log("[MONORISE_DEBUG] createMutual service complete");
|
|
8768
7976
|
return { mutual, eventPayload };
|
|
8769
7977
|
});
|
|
8770
7978
|
this.updateMutual = (_0) => __async(this, [_0], function* ({
|
|
@@ -8776,20 +7984,8 @@ var MutualService = class {
|
|
|
8776
7984
|
accountId,
|
|
8777
7985
|
options
|
|
8778
7986
|
}) {
|
|
8779
|
-
|
|
8780
|
-
console.log("[MONORISE_DEBUG] updateMutual service start:", {
|
|
8781
|
-
byEntityType,
|
|
8782
|
-
byEntityId,
|
|
8783
|
-
entityType,
|
|
8784
|
-
entityId,
|
|
8785
|
-
mutualPayload,
|
|
8786
|
-
options
|
|
8787
|
-
});
|
|
8788
|
-
const schema = (_a = this.getMutualDataSchema(byEntityType, entityType)) != null ? _a : external_exports.record(external_exports.string(), external_exports.any());
|
|
8789
|
-
console.log("[MONORISE_DEBUG] updateMutual schema resolved");
|
|
7987
|
+
const schema = external_exports.record(external_exports.string(), external_exports.any());
|
|
8790
7988
|
const parsedMutualPayload = schema.parse(mutualPayload);
|
|
8791
|
-
console.log("[MONORISE_DEBUG] updateMutual payload parsed:", parsedMutualPayload);
|
|
8792
|
-
console.log("[MONORISE_DEBUG] updateMutual calling repository...");
|
|
8793
7989
|
const mutual = yield this.mutualRepository.updateMutual(
|
|
8794
7990
|
byEntityType,
|
|
8795
7991
|
byEntityId,
|
|
@@ -8798,10 +7994,6 @@ var MutualService = class {
|
|
|
8798
7994
|
{ mutualData: parsedMutualPayload },
|
|
8799
7995
|
options
|
|
8800
7996
|
);
|
|
8801
|
-
console.log("[MONORISE_DEBUG] updateMutual repository result:", {
|
|
8802
|
-
hasMutual: !!mutual,
|
|
8803
|
-
mutualId: mutual == null ? void 0 : mutual.mutualId
|
|
8804
|
-
});
|
|
8805
7997
|
yield this.publishEvent({
|
|
8806
7998
|
event: EVENT.CORE.MUTUAL_UPDATED(byEntityType, entityType),
|
|
8807
7999
|
payload: {
|
|
@@ -8813,7 +8005,6 @@ var MutualService = class {
|
|
|
8813
8005
|
updatedByAccountId: accountId
|
|
8814
8006
|
}
|
|
8815
8007
|
});
|
|
8816
|
-
console.log("[MONORISE_DEBUG] updateMutual service complete");
|
|
8817
8008
|
return mutual;
|
|
8818
8009
|
});
|
|
8819
8010
|
this.deleteMutual = (_0) => __async(this, [_0], function* ({
|
|
@@ -8842,22 +8033,6 @@ var MutualService = class {
|
|
|
8842
8033
|
return mutual;
|
|
8843
8034
|
});
|
|
8844
8035
|
}
|
|
8845
|
-
getMutualDataSchema(byEntityType, entityType) {
|
|
8846
|
-
var _a, _b, _c;
|
|
8847
|
-
for (const [from, to] of [
|
|
8848
|
-
[byEntityType, entityType],
|
|
8849
|
-
[entityType, byEntityType]
|
|
8850
|
-
]) {
|
|
8851
|
-
const mutualFields = (_b = (_a = this.EntityConfig[from]) == null ? void 0 : _a.mutual) == null ? void 0 : _b.mutualFields;
|
|
8852
|
-
if (!mutualFields) continue;
|
|
8853
|
-
for (const config of Object.values(mutualFields)) {
|
|
8854
|
-
if (config.entityType === to && ((_c = config.mutual) == null ? void 0 : _c.mutualDataSchema)) {
|
|
8855
|
-
return config.mutual.mutualDataSchema;
|
|
8856
|
-
}
|
|
8857
|
-
}
|
|
8858
|
-
}
|
|
8859
|
-
return void 0;
|
|
8860
|
-
}
|
|
8861
8036
|
};
|
|
8862
8037
|
|
|
8863
8038
|
// controllers/tag/list-tags.controller.ts
|
|
@@ -8907,125 +8082,15 @@ var ListTagsController = class {
|
|
|
8907
8082
|
}
|
|
8908
8083
|
};
|
|
8909
8084
|
|
|
8910
|
-
//
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
this.
|
|
8916
|
-
|
|
8917
|
-
|
|
8918
|
-
|
|
8919
|
-
const accountId = c.req.header("account-id") || "";
|
|
8920
|
-
const body = yield c.req.json();
|
|
8921
|
-
if (!body.operations || !Array.isArray(body.operations)) {
|
|
8922
|
-
c.status(httpStatus15.BAD_REQUEST);
|
|
8923
|
-
return c.json({
|
|
8924
|
-
code: "API_VALIDATION_ERROR",
|
|
8925
|
-
message: 'Request body must contain an "operations" array'
|
|
8926
|
-
});
|
|
8927
|
-
}
|
|
8928
|
-
try {
|
|
8929
|
-
const result = yield this.transactionService.executeTransaction(
|
|
8930
|
-
body.operations,
|
|
8931
|
-
accountId
|
|
8932
|
-
);
|
|
8933
|
-
c.status(httpStatus15.OK);
|
|
8934
|
-
return c.json(result);
|
|
8935
|
-
} catch (err) {
|
|
8936
|
-
if (((_a = err.constructor) == null ? void 0 : _a.name) === "ZodError") {
|
|
8937
|
-
c.status(httpStatus15.BAD_REQUEST);
|
|
8938
|
-
return c.json({
|
|
8939
|
-
code: "API_VALIDATION_ERROR",
|
|
8940
|
-
message: "Validation failed",
|
|
8941
|
-
details: err.flatten()
|
|
8942
|
-
});
|
|
8943
|
-
}
|
|
8944
|
-
if (err instanceof StandardError) {
|
|
8945
|
-
const code = err.code;
|
|
8946
|
-
if (code === StandardErrorCode.TRANSACTION_EMPTY || code === StandardErrorCode.TRANSACTION_ITEM_LIMIT_EXCEEDED || code === StandardErrorCode.TRANSACTION_UNIQUE_FIELD_UPDATE || code === StandardErrorCode.INVALID_ENTITY_TYPE || code === StandardErrorCode.INVALID_CONDITION || code === StandardErrorCode.INVALID_UNIQUE_VALUE_TYPE) {
|
|
8947
|
-
c.status(httpStatus15.BAD_REQUEST);
|
|
8948
|
-
return c.json(__spreadValues({}, err.toJSON()));
|
|
8949
|
-
}
|
|
8950
|
-
if (code === StandardErrorCode.TRANSACTION_FAILED || code === StandardErrorCode.CONDITIONAL_CHECK_FAILED || code === StandardErrorCode.UNIQUE_VALUE_EXISTS) {
|
|
8951
|
-
c.status(httpStatus15.CONFLICT);
|
|
8952
|
-
return c.json(__spreadValues({}, err.toJSON()));
|
|
8953
|
-
}
|
|
8954
|
-
}
|
|
8955
|
-
throw err;
|
|
8956
|
-
}
|
|
8957
|
-
}));
|
|
8958
|
-
}
|
|
8959
|
-
};
|
|
8960
|
-
|
|
8961
|
-
// controllers/ws/create-ticket.controller.ts
|
|
8962
|
-
import { createMiddleware as createMiddleware18 } from "hono/factory";
|
|
8963
|
-
import { ulid as ulid5 } from "ulid";
|
|
8964
|
-
var TICKET_TTL_SECONDS = 30 * 60;
|
|
8965
|
-
var CreateTicketController = class {
|
|
8966
|
-
constructor(container) {
|
|
8967
|
-
this.container = container;
|
|
8968
|
-
this.controller = createMiddleware18((c) => __async(this, null, function* () {
|
|
8969
|
-
var _a;
|
|
8970
|
-
const { entityType, entityId } = c.req.param();
|
|
8971
|
-
let feedTypes;
|
|
8972
|
-
try {
|
|
8973
|
-
const body = yield c.req.json();
|
|
8974
|
-
feedTypes = body.feedTypes;
|
|
8975
|
-
} catch (e) {
|
|
8976
|
-
}
|
|
8977
|
-
if (!feedTypes || feedTypes.length === 0) {
|
|
8978
|
-
const allConfigs = this.container.config.EntityConfig;
|
|
8979
|
-
const visited = /* @__PURE__ */ new Set();
|
|
8980
|
-
const queue = [entityType];
|
|
8981
|
-
while (queue.length > 0) {
|
|
8982
|
-
const current = queue.shift();
|
|
8983
|
-
if (!current) continue;
|
|
8984
|
-
if (visited.has(current)) continue;
|
|
8985
|
-
visited.add(current);
|
|
8986
|
-
const config = allConfigs[current];
|
|
8987
|
-
if ((_a = config == null ? void 0 : config.mutual) == null ? void 0 : _a.mutualFields) {
|
|
8988
|
-
for (const field of Object.values(
|
|
8989
|
-
config.mutual.mutualFields
|
|
8990
|
-
)) {
|
|
8991
|
-
if (!visited.has(field.entityType)) {
|
|
8992
|
-
queue.push(field.entityType);
|
|
8993
|
-
}
|
|
8994
|
-
}
|
|
8995
|
-
}
|
|
8996
|
-
}
|
|
8997
|
-
visited.delete(entityType);
|
|
8998
|
-
feedTypes = Array.from(visited);
|
|
8999
|
-
}
|
|
9000
|
-
const ticket = ulid5();
|
|
9001
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
9002
|
-
const expiresAt = now + TICKET_TTL_SECONDS;
|
|
9003
|
-
yield this.container.websocketRepository.createTicket(
|
|
9004
|
-
ticket,
|
|
9005
|
-
entityType,
|
|
9006
|
-
entityId,
|
|
9007
|
-
feedTypes,
|
|
9008
|
-
expiresAt
|
|
9009
|
-
);
|
|
9010
|
-
const wsEndpoint = process.env.WEBSOCKET_URL || "";
|
|
9011
|
-
return c.json({
|
|
9012
|
-
ticket,
|
|
9013
|
-
wsUrl: wsEndpoint,
|
|
9014
|
-
expiresIn: TICKET_TTL_SECONDS
|
|
9015
|
-
});
|
|
9016
|
-
}));
|
|
9017
|
-
}
|
|
9018
|
-
};
|
|
9019
|
-
|
|
9020
|
-
// services/entity-service-lifecycle.ts
|
|
9021
|
-
var EntityServiceLifeCycle = class {
|
|
9022
|
-
constructor(EntityConfig, publishEvent2, eventUtils) {
|
|
9023
|
-
this.EntityConfig = EntityConfig;
|
|
9024
|
-
this.publishEvent = publishEvent2;
|
|
9025
|
-
this.eventUtils = eventUtils;
|
|
9026
|
-
}
|
|
9027
|
-
afterCreateEntityHook(entity, entityPayload, accountId) {
|
|
9028
|
-
return __async(this, null, function* () {
|
|
8085
|
+
// services/entity-service-lifecycle.ts
|
|
8086
|
+
var EntityServiceLifeCycle = class {
|
|
8087
|
+
constructor(EntityConfig, publishEvent2, eventUtils) {
|
|
8088
|
+
this.EntityConfig = EntityConfig;
|
|
8089
|
+
this.publishEvent = publishEvent2;
|
|
8090
|
+
this.eventUtils = eventUtils;
|
|
8091
|
+
}
|
|
8092
|
+
afterCreateEntityHook(entity, entityPayload, accountId) {
|
|
8093
|
+
return __async(this, null, function* () {
|
|
9029
8094
|
var _a;
|
|
9030
8095
|
const mutualSchema = (_a = this.EntityConfig[entity.entityType].mutual) == null ? void 0 : _a.mutualSchema;
|
|
9031
8096
|
const parsedMutualPayload = mutualSchema == null ? void 0 : mutualSchema.parse(entityPayload);
|
|
@@ -9049,435 +8114,6 @@ var EntityServiceLifeCycle = class {
|
|
|
9049
8114
|
}
|
|
9050
8115
|
};
|
|
9051
8116
|
|
|
9052
|
-
// services/transaction.service.ts
|
|
9053
|
-
import { TransactionCanceledException as TransactionCanceledException5 } from "@aws-sdk/client-dynamodb";
|
|
9054
|
-
import { ulid as ulid6 } from "ulid";
|
|
9055
|
-
var MAX_TRANSACTION_ITEMS = 100;
|
|
9056
|
-
var TransactionService = class {
|
|
9057
|
-
constructor(EntityConfig, EmailAuthEnabledEntities, entityRepository, dynamodbClient, publishEvent2, entityServiceLifeCycle, eventUtils) {
|
|
9058
|
-
this.EntityConfig = EntityConfig;
|
|
9059
|
-
this.EmailAuthEnabledEntities = EmailAuthEnabledEntities;
|
|
9060
|
-
this.entityRepository = entityRepository;
|
|
9061
|
-
this.dynamodbClient = dynamodbClient;
|
|
9062
|
-
this.publishEvent = publishEvent2;
|
|
9063
|
-
this.entityServiceLifeCycle = entityServiceLifeCycle;
|
|
9064
|
-
this.eventUtils = eventUtils;
|
|
9065
|
-
this.executeTransaction = (operations, accountId) => __async(this, null, function* () {
|
|
9066
|
-
var _a;
|
|
9067
|
-
if (!operations || operations.length === 0) {
|
|
9068
|
-
throw new StandardError(
|
|
9069
|
-
StandardErrorCode.TRANSACTION_EMPTY,
|
|
9070
|
-
"Transaction must contain at least one operation"
|
|
9071
|
-
);
|
|
9072
|
-
}
|
|
9073
|
-
const allTransactItems = [];
|
|
9074
|
-
const pendingEvents = [];
|
|
9075
|
-
const resultEntries = [];
|
|
9076
|
-
for (const op of operations) {
|
|
9077
|
-
switch (op.operation) {
|
|
9078
|
-
case "createEntity": {
|
|
9079
|
-
const { items, entity } = yield this.buildCreateItems(op);
|
|
9080
|
-
allTransactItems.push(...items);
|
|
9081
|
-
pendingEvents.push(
|
|
9082
|
-
...this.collectCreateEvents(
|
|
9083
|
-
entity,
|
|
9084
|
-
op.payload,
|
|
9085
|
-
accountId
|
|
9086
|
-
)
|
|
9087
|
-
);
|
|
9088
|
-
resultEntries.push({
|
|
9089
|
-
operation: "createEntity",
|
|
9090
|
-
entityType: op.entityType,
|
|
9091
|
-
entityId: entity.entityId,
|
|
9092
|
-
data: entity.data
|
|
9093
|
-
});
|
|
9094
|
-
break;
|
|
9095
|
-
}
|
|
9096
|
-
case "updateEntity": {
|
|
9097
|
-
const { item, updatedAt } = yield this.buildUpdateItem(op);
|
|
9098
|
-
allTransactItems.push(item);
|
|
9099
|
-
pendingEvents.push(
|
|
9100
|
-
...this.collectUpdateEvents(
|
|
9101
|
-
op,
|
|
9102
|
-
updatedAt,
|
|
9103
|
-
accountId
|
|
9104
|
-
)
|
|
9105
|
-
);
|
|
9106
|
-
resultEntries.push({
|
|
9107
|
-
operation: "updateEntity",
|
|
9108
|
-
entityType: op.entityType,
|
|
9109
|
-
entityId: op.entityId
|
|
9110
|
-
});
|
|
9111
|
-
break;
|
|
9112
|
-
}
|
|
9113
|
-
case "adjustEntity": {
|
|
9114
|
-
const { item, updatedAt } = yield this.buildAdjustItem(op);
|
|
9115
|
-
allTransactItems.push(item);
|
|
9116
|
-
pendingEvents.push({
|
|
9117
|
-
event: EVENT.CORE.ENTITY_UPDATED,
|
|
9118
|
-
payload: {
|
|
9119
|
-
entityType: op.entityType,
|
|
9120
|
-
entityId: op.entityId,
|
|
9121
|
-
updatedByAccountId: accountId,
|
|
9122
|
-
publishedAt: updatedAt
|
|
9123
|
-
}
|
|
9124
|
-
});
|
|
9125
|
-
resultEntries.push({
|
|
9126
|
-
operation: "adjustEntity",
|
|
9127
|
-
entityType: op.entityType,
|
|
9128
|
-
entityId: op.entityId
|
|
9129
|
-
});
|
|
9130
|
-
break;
|
|
9131
|
-
}
|
|
9132
|
-
case "deleteEntity": {
|
|
9133
|
-
const item = this.buildDeleteItem(op);
|
|
9134
|
-
allTransactItems.push(item);
|
|
9135
|
-
pendingEvents.push({
|
|
9136
|
-
event: EVENT.CORE.ENTITY_DELETED,
|
|
9137
|
-
payload: {
|
|
9138
|
-
entityType: op.entityType,
|
|
9139
|
-
entityId: op.entityId,
|
|
9140
|
-
deletedByAccountId: accountId
|
|
9141
|
-
}
|
|
9142
|
-
});
|
|
9143
|
-
resultEntries.push({
|
|
9144
|
-
operation: "deleteEntity",
|
|
9145
|
-
entityType: op.entityType,
|
|
9146
|
-
entityId: op.entityId
|
|
9147
|
-
});
|
|
9148
|
-
break;
|
|
9149
|
-
}
|
|
9150
|
-
default:
|
|
9151
|
-
throw new StandardError(
|
|
9152
|
-
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
9153
|
-
`Unknown operation: '${op.operation}'`
|
|
9154
|
-
);
|
|
9155
|
-
}
|
|
9156
|
-
}
|
|
9157
|
-
if (allTransactItems.length > MAX_TRANSACTION_ITEMS) {
|
|
9158
|
-
throw new StandardError(
|
|
9159
|
-
StandardErrorCode.TRANSACTION_ITEM_LIMIT_EXCEEDED,
|
|
9160
|
-
`Transaction contains ${allTransactItems.length} items, exceeds limit of ${MAX_TRANSACTION_ITEMS}`
|
|
9161
|
-
);
|
|
9162
|
-
}
|
|
9163
|
-
try {
|
|
9164
|
-
yield this.dynamodbClient.transactWriteItems({
|
|
9165
|
-
TransactItems: allTransactItems
|
|
9166
|
-
});
|
|
9167
|
-
} catch (err) {
|
|
9168
|
-
if (err instanceof TransactionCanceledException5) {
|
|
9169
|
-
throw new StandardError(
|
|
9170
|
-
StandardErrorCode.TRANSACTION_FAILED,
|
|
9171
|
-
"Transaction failed",
|
|
9172
|
-
err,
|
|
9173
|
-
{
|
|
9174
|
-
reasons: (_a = err.CancellationReasons) == null ? void 0 : _a.map((r, i) => ({
|
|
9175
|
-
index: i,
|
|
9176
|
-
code: r.Code,
|
|
9177
|
-
message: r.Message
|
|
9178
|
-
}))
|
|
9179
|
-
}
|
|
9180
|
-
);
|
|
9181
|
-
}
|
|
9182
|
-
throw err;
|
|
9183
|
-
}
|
|
9184
|
-
const readPromises = resultEntries.map((entry) => __async(this, null, function* () {
|
|
9185
|
-
if ((entry.operation === "updateEntity" || entry.operation === "adjustEntity") && !entry.data) {
|
|
9186
|
-
try {
|
|
9187
|
-
const entity = yield this.entityRepository.getEntity(
|
|
9188
|
-
entry.entityType,
|
|
9189
|
-
entry.entityId
|
|
9190
|
-
);
|
|
9191
|
-
entry.data = entity.data;
|
|
9192
|
-
} catch (e) {
|
|
9193
|
-
}
|
|
9194
|
-
}
|
|
9195
|
-
}));
|
|
9196
|
-
yield Promise.all(readPromises);
|
|
9197
|
-
yield Promise.allSettled(pendingEvents.map((ev) => this.publishEvent(ev)));
|
|
9198
|
-
return { results: resultEntries };
|
|
9199
|
-
});
|
|
9200
|
-
}
|
|
9201
|
-
buildCreateItems(op) {
|
|
9202
|
-
return __async(this, null, function* () {
|
|
9203
|
-
const config = this.EntityConfig[op.entityType];
|
|
9204
|
-
if (!config) {
|
|
9205
|
-
throw new StandardError(
|
|
9206
|
-
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
9207
|
-
`Unknown entity type: '${op.entityType}'`
|
|
9208
|
-
);
|
|
9209
|
-
}
|
|
9210
|
-
const entitySchema = config.createSchema || config.baseSchema;
|
|
9211
|
-
if (!entitySchema) {
|
|
9212
|
-
throw new StandardError(
|
|
9213
|
-
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
9214
|
-
`No schema defined for entity type: '${op.entityType}'`
|
|
9215
|
-
);
|
|
9216
|
-
}
|
|
9217
|
-
if (config.finalSchema) {
|
|
9218
|
-
config.finalSchema.parse(op.payload);
|
|
9219
|
-
}
|
|
9220
|
-
const parsedPayload = entitySchema.parse(
|
|
9221
|
-
op.payload
|
|
9222
|
-
);
|
|
9223
|
-
const currentDatetime = /* @__PURE__ */ new Date();
|
|
9224
|
-
const entity = new Entity(
|
|
9225
|
-
op.entityType,
|
|
9226
|
-
op.entityId || ulid6(),
|
|
9227
|
-
parsedPayload,
|
|
9228
|
-
currentDatetime,
|
|
9229
|
-
currentDatetime
|
|
9230
|
-
);
|
|
9231
|
-
const uniqueFields = config.uniqueFields || [];
|
|
9232
|
-
const uniqueFieldValues = {};
|
|
9233
|
-
for (const field of uniqueFields) {
|
|
9234
|
-
if (!(field in parsedPayload)) continue;
|
|
9235
|
-
const value = parsedPayload[field];
|
|
9236
|
-
if (typeof value !== "string") {
|
|
9237
|
-
throw new StandardError(
|
|
9238
|
-
StandardErrorCode.INVALID_UNIQUE_VALUE_TYPE,
|
|
9239
|
-
`Invalid type. ${field} is not a 'string'.`
|
|
9240
|
-
);
|
|
9241
|
-
}
|
|
9242
|
-
uniqueFieldValues[field] = value;
|
|
9243
|
-
}
|
|
9244
|
-
const items = this.entityRepository.createEntityTransactItems(entity, {
|
|
9245
|
-
uniqueFieldValues
|
|
9246
|
-
});
|
|
9247
|
-
return { items, entity };
|
|
9248
|
-
});
|
|
9249
|
-
}
|
|
9250
|
-
buildUpdateItem(op) {
|
|
9251
|
-
return __async(this, null, function* () {
|
|
9252
|
-
const config = this.EntityConfig[op.entityType];
|
|
9253
|
-
if (!config) {
|
|
9254
|
-
throw new StandardError(
|
|
9255
|
-
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
9256
|
-
`Unknown entity type: '${op.entityType}'`
|
|
9257
|
-
);
|
|
9258
|
-
}
|
|
9259
|
-
const uniqueFields = config.uniqueFields || [];
|
|
9260
|
-
for (const field of uniqueFields) {
|
|
9261
|
-
if (field in op.payload) {
|
|
9262
|
-
throw new StandardError(
|
|
9263
|
-
StandardErrorCode.TRANSACTION_UNIQUE_FIELD_UPDATE,
|
|
9264
|
-
`Cannot update unique field '${field}' within a transaction. Use a standalone updateEntity call instead.`
|
|
9265
|
-
);
|
|
9266
|
-
}
|
|
9267
|
-
}
|
|
9268
|
-
const entitySchema = config.baseSchema;
|
|
9269
|
-
if (!entitySchema) {
|
|
9270
|
-
throw new StandardError(
|
|
9271
|
-
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
9272
|
-
`No schema defined for entity type: '${op.entityType}'`
|
|
9273
|
-
);
|
|
9274
|
-
}
|
|
9275
|
-
const parsedPayload = entitySchema.partial().parse(op.payload);
|
|
9276
|
-
const currentDatetime = (/* @__PURE__ */ new Date()).toISOString();
|
|
9277
|
-
const toUpdateExpressions = this.entityRepository.toUpdate({
|
|
9278
|
-
updatedAt: currentDatetime,
|
|
9279
|
-
data: parsedPayload
|
|
9280
|
-
});
|
|
9281
|
-
let conditionOpts;
|
|
9282
|
-
if (op.condition) {
|
|
9283
|
-
const updateConditions = config.updateConditions;
|
|
9284
|
-
if (!updateConditions) {
|
|
9285
|
-
throw new StandardError(
|
|
9286
|
-
StandardErrorCode.INVALID_CONDITION,
|
|
9287
|
-
`Entity '${op.entityType}' has no updateConditions defined`
|
|
9288
|
-
);
|
|
9289
|
-
}
|
|
9290
|
-
conditionOpts = yield resolveUpdateCondition({
|
|
9291
|
-
conditionName: op.condition,
|
|
9292
|
-
conditions: updateConditions,
|
|
9293
|
-
getEntityData: () => __async(this, null, function* () {
|
|
9294
|
-
var _a;
|
|
9295
|
-
const entity2 = yield this.entityRepository.getEntity(
|
|
9296
|
-
op.entityType,
|
|
9297
|
-
op.entityId
|
|
9298
|
-
);
|
|
9299
|
-
return (_a = entity2 == null ? void 0 : entity2.data) != null ? _a : {};
|
|
9300
|
-
})
|
|
9301
|
-
});
|
|
9302
|
-
}
|
|
9303
|
-
const entity = new Entity(op.entityType, op.entityId);
|
|
9304
|
-
const item = {
|
|
9305
|
-
Update: {
|
|
9306
|
-
TableName: this.entityRepository.TABLE_NAME,
|
|
9307
|
-
Key: entity.keys(),
|
|
9308
|
-
ConditionExpression: (conditionOpts == null ? void 0 : conditionOpts.ConditionExpression) || "attribute_exists(PK)",
|
|
9309
|
-
UpdateExpression: toUpdateExpressions.UpdateExpression,
|
|
9310
|
-
ExpressionAttributeNames: __spreadValues(__spreadValues({}, toUpdateExpressions.ExpressionAttributeNames), conditionOpts == null ? void 0 : conditionOpts.ExpressionAttributeNames),
|
|
9311
|
-
ExpressionAttributeValues: __spreadValues(__spreadValues({}, toUpdateExpressions.ExpressionAttributeValues), conditionOpts == null ? void 0 : conditionOpts.ExpressionAttributeValues)
|
|
9312
|
-
}
|
|
9313
|
-
};
|
|
9314
|
-
return { item, updatedAt: currentDatetime };
|
|
9315
|
-
});
|
|
9316
|
-
}
|
|
9317
|
-
buildAdjustItem(op) {
|
|
9318
|
-
return __async(this, null, function* () {
|
|
9319
|
-
const config = this.EntityConfig[op.entityType];
|
|
9320
|
-
if (!config) {
|
|
9321
|
-
throw new StandardError(
|
|
9322
|
-
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
9323
|
-
`Unknown entity type: '${op.entityType}'`
|
|
9324
|
-
);
|
|
9325
|
-
}
|
|
9326
|
-
for (const [key, value] of Object.entries(op.adjustments)) {
|
|
9327
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
9328
|
-
throw new StandardError(
|
|
9329
|
-
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
9330
|
-
`Adjustment field "${key}" must be a finite number`
|
|
9331
|
-
);
|
|
9332
|
-
}
|
|
9333
|
-
}
|
|
9334
|
-
const {
|
|
9335
|
-
UpdateExpression,
|
|
9336
|
-
ExpressionAttributeNames,
|
|
9337
|
-
ExpressionAttributeValues
|
|
9338
|
-
} = this.entityRepository.toAdjustUpdate(op.adjustments);
|
|
9339
|
-
const currentDatetime = (/* @__PURE__ */ new Date()).toISOString();
|
|
9340
|
-
ExpressionAttributeNames["#updatedAt"] = "updatedAt";
|
|
9341
|
-
ExpressionAttributeValues[":updatedAt"] = { S: currentDatetime };
|
|
9342
|
-
const fullUpdateExpression = `${UpdateExpression}, #updatedAt = :updatedAt`;
|
|
9343
|
-
let conditionOpts;
|
|
9344
|
-
const adjustmentConditions = config.adjustmentConditions;
|
|
9345
|
-
if (adjustmentConditions) {
|
|
9346
|
-
if (!op.condition) {
|
|
9347
|
-
throw new StandardError(
|
|
9348
|
-
StandardErrorCode.INVALID_CONDITION,
|
|
9349
|
-
`Entity '${op.entityType}' has adjustmentConditions defined; condition is required`
|
|
9350
|
-
);
|
|
9351
|
-
}
|
|
9352
|
-
conditionOpts = yield resolveAdjustmentCondition({
|
|
9353
|
-
conditionName: op.condition,
|
|
9354
|
-
conditions: adjustmentConditions,
|
|
9355
|
-
adjustments: op.adjustments,
|
|
9356
|
-
getEntityData: () => __async(this, null, function* () {
|
|
9357
|
-
var _a;
|
|
9358
|
-
const entity2 = yield this.entityRepository.getEntity(
|
|
9359
|
-
op.entityType,
|
|
9360
|
-
op.entityId
|
|
9361
|
-
);
|
|
9362
|
-
return (_a = entity2 == null ? void 0 : entity2.data) != null ? _a : {};
|
|
9363
|
-
})
|
|
9364
|
-
});
|
|
9365
|
-
}
|
|
9366
|
-
const entity = new Entity(op.entityType, op.entityId);
|
|
9367
|
-
const item = {
|
|
9368
|
-
Update: {
|
|
9369
|
-
TableName: this.entityRepository.TABLE_NAME,
|
|
9370
|
-
Key: entity.keys(),
|
|
9371
|
-
UpdateExpression: fullUpdateExpression,
|
|
9372
|
-
ConditionExpression: (conditionOpts == null ? void 0 : conditionOpts.ConditionExpression) || "attribute_exists(PK)",
|
|
9373
|
-
ExpressionAttributeNames: __spreadValues(__spreadValues({}, ExpressionAttributeNames), conditionOpts == null ? void 0 : conditionOpts.ExpressionAttributeNames),
|
|
9374
|
-
ExpressionAttributeValues: __spreadValues(__spreadValues({}, ExpressionAttributeValues), conditionOpts == null ? void 0 : conditionOpts.ExpressionAttributeValues)
|
|
9375
|
-
}
|
|
9376
|
-
};
|
|
9377
|
-
return { item, updatedAt: currentDatetime };
|
|
9378
|
-
});
|
|
9379
|
-
}
|
|
9380
|
-
buildDeleteItem(op) {
|
|
9381
|
-
const config = this.EntityConfig[op.entityType];
|
|
9382
|
-
if (!config) {
|
|
9383
|
-
throw new StandardError(
|
|
9384
|
-
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
9385
|
-
`Unknown entity type: '${op.entityType}'`
|
|
9386
|
-
);
|
|
9387
|
-
}
|
|
9388
|
-
const entity = new Entity(op.entityType, op.entityId);
|
|
9389
|
-
return {
|
|
9390
|
-
Delete: {
|
|
9391
|
-
TableName: this.entityRepository.TABLE_NAME,
|
|
9392
|
-
Key: entity.keys(),
|
|
9393
|
-
ConditionExpression: "attribute_exists(PK)"
|
|
9394
|
-
}
|
|
9395
|
-
};
|
|
9396
|
-
}
|
|
9397
|
-
collectCreateEvents(entity, payload, accountId) {
|
|
9398
|
-
var _a, _b;
|
|
9399
|
-
const events = [];
|
|
9400
|
-
const publishedAt = entity.updatedAt || (/* @__PURE__ */ new Date()).toISOString();
|
|
9401
|
-
const config = this.EntityConfig[entity.entityType];
|
|
9402
|
-
const mutualSchema = (_a = config == null ? void 0 : config.mutual) == null ? void 0 : _a.mutualSchema;
|
|
9403
|
-
if (mutualSchema) {
|
|
9404
|
-
const parsedMutualPayload = mutualSchema.parse(payload);
|
|
9405
|
-
if (parsedMutualPayload) {
|
|
9406
|
-
for (const [fieldKey, fieldConfig] of Object.entries(
|
|
9407
|
-
((_b = config.mutual) == null ? void 0 : _b.mutualFields) || {}
|
|
9408
|
-
)) {
|
|
9409
|
-
const toMutualIds = fieldConfig.toMutualIds;
|
|
9410
|
-
const mutualPayload = parsedMutualPayload[fieldKey];
|
|
9411
|
-
if (!mutualPayload) continue;
|
|
9412
|
-
events.push({
|
|
9413
|
-
event: EVENT.CORE.ENTITY_MUTUAL_TO_CREATE,
|
|
9414
|
-
payload: {
|
|
9415
|
-
byEntityType: entity.entityType,
|
|
9416
|
-
byEntityId: entity.entityId,
|
|
9417
|
-
entityType: fieldConfig.entityType,
|
|
9418
|
-
field: fieldKey,
|
|
9419
|
-
mutualIds: toMutualIds ? toMutualIds(mutualPayload) : mutualPayload,
|
|
9420
|
-
customContext: toMutualIds ? mutualPayload : {},
|
|
9421
|
-
publishedAt
|
|
9422
|
-
}
|
|
9423
|
-
});
|
|
9424
|
-
}
|
|
9425
|
-
}
|
|
9426
|
-
}
|
|
9427
|
-
events.push({
|
|
9428
|
-
event: EVENT.CORE.ENTITY_CREATED,
|
|
9429
|
-
payload: {
|
|
9430
|
-
entityType: entity.entityType,
|
|
9431
|
-
entityId: entity.entityId,
|
|
9432
|
-
data: entity.data,
|
|
9433
|
-
createdByAccountId: accountId,
|
|
9434
|
-
publishedAt
|
|
9435
|
-
}
|
|
9436
|
-
});
|
|
9437
|
-
return events;
|
|
9438
|
-
}
|
|
9439
|
-
collectUpdateEvents(op, updatedAt, accountId) {
|
|
9440
|
-
var _a, _b;
|
|
9441
|
-
const events = [];
|
|
9442
|
-
const config = this.EntityConfig[op.entityType];
|
|
9443
|
-
const mutualSchema = (_a = config == null ? void 0 : config.mutual) == null ? void 0 : _a.mutualSchema;
|
|
9444
|
-
if (mutualSchema) {
|
|
9445
|
-
const parsedMutualPayload = mutualSchema.parse(op.payload);
|
|
9446
|
-
if (parsedMutualPayload) {
|
|
9447
|
-
for (const [fieldKey, fieldConfig] of Object.entries(
|
|
9448
|
-
((_b = config.mutual) == null ? void 0 : _b.mutualFields) || {}
|
|
9449
|
-
)) {
|
|
9450
|
-
const toMutualIds = fieldConfig.toMutualIds;
|
|
9451
|
-
const mutualPayload = parsedMutualPayload[fieldKey];
|
|
9452
|
-
if (!mutualPayload) continue;
|
|
9453
|
-
events.push({
|
|
9454
|
-
event: EVENT.CORE.ENTITY_MUTUAL_TO_UPDATE,
|
|
9455
|
-
payload: {
|
|
9456
|
-
byEntityType: op.entityType,
|
|
9457
|
-
byEntityId: op.entityId,
|
|
9458
|
-
entityType: fieldConfig.entityType,
|
|
9459
|
-
field: fieldKey,
|
|
9460
|
-
mutualIds: toMutualIds ? toMutualIds(mutualPayload) : mutualPayload,
|
|
9461
|
-
customContext: toMutualIds ? mutualPayload : {},
|
|
9462
|
-
publishedAt: updatedAt
|
|
9463
|
-
}
|
|
9464
|
-
});
|
|
9465
|
-
}
|
|
9466
|
-
}
|
|
9467
|
-
}
|
|
9468
|
-
events.push({
|
|
9469
|
-
event: EVENT.CORE.ENTITY_UPDATED,
|
|
9470
|
-
payload: {
|
|
9471
|
-
entityType: op.entityType,
|
|
9472
|
-
entityId: op.entityId,
|
|
9473
|
-
updatedByAccountId: accountId,
|
|
9474
|
-
publishedAt: updatedAt
|
|
9475
|
-
}
|
|
9476
|
-
});
|
|
9477
|
-
return events;
|
|
9478
|
-
}
|
|
9479
|
-
};
|
|
9480
|
-
|
|
9481
8117
|
// services/DependencyContainer.ts
|
|
9482
8118
|
var DependencyContainer = class {
|
|
9483
8119
|
constructor(config) {
|
|
@@ -9556,7 +8192,6 @@ var DependencyContainer = class {
|
|
|
9556
8192
|
get mutualService() {
|
|
9557
8193
|
return this.createCachedInstance(
|
|
9558
8194
|
MutualService,
|
|
9559
|
-
this.config.EntityConfig,
|
|
9560
8195
|
this.entityRepository,
|
|
9561
8196
|
this.mutualRepository,
|
|
9562
8197
|
this.publishEvent,
|
|
@@ -9571,13 +8206,6 @@ var DependencyContainer = class {
|
|
|
9571
8206
|
this.dynamodbClient
|
|
9572
8207
|
);
|
|
9573
8208
|
}
|
|
9574
|
-
get websocketRepository() {
|
|
9575
|
-
return this.createCachedInstance(
|
|
9576
|
-
WebSocketRepository,
|
|
9577
|
-
this.coreTable,
|
|
9578
|
-
this.dynamodbClient
|
|
9579
|
-
);
|
|
9580
|
-
}
|
|
9581
8209
|
get getEntityController() {
|
|
9582
8210
|
return this.createCachedInstance(
|
|
9583
8211
|
GetEntityController,
|
|
@@ -9661,90 +8289,6 @@ var DependencyContainer = class {
|
|
|
9661
8289
|
get listTagsController() {
|
|
9662
8290
|
return this.createCachedInstance(ListTagsController, this.tagRepository);
|
|
9663
8291
|
}
|
|
9664
|
-
get transactionService() {
|
|
9665
|
-
return this.createCachedInstance(
|
|
9666
|
-
TransactionService,
|
|
9667
|
-
this.config.EntityConfig,
|
|
9668
|
-
this.config.EmailAuthEnabledEntities,
|
|
9669
|
-
this.entityRepository,
|
|
9670
|
-
this.dynamodbClient,
|
|
9671
|
-
this.publishEvent,
|
|
9672
|
-
this.entityServiceLifeCycle,
|
|
9673
|
-
this.eventUtils
|
|
9674
|
-
);
|
|
9675
|
-
}
|
|
9676
|
-
get executeTransactionController() {
|
|
9677
|
-
return this.createCachedInstance(
|
|
9678
|
-
ExecuteTransactionController,
|
|
9679
|
-
this.transactionService
|
|
9680
|
-
);
|
|
9681
|
-
}
|
|
9682
|
-
get createTicketController() {
|
|
9683
|
-
return this.createCachedInstance(CreateTicketController, this);
|
|
9684
|
-
}
|
|
9685
|
-
};
|
|
9686
|
-
|
|
9687
|
-
// ../base/dist/index.js
|
|
9688
|
-
var __defProp = Object.defineProperty;
|
|
9689
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9690
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9691
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9692
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9693
|
-
var __spreadValues2 = (a, b) => {
|
|
9694
|
-
for (var prop in b || (b = {}))
|
|
9695
|
-
if (__hasOwnProp.call(b, prop))
|
|
9696
|
-
__defNormalProp(a, prop, b[prop]);
|
|
9697
|
-
if (__getOwnPropSymbols)
|
|
9698
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
9699
|
-
if (__propIsEnum.call(b, prop))
|
|
9700
|
-
__defNormalProp(a, prop, b[prop]);
|
|
9701
|
-
}
|
|
9702
|
-
return a;
|
|
9703
|
-
};
|
|
9704
|
-
var __objRest2 = (source, exclude) => {
|
|
9705
|
-
var target = {};
|
|
9706
|
-
for (var prop in source)
|
|
9707
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
9708
|
-
target[prop] = source[prop];
|
|
9709
|
-
if (source != null && __getOwnPropSymbols)
|
|
9710
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
9711
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
9712
|
-
target[prop] = source[prop];
|
|
9713
|
-
}
|
|
9714
|
-
return target;
|
|
9715
|
-
};
|
|
9716
|
-
var transactional = {
|
|
9717
|
-
createEntity: (entityType, payload) => {
|
|
9718
|
-
const _a = payload, { entityId } = _a, rest = __objRest2(_a, ["entityId"]);
|
|
9719
|
-
return __spreadValues2({
|
|
9720
|
-
operation: "createEntity",
|
|
9721
|
-
entityType,
|
|
9722
|
-
payload: rest
|
|
9723
|
-
}, entityId && { entityId });
|
|
9724
|
-
},
|
|
9725
|
-
updateEntity: (entityType, entityId, payload) => {
|
|
9726
|
-
const _a = payload, { $condition } = _a, rest = __objRest2(_a, ["$condition"]);
|
|
9727
|
-
return __spreadValues2({
|
|
9728
|
-
operation: "updateEntity",
|
|
9729
|
-
entityType,
|
|
9730
|
-
entityId,
|
|
9731
|
-
payload: rest
|
|
9732
|
-
}, $condition && { condition: $condition });
|
|
9733
|
-
},
|
|
9734
|
-
adjustEntity: (entityType, entityId, adjustments) => {
|
|
9735
|
-
const _a = adjustments, { $condition } = _a, rest = __objRest2(_a, ["$condition"]);
|
|
9736
|
-
return __spreadValues2({
|
|
9737
|
-
operation: "adjustEntity",
|
|
9738
|
-
entityType,
|
|
9739
|
-
entityId,
|
|
9740
|
-
adjustments: rest
|
|
9741
|
-
}, $condition && { condition: $condition });
|
|
9742
|
-
},
|
|
9743
|
-
deleteEntity: (entityType, entityId) => ({
|
|
9744
|
-
operation: "deleteEntity",
|
|
9745
|
-
entityType,
|
|
9746
|
-
entityId
|
|
9747
|
-
})
|
|
9748
8292
|
};
|
|
9749
8293
|
|
|
9750
8294
|
// index.ts
|
|
@@ -9760,10 +8304,6 @@ var CoreFactory = class {
|
|
|
9760
8304
|
this.prejoinProcessor = handler3(dependencyContainer);
|
|
9761
8305
|
this.tagProcessor = handler5(dependencyContainer);
|
|
9762
8306
|
this.appHandler = appHandler(dependencyContainer);
|
|
9763
|
-
this.wsConnect = connect(dependencyContainer);
|
|
9764
|
-
this.wsDisconnect = disconnect(dependencyContainer);
|
|
9765
|
-
this.wsDefault = $default(dependencyContainer);
|
|
9766
|
-
this.wsBroadcast = broadcast(dependencyContainer);
|
|
9767
8307
|
}
|
|
9768
8308
|
};
|
|
9769
8309
|
var index_default = CoreFactory;
|
|
@@ -9779,8 +8319,6 @@ export {
|
|
|
9779
8319
|
StandardError,
|
|
9780
8320
|
StandardErrorCode,
|
|
9781
8321
|
TagRepository,
|
|
9782
|
-
TransactionService,
|
|
9783
|
-
WebSocketRepository,
|
|
9784
8322
|
appHandler,
|
|
9785
8323
|
handler as createEntityProcessor,
|
|
9786
8324
|
index_default as default,
|
|
@@ -9788,11 +8326,6 @@ export {
|
|
|
9788
8326
|
handler3 as prejoinProcessor,
|
|
9789
8327
|
handler4 as replicationProcessor,
|
|
9790
8328
|
setupCommonRoutes,
|
|
9791
|
-
handler5 as tagProcessor
|
|
9792
|
-
transactional,
|
|
9793
|
-
broadcast as wsBroadcast,
|
|
9794
|
-
connect as wsConnect,
|
|
9795
|
-
$default as wsDefault,
|
|
9796
|
-
disconnect as wsDisconnect
|
|
8329
|
+
handler5 as tagProcessor
|
|
9797
8330
|
};
|
|
9798
8331
|
//# sourceMappingURL=index.js.map
|