monorise 1.5.0 → 1.6.0
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/cli/cli.js +2 -2
- package/dist/core/index.d.ts +83 -2
- package/dist/core/index.js +580 -1
- package/dist/core/index.js.map +1 -1
- package/dist/react/chunk-5XIRNUBL.js +43 -0
- package/dist/react/chunk-5XIRNUBL.js.map +1 -0
- package/dist/react/chunk-7JDOKZGQ.js +172 -0
- package/dist/react/chunk-7JDOKZGQ.js.map +1 -0
- package/dist/react/chunk-A5TI2FW3.js +13 -0
- package/dist/react/chunk-A5TI2FW3.js.map +1 -0
- package/dist/react/chunk-AYQDOLYF.js +628 -0
- package/dist/react/chunk-AYQDOLYF.js.map +1 -0
- package/dist/react/chunk-BUTF5RJU.js +29 -0
- package/dist/react/chunk-BUTF5RJU.js.map +1 -0
- package/dist/react/chunk-EYG2DL3D.js +893 -0
- package/dist/react/chunk-EYG2DL3D.js.map +1 -0
- package/dist/react/chunk-GEN4TSCQ.js +5179 -0
- package/dist/react/chunk-GEN4TSCQ.js.map +1 -0
- package/dist/react/chunk-GFVCNWVT.js +54 -0
- package/dist/react/chunk-GFVCNWVT.js.map +1 -0
- package/dist/react/chunk-KJX5LOMN.js +43 -0
- package/dist/react/chunk-KJX5LOMN.js.map +1 -0
- package/dist/react/chunk-KLXK4V6G.js +65 -0
- package/dist/react/chunk-KLXK4V6G.js.map +1 -0
- package/dist/react/chunk-L6MAS3AX.js +482 -0
- package/dist/react/chunk-L6MAS3AX.js.map +1 -0
- package/dist/react/chunk-LPXR5V4J.js +582 -0
- package/dist/react/chunk-LPXR5V4J.js.map +1 -0
- package/dist/react/chunk-MIXAYX55.js +147 -0
- package/dist/react/chunk-MIXAYX55.js.map +1 -0
- package/dist/react/chunk-OEHQ546W.js +182 -0
- package/dist/react/chunk-OEHQ546W.js.map +1 -0
- package/dist/react/chunk-RPNCWADG.js +248 -0
- package/dist/react/chunk-RPNCWADG.js.map +1 -0
- package/dist/react/chunk-S6RDMHHH.js +47 -0
- package/dist/react/chunk-S6RDMHHH.js.map +1 -0
- package/dist/react/chunk-VVCM7N22.js +101 -0
- package/dist/react/chunk-VVCM7N22.js.map +1 -0
- package/dist/react/dist-es-5WYA7CWK.js +379 -0
- package/dist/react/dist-es-5WYA7CWK.js.map +1 -0
- package/dist/react/dist-es-DLWQXBOR.js +333 -0
- package/dist/react/dist-es-DLWQXBOR.js.map +1 -0
- package/dist/react/dist-es-EMJCB37T.js +71 -0
- package/dist/react/dist-es-EMJCB37T.js.map +1 -0
- package/dist/react/dist-es-Q7IAXWRB.js +494 -0
- package/dist/react/dist-es-Q7IAXWRB.js.map +1 -0
- package/dist/react/dist-es-QF65HH5Y.js +169 -0
- package/dist/react/dist-es-QF65HH5Y.js.map +1 -0
- package/dist/react/dist-es-R4TRTT45.js +22 -0
- package/dist/react/dist-es-R4TRTT45.js.map +1 -0
- package/dist/react/dist-es-XNAC47MK.js +90 -0
- package/dist/react/dist-es-XNAC47MK.js.map +1 -0
- package/dist/react/event-streams-6APKUBMC.js +270 -0
- package/dist/react/event-streams-6APKUBMC.js.map +1 -0
- package/dist/react/index.d.ts +17 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +8722 -159
- package/dist/react/index.js.map +1 -1
- package/dist/react/loadSso-WMS367NT.js +595 -0
- package/dist/react/loadSso-WMS367NT.js.map +1 -0
- package/dist/react/services/core.service.d.ts +8 -0
- package/dist/react/services/core.service.d.ts.map +1 -1
- package/dist/react/signin-2I7AG6XI.js +707 -0
- package/dist/react/signin-2I7AG6XI.js.map +1 -0
- package/dist/react/sso-oidc-OAJ7SALL.js +825 -0
- package/dist/react/sso-oidc-OAJ7SALL.js.map +1 -0
- package/dist/react/sts-LKM23TRV.js +3866 -0
- package/dist/react/sts-LKM23TRV.js.map +1 -0
- package/package.json +1 -1
package/dist/core/index.js
CHANGED
|
@@ -140,6 +140,7 @@ var setupCommonRoutes = (container) => {
|
|
|
140
140
|
container.deleteEntityController.controller
|
|
141
141
|
);
|
|
142
142
|
app.get("/tag/:entityType/:tagName", container.listTagsController.controller);
|
|
143
|
+
app.post("/transaction", container.executeTransactionController.controller);
|
|
143
144
|
return app;
|
|
144
145
|
};
|
|
145
146
|
|
|
@@ -188,7 +189,12 @@ var StandardErrorCode = {
|
|
|
188
189
|
REPLICATION_ERROR: "REPLICATION_ERROR",
|
|
189
190
|
RETRYABLE_MUTUAL_LOCK_CONFLICT: "RETRYABLE_MUTUAL_LOCK_CONFLICT",
|
|
190
191
|
TAG_IS_UNDEFINED: "TAG_IS_UNDEFINED",
|
|
192
|
+
TRANSACTION_EMPTY: "TRANSACTION_EMPTY",
|
|
191
193
|
TRANSACTION_FAILED: "TRANSACTION_FAILED",
|
|
194
|
+
TRANSACTION_INVALID_OPERATION: "TRANSACTION_INVALID_OPERATION",
|
|
195
|
+
TRANSACTION_ITEM_LIMIT_EXCEEDED: "TRANSACTION_ITEM_LIMIT_EXCEEDED",
|
|
196
|
+
TRANSACTION_UNIQUE_FIELD_UPDATE: "TRANSACTION_UNIQUE_FIELD_UPDATE",
|
|
197
|
+
TRANSACTION_VALIDATION_ERROR: "TRANSACTION_VALIDATION_ERROR",
|
|
192
198
|
UNIQUE_VALUE_EXISTS: "UNIQUE_VALUE_EXISTS"
|
|
193
199
|
};
|
|
194
200
|
|
|
@@ -8416,6 +8422,68 @@ var ListTagsController = class {
|
|
|
8416
8422
|
}
|
|
8417
8423
|
};
|
|
8418
8424
|
|
|
8425
|
+
// controllers/transaction/execute-transaction.controller.ts
|
|
8426
|
+
import { createMiddleware as createMiddleware17 } from "hono/factory";
|
|
8427
|
+
import httpStatus15 from "http-status";
|
|
8428
|
+
var ExecuteTransactionController = class {
|
|
8429
|
+
constructor(transactionService) {
|
|
8430
|
+
this.transactionService = transactionService;
|
|
8431
|
+
// biome-ignore lint/suspicious/noExplicitAny: Hono createMiddleware requires consistent return types
|
|
8432
|
+
this.controller = createMiddleware17((c) => __async(this, null, function* () {
|
|
8433
|
+
var _a;
|
|
8434
|
+
const accountId = c.req.header("account-id") || "";
|
|
8435
|
+
try {
|
|
8436
|
+
const body = yield c.req.json();
|
|
8437
|
+
if (!body.operations || !Array.isArray(body.operations)) {
|
|
8438
|
+
c.status(httpStatus15.BAD_REQUEST);
|
|
8439
|
+
return c.json({
|
|
8440
|
+
code: "API_VALIDATION_ERROR",
|
|
8441
|
+
message: 'Request body must contain an "operations" array'
|
|
8442
|
+
});
|
|
8443
|
+
}
|
|
8444
|
+
const result = yield this.transactionService.executeTransaction(
|
|
8445
|
+
body.operations,
|
|
8446
|
+
accountId
|
|
8447
|
+
);
|
|
8448
|
+
c.status(httpStatus15.OK);
|
|
8449
|
+
return c.json(result);
|
|
8450
|
+
} catch (err) {
|
|
8451
|
+
if (((_a = err.constructor) == null ? void 0 : _a.name) === "ZodError") {
|
|
8452
|
+
c.status(httpStatus15.BAD_REQUEST);
|
|
8453
|
+
return c.json({
|
|
8454
|
+
code: "API_VALIDATION_ERROR",
|
|
8455
|
+
message: "Validation failed",
|
|
8456
|
+
details: err.flatten()
|
|
8457
|
+
});
|
|
8458
|
+
}
|
|
8459
|
+
if (err instanceof SyntaxError) {
|
|
8460
|
+
c.status(httpStatus15.BAD_REQUEST);
|
|
8461
|
+
return c.json({
|
|
8462
|
+
code: "API_VALIDATION_ERROR",
|
|
8463
|
+
message: "Request body must be valid JSON"
|
|
8464
|
+
});
|
|
8465
|
+
}
|
|
8466
|
+
if (err instanceof StandardError) {
|
|
8467
|
+
const code = err.code;
|
|
8468
|
+
if (code === StandardErrorCode.ENTITY_IS_UNDEFINED || code === StandardErrorCode.ENTITY_NOT_FOUND) {
|
|
8469
|
+
c.status(httpStatus15.NOT_FOUND);
|
|
8470
|
+
return c.json(__spreadValues({}, err.toJSON()));
|
|
8471
|
+
}
|
|
8472
|
+
if (code === StandardErrorCode.TRANSACTION_EMPTY || code === StandardErrorCode.TRANSACTION_ITEM_LIMIT_EXCEEDED || code === StandardErrorCode.TRANSACTION_UNIQUE_FIELD_UPDATE || code === StandardErrorCode.TRANSACTION_INVALID_OPERATION || code === StandardErrorCode.TRANSACTION_VALIDATION_ERROR || code === StandardErrorCode.INVALID_ENTITY_TYPE || code === StandardErrorCode.INVALID_CONDITION || code === StandardErrorCode.INVALID_UNIQUE_VALUE_TYPE) {
|
|
8473
|
+
c.status(httpStatus15.BAD_REQUEST);
|
|
8474
|
+
return c.json(__spreadValues({}, err.toJSON()));
|
|
8475
|
+
}
|
|
8476
|
+
if (code === StandardErrorCode.TRANSACTION_FAILED || code === StandardErrorCode.CONDITIONAL_CHECK_FAILED || code === StandardErrorCode.UNIQUE_VALUE_EXISTS) {
|
|
8477
|
+
c.status(httpStatus15.CONFLICT);
|
|
8478
|
+
return c.json(__spreadValues({}, err.toJSON()));
|
|
8479
|
+
}
|
|
8480
|
+
}
|
|
8481
|
+
throw err;
|
|
8482
|
+
}
|
|
8483
|
+
}));
|
|
8484
|
+
}
|
|
8485
|
+
};
|
|
8486
|
+
|
|
8419
8487
|
// services/entity-service-lifecycle.ts
|
|
8420
8488
|
var EntityServiceLifeCycle = class {
|
|
8421
8489
|
constructor(EntityConfig, publishEvent2, eventUtils) {
|
|
@@ -8448,6 +8516,462 @@ var EntityServiceLifeCycle = class {
|
|
|
8448
8516
|
}
|
|
8449
8517
|
};
|
|
8450
8518
|
|
|
8519
|
+
// services/transaction.service.ts
|
|
8520
|
+
import { TransactionCanceledException as TransactionCanceledException5 } from "@aws-sdk/client-dynamodb";
|
|
8521
|
+
import { ulid as ulid4 } from "ulid";
|
|
8522
|
+
var MAX_TRANSACTION_ITEMS = 100;
|
|
8523
|
+
var TransactionService = class {
|
|
8524
|
+
constructor(EntityConfig, EmailAuthEnabledEntities, entityRepository, dynamodbClient, publishEvent2, entityServiceLifeCycle, eventUtils) {
|
|
8525
|
+
this.EntityConfig = EntityConfig;
|
|
8526
|
+
this.EmailAuthEnabledEntities = EmailAuthEnabledEntities;
|
|
8527
|
+
this.entityRepository = entityRepository;
|
|
8528
|
+
this.dynamodbClient = dynamodbClient;
|
|
8529
|
+
this.publishEvent = publishEvent2;
|
|
8530
|
+
this.entityServiceLifeCycle = entityServiceLifeCycle;
|
|
8531
|
+
this.eventUtils = eventUtils;
|
|
8532
|
+
this.executeTransaction = (operations, accountId) => __async(this, null, function* () {
|
|
8533
|
+
var _a;
|
|
8534
|
+
if (!operations || operations.length === 0) {
|
|
8535
|
+
throw new StandardError(
|
|
8536
|
+
StandardErrorCode.TRANSACTION_EMPTY,
|
|
8537
|
+
"Transaction must contain at least one operation"
|
|
8538
|
+
);
|
|
8539
|
+
}
|
|
8540
|
+
const allTransactItems = [];
|
|
8541
|
+
const pendingEvents = [];
|
|
8542
|
+
const resultEntries = [];
|
|
8543
|
+
const processed = yield Promise.all(
|
|
8544
|
+
operations.map((op) => this.processOperation(op, accountId))
|
|
8545
|
+
);
|
|
8546
|
+
for (const { items, events, resultEntry } of processed) {
|
|
8547
|
+
allTransactItems.push(...items);
|
|
8548
|
+
pendingEvents.push(...events);
|
|
8549
|
+
resultEntries.push(resultEntry);
|
|
8550
|
+
}
|
|
8551
|
+
if (allTransactItems.length > MAX_TRANSACTION_ITEMS) {
|
|
8552
|
+
throw new StandardError(
|
|
8553
|
+
StandardErrorCode.TRANSACTION_ITEM_LIMIT_EXCEEDED,
|
|
8554
|
+
`Transaction contains ${allTransactItems.length} items, exceeds limit of ${MAX_TRANSACTION_ITEMS}`
|
|
8555
|
+
);
|
|
8556
|
+
}
|
|
8557
|
+
try {
|
|
8558
|
+
yield this.dynamodbClient.transactWriteItems({
|
|
8559
|
+
TransactItems: allTransactItems
|
|
8560
|
+
});
|
|
8561
|
+
} catch (err) {
|
|
8562
|
+
if (err instanceof TransactionCanceledException5) {
|
|
8563
|
+
throw new StandardError(
|
|
8564
|
+
StandardErrorCode.TRANSACTION_FAILED,
|
|
8565
|
+
"Transaction failed",
|
|
8566
|
+
err,
|
|
8567
|
+
{
|
|
8568
|
+
reasons: (_a = err.CancellationReasons) == null ? void 0 : _a.map((r, i) => ({
|
|
8569
|
+
index: i,
|
|
8570
|
+
code: r.Code,
|
|
8571
|
+
message: r.Message
|
|
8572
|
+
}))
|
|
8573
|
+
}
|
|
8574
|
+
);
|
|
8575
|
+
}
|
|
8576
|
+
if ((err == null ? void 0 : err.name) === "ValidationException") {
|
|
8577
|
+
throw new StandardError(
|
|
8578
|
+
StandardErrorCode.TRANSACTION_VALIDATION_ERROR,
|
|
8579
|
+
"Transaction request is invalid (e.g. multiple operations on the same item, or an item exceeds a DynamoDB limit)",
|
|
8580
|
+
err
|
|
8581
|
+
);
|
|
8582
|
+
}
|
|
8583
|
+
throw err;
|
|
8584
|
+
}
|
|
8585
|
+
const readPromises = resultEntries.map((entry) => __async(this, null, function* () {
|
|
8586
|
+
if ((entry.operation === "updateEntity" || entry.operation === "adjustEntity") && !entry.data) {
|
|
8587
|
+
try {
|
|
8588
|
+
const entity = yield this.entityRepository.getEntity(
|
|
8589
|
+
entry.entityType,
|
|
8590
|
+
entry.entityId
|
|
8591
|
+
);
|
|
8592
|
+
entry.data = entity.data;
|
|
8593
|
+
} catch (e) {
|
|
8594
|
+
}
|
|
8595
|
+
}
|
|
8596
|
+
}));
|
|
8597
|
+
yield Promise.all(readPromises);
|
|
8598
|
+
const eventResults = yield Promise.allSettled(
|
|
8599
|
+
pendingEvents.map((ev) => this.publishEvent(ev))
|
|
8600
|
+
);
|
|
8601
|
+
for (const [i, result] of eventResults.entries()) {
|
|
8602
|
+
if (result.status === "rejected") {
|
|
8603
|
+
console.error(
|
|
8604
|
+
"[monorise] Failed to publish event after transaction commit:",
|
|
8605
|
+
{
|
|
8606
|
+
event: pendingEvents[i].event,
|
|
8607
|
+
payload: pendingEvents[i].payload,
|
|
8608
|
+
reason: result.reason
|
|
8609
|
+
}
|
|
8610
|
+
);
|
|
8611
|
+
}
|
|
8612
|
+
}
|
|
8613
|
+
return { results: resultEntries };
|
|
8614
|
+
});
|
|
8615
|
+
}
|
|
8616
|
+
processOperation(op, accountId) {
|
|
8617
|
+
return __async(this, null, function* () {
|
|
8618
|
+
switch (op.operation) {
|
|
8619
|
+
case "createEntity": {
|
|
8620
|
+
const { items, entity } = yield this.buildCreateItems(op);
|
|
8621
|
+
return {
|
|
8622
|
+
items,
|
|
8623
|
+
events: this.collectCreateEvents(entity, op.payload, accountId),
|
|
8624
|
+
resultEntry: {
|
|
8625
|
+
operation: "createEntity",
|
|
8626
|
+
entityType: op.entityType,
|
|
8627
|
+
entityId: entity.entityId,
|
|
8628
|
+
data: entity.data
|
|
8629
|
+
}
|
|
8630
|
+
};
|
|
8631
|
+
}
|
|
8632
|
+
case "updateEntity": {
|
|
8633
|
+
const { item, updatedAt } = yield this.buildUpdateItem(op);
|
|
8634
|
+
return {
|
|
8635
|
+
items: [item],
|
|
8636
|
+
events: this.collectUpdateEvents(op, updatedAt, accountId),
|
|
8637
|
+
resultEntry: {
|
|
8638
|
+
operation: "updateEntity",
|
|
8639
|
+
entityType: op.entityType,
|
|
8640
|
+
entityId: op.entityId
|
|
8641
|
+
}
|
|
8642
|
+
};
|
|
8643
|
+
}
|
|
8644
|
+
case "adjustEntity": {
|
|
8645
|
+
const { item, updatedAt } = yield this.buildAdjustItem(op);
|
|
8646
|
+
return {
|
|
8647
|
+
items: [item],
|
|
8648
|
+
events: [
|
|
8649
|
+
{
|
|
8650
|
+
event: EVENT.CORE.ENTITY_UPDATED,
|
|
8651
|
+
payload: {
|
|
8652
|
+
entityType: op.entityType,
|
|
8653
|
+
entityId: op.entityId,
|
|
8654
|
+
updatedByAccountId: accountId,
|
|
8655
|
+
publishedAt: updatedAt
|
|
8656
|
+
}
|
|
8657
|
+
}
|
|
8658
|
+
],
|
|
8659
|
+
resultEntry: {
|
|
8660
|
+
operation: "adjustEntity",
|
|
8661
|
+
entityType: op.entityType,
|
|
8662
|
+
entityId: op.entityId
|
|
8663
|
+
}
|
|
8664
|
+
};
|
|
8665
|
+
}
|
|
8666
|
+
case "deleteEntity": {
|
|
8667
|
+
const item = this.buildDeleteItem(op);
|
|
8668
|
+
return {
|
|
8669
|
+
items: [item],
|
|
8670
|
+
events: [
|
|
8671
|
+
{
|
|
8672
|
+
event: EVENT.CORE.ENTITY_DELETED,
|
|
8673
|
+
payload: {
|
|
8674
|
+
entityType: op.entityType,
|
|
8675
|
+
entityId: op.entityId,
|
|
8676
|
+
deletedByAccountId: accountId
|
|
8677
|
+
}
|
|
8678
|
+
}
|
|
8679
|
+
],
|
|
8680
|
+
resultEntry: {
|
|
8681
|
+
operation: "deleteEntity",
|
|
8682
|
+
entityType: op.entityType,
|
|
8683
|
+
entityId: op.entityId
|
|
8684
|
+
}
|
|
8685
|
+
};
|
|
8686
|
+
}
|
|
8687
|
+
default:
|
|
8688
|
+
throw new StandardError(
|
|
8689
|
+
StandardErrorCode.TRANSACTION_INVALID_OPERATION,
|
|
8690
|
+
`Unknown operation: '${op.operation}'`
|
|
8691
|
+
);
|
|
8692
|
+
}
|
|
8693
|
+
});
|
|
8694
|
+
}
|
|
8695
|
+
buildCreateItems(op) {
|
|
8696
|
+
return __async(this, null, function* () {
|
|
8697
|
+
const config = this.EntityConfig[op.entityType];
|
|
8698
|
+
if (!config) {
|
|
8699
|
+
throw new StandardError(
|
|
8700
|
+
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
8701
|
+
`Unknown entity type: '${op.entityType}'`
|
|
8702
|
+
);
|
|
8703
|
+
}
|
|
8704
|
+
const entitySchema = config.createSchema || config.baseSchema;
|
|
8705
|
+
if (!entitySchema) {
|
|
8706
|
+
throw new StandardError(
|
|
8707
|
+
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
8708
|
+
`No schema defined for entity type: '${op.entityType}'`
|
|
8709
|
+
);
|
|
8710
|
+
}
|
|
8711
|
+
if (config.finalSchema) {
|
|
8712
|
+
config.finalSchema.parse(op.payload);
|
|
8713
|
+
}
|
|
8714
|
+
const parsedPayload = entitySchema.parse(
|
|
8715
|
+
op.payload
|
|
8716
|
+
);
|
|
8717
|
+
const currentDatetime = /* @__PURE__ */ new Date();
|
|
8718
|
+
const entity = new Entity(
|
|
8719
|
+
op.entityType,
|
|
8720
|
+
op.entityId || ulid4(),
|
|
8721
|
+
parsedPayload,
|
|
8722
|
+
currentDatetime,
|
|
8723
|
+
currentDatetime
|
|
8724
|
+
);
|
|
8725
|
+
const uniqueFields = config.uniqueFields || [];
|
|
8726
|
+
const uniqueFieldValues = {};
|
|
8727
|
+
for (const field of uniqueFields) {
|
|
8728
|
+
if (!(field in parsedPayload)) continue;
|
|
8729
|
+
const value = parsedPayload[field];
|
|
8730
|
+
if (typeof value !== "string") {
|
|
8731
|
+
throw new StandardError(
|
|
8732
|
+
StandardErrorCode.INVALID_UNIQUE_VALUE_TYPE,
|
|
8733
|
+
`Invalid type. ${field} is not a 'string'.`
|
|
8734
|
+
);
|
|
8735
|
+
}
|
|
8736
|
+
uniqueFieldValues[field] = value;
|
|
8737
|
+
}
|
|
8738
|
+
const items = this.entityRepository.createEntityTransactItems(entity, {
|
|
8739
|
+
uniqueFieldValues
|
|
8740
|
+
});
|
|
8741
|
+
return { items, entity };
|
|
8742
|
+
});
|
|
8743
|
+
}
|
|
8744
|
+
buildUpdateItem(op) {
|
|
8745
|
+
return __async(this, null, function* () {
|
|
8746
|
+
const config = this.EntityConfig[op.entityType];
|
|
8747
|
+
if (!config) {
|
|
8748
|
+
throw new StandardError(
|
|
8749
|
+
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
8750
|
+
`Unknown entity type: '${op.entityType}'`
|
|
8751
|
+
);
|
|
8752
|
+
}
|
|
8753
|
+
const uniqueFields = config.uniqueFields || [];
|
|
8754
|
+
for (const field of uniqueFields) {
|
|
8755
|
+
if (field in op.payload) {
|
|
8756
|
+
throw new StandardError(
|
|
8757
|
+
StandardErrorCode.TRANSACTION_UNIQUE_FIELD_UPDATE,
|
|
8758
|
+
`Cannot update unique field '${field}' within a transaction. Use a standalone updateEntity call instead.`
|
|
8759
|
+
);
|
|
8760
|
+
}
|
|
8761
|
+
}
|
|
8762
|
+
const entitySchema = config.baseSchema;
|
|
8763
|
+
if (!entitySchema) {
|
|
8764
|
+
throw new StandardError(
|
|
8765
|
+
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
8766
|
+
`No schema defined for entity type: '${op.entityType}'`
|
|
8767
|
+
);
|
|
8768
|
+
}
|
|
8769
|
+
const parsedPayload = entitySchema.partial().parse(op.payload);
|
|
8770
|
+
const currentDatetime = (/* @__PURE__ */ new Date()).toISOString();
|
|
8771
|
+
const toUpdateExpressions = this.entityRepository.toUpdate({
|
|
8772
|
+
updatedAt: currentDatetime,
|
|
8773
|
+
data: parsedPayload
|
|
8774
|
+
});
|
|
8775
|
+
let conditionOpts;
|
|
8776
|
+
if (op.condition) {
|
|
8777
|
+
const updateConditions = config.updateConditions;
|
|
8778
|
+
if (!updateConditions) {
|
|
8779
|
+
throw new StandardError(
|
|
8780
|
+
StandardErrorCode.INVALID_CONDITION,
|
|
8781
|
+
`Entity '${op.entityType}' has no updateConditions defined`
|
|
8782
|
+
);
|
|
8783
|
+
}
|
|
8784
|
+
conditionOpts = yield resolveUpdateCondition({
|
|
8785
|
+
conditionName: op.condition,
|
|
8786
|
+
conditions: updateConditions,
|
|
8787
|
+
getEntityData: () => __async(this, null, function* () {
|
|
8788
|
+
var _a;
|
|
8789
|
+
const entity2 = yield this.entityRepository.getEntity(
|
|
8790
|
+
op.entityType,
|
|
8791
|
+
op.entityId
|
|
8792
|
+
);
|
|
8793
|
+
return (_a = entity2 == null ? void 0 : entity2.data) != null ? _a : {};
|
|
8794
|
+
})
|
|
8795
|
+
});
|
|
8796
|
+
}
|
|
8797
|
+
const entity = new Entity(op.entityType, op.entityId);
|
|
8798
|
+
const item = {
|
|
8799
|
+
Update: {
|
|
8800
|
+
TableName: this.entityRepository.TABLE_NAME,
|
|
8801
|
+
Key: entity.keys(),
|
|
8802
|
+
ConditionExpression: (conditionOpts == null ? void 0 : conditionOpts.ConditionExpression) || "attribute_exists(PK)",
|
|
8803
|
+
UpdateExpression: toUpdateExpressions.UpdateExpression,
|
|
8804
|
+
ExpressionAttributeNames: __spreadValues(__spreadValues({}, toUpdateExpressions.ExpressionAttributeNames), conditionOpts == null ? void 0 : conditionOpts.ExpressionAttributeNames),
|
|
8805
|
+
ExpressionAttributeValues: __spreadValues(__spreadValues({}, toUpdateExpressions.ExpressionAttributeValues), conditionOpts == null ? void 0 : conditionOpts.ExpressionAttributeValues)
|
|
8806
|
+
}
|
|
8807
|
+
};
|
|
8808
|
+
return { item, updatedAt: currentDatetime };
|
|
8809
|
+
});
|
|
8810
|
+
}
|
|
8811
|
+
buildAdjustItem(op) {
|
|
8812
|
+
return __async(this, null, function* () {
|
|
8813
|
+
const config = this.EntityConfig[op.entityType];
|
|
8814
|
+
if (!config) {
|
|
8815
|
+
throw new StandardError(
|
|
8816
|
+
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
8817
|
+
`Unknown entity type: '${op.entityType}'`
|
|
8818
|
+
);
|
|
8819
|
+
}
|
|
8820
|
+
for (const [key, value] of Object.entries(op.adjustments)) {
|
|
8821
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
8822
|
+
throw new StandardError(
|
|
8823
|
+
StandardErrorCode.TRANSACTION_INVALID_OPERATION,
|
|
8824
|
+
`Adjustment field "${key}" must be a finite number`
|
|
8825
|
+
);
|
|
8826
|
+
}
|
|
8827
|
+
}
|
|
8828
|
+
const {
|
|
8829
|
+
UpdateExpression,
|
|
8830
|
+
ExpressionAttributeNames,
|
|
8831
|
+
ExpressionAttributeValues
|
|
8832
|
+
} = this.entityRepository.toAdjustUpdate(op.adjustments);
|
|
8833
|
+
const currentDatetime = (/* @__PURE__ */ new Date()).toISOString();
|
|
8834
|
+
ExpressionAttributeNames["#updatedAt"] = "updatedAt";
|
|
8835
|
+
ExpressionAttributeValues[":updatedAt"] = { S: currentDatetime };
|
|
8836
|
+
const fullUpdateExpression = `${UpdateExpression}, #updatedAt = :updatedAt`;
|
|
8837
|
+
let conditionOpts;
|
|
8838
|
+
const adjustmentConditions = config.adjustmentConditions;
|
|
8839
|
+
if (adjustmentConditions) {
|
|
8840
|
+
if (!op.condition) {
|
|
8841
|
+
throw new StandardError(
|
|
8842
|
+
StandardErrorCode.INVALID_CONDITION,
|
|
8843
|
+
`Entity '${op.entityType}' has adjustmentConditions defined; condition is required`
|
|
8844
|
+
);
|
|
8845
|
+
}
|
|
8846
|
+
conditionOpts = yield resolveAdjustmentCondition({
|
|
8847
|
+
conditionName: op.condition,
|
|
8848
|
+
conditions: adjustmentConditions,
|
|
8849
|
+
adjustments: op.adjustments,
|
|
8850
|
+
getEntityData: () => __async(this, null, function* () {
|
|
8851
|
+
var _a;
|
|
8852
|
+
const entity2 = yield this.entityRepository.getEntity(
|
|
8853
|
+
op.entityType,
|
|
8854
|
+
op.entityId
|
|
8855
|
+
);
|
|
8856
|
+
return (_a = entity2 == null ? void 0 : entity2.data) != null ? _a : {};
|
|
8857
|
+
})
|
|
8858
|
+
});
|
|
8859
|
+
}
|
|
8860
|
+
const entity = new Entity(op.entityType, op.entityId);
|
|
8861
|
+
const item = {
|
|
8862
|
+
Update: {
|
|
8863
|
+
TableName: this.entityRepository.TABLE_NAME,
|
|
8864
|
+
Key: entity.keys(),
|
|
8865
|
+
UpdateExpression: fullUpdateExpression,
|
|
8866
|
+
ConditionExpression: (conditionOpts == null ? void 0 : conditionOpts.ConditionExpression) || "attribute_exists(PK)",
|
|
8867
|
+
ExpressionAttributeNames: __spreadValues(__spreadValues({}, ExpressionAttributeNames), conditionOpts == null ? void 0 : conditionOpts.ExpressionAttributeNames),
|
|
8868
|
+
ExpressionAttributeValues: __spreadValues(__spreadValues({}, ExpressionAttributeValues), conditionOpts == null ? void 0 : conditionOpts.ExpressionAttributeValues)
|
|
8869
|
+
}
|
|
8870
|
+
};
|
|
8871
|
+
return { item, updatedAt: currentDatetime };
|
|
8872
|
+
});
|
|
8873
|
+
}
|
|
8874
|
+
buildDeleteItem(op) {
|
|
8875
|
+
const config = this.EntityConfig[op.entityType];
|
|
8876
|
+
if (!config) {
|
|
8877
|
+
throw new StandardError(
|
|
8878
|
+
StandardErrorCode.INVALID_ENTITY_TYPE,
|
|
8879
|
+
`Unknown entity type: '${op.entityType}'`
|
|
8880
|
+
);
|
|
8881
|
+
}
|
|
8882
|
+
const entity = new Entity(op.entityType, op.entityId);
|
|
8883
|
+
return {
|
|
8884
|
+
Delete: {
|
|
8885
|
+
TableName: this.entityRepository.TABLE_NAME,
|
|
8886
|
+
Key: entity.keys(),
|
|
8887
|
+
ConditionExpression: "attribute_exists(PK)"
|
|
8888
|
+
}
|
|
8889
|
+
};
|
|
8890
|
+
}
|
|
8891
|
+
collectCreateEvents(entity, payload, accountId) {
|
|
8892
|
+
var _a, _b;
|
|
8893
|
+
const events = [];
|
|
8894
|
+
const publishedAt = entity.updatedAt || (/* @__PURE__ */ new Date()).toISOString();
|
|
8895
|
+
const config = this.EntityConfig[entity.entityType];
|
|
8896
|
+
const mutualSchema = (_a = config == null ? void 0 : config.mutual) == null ? void 0 : _a.mutualSchema;
|
|
8897
|
+
if (mutualSchema) {
|
|
8898
|
+
const parsedMutualPayload = mutualSchema.parse(payload);
|
|
8899
|
+
if (parsedMutualPayload) {
|
|
8900
|
+
for (const [fieldKey, fieldConfig] of Object.entries(
|
|
8901
|
+
((_b = config.mutual) == null ? void 0 : _b.mutualFields) || {}
|
|
8902
|
+
)) {
|
|
8903
|
+
const toMutualIds = fieldConfig.toMutualIds;
|
|
8904
|
+
const mutualPayload = parsedMutualPayload[fieldKey];
|
|
8905
|
+
if (!mutualPayload) continue;
|
|
8906
|
+
events.push({
|
|
8907
|
+
event: EVENT.CORE.ENTITY_MUTUAL_TO_CREATE,
|
|
8908
|
+
payload: {
|
|
8909
|
+
byEntityType: entity.entityType,
|
|
8910
|
+
byEntityId: entity.entityId,
|
|
8911
|
+
entityType: fieldConfig.entityType,
|
|
8912
|
+
field: fieldKey,
|
|
8913
|
+
mutualIds: toMutualIds ? toMutualIds(mutualPayload) : mutualPayload,
|
|
8914
|
+
customContext: toMutualIds ? mutualPayload : {},
|
|
8915
|
+
publishedAt
|
|
8916
|
+
}
|
|
8917
|
+
});
|
|
8918
|
+
}
|
|
8919
|
+
}
|
|
8920
|
+
}
|
|
8921
|
+
events.push({
|
|
8922
|
+
event: EVENT.CORE.ENTITY_CREATED,
|
|
8923
|
+
payload: {
|
|
8924
|
+
entityType: entity.entityType,
|
|
8925
|
+
entityId: entity.entityId,
|
|
8926
|
+
data: entity.data,
|
|
8927
|
+
createdByAccountId: accountId,
|
|
8928
|
+
publishedAt
|
|
8929
|
+
}
|
|
8930
|
+
});
|
|
8931
|
+
return events;
|
|
8932
|
+
}
|
|
8933
|
+
collectUpdateEvents(op, updatedAt, accountId) {
|
|
8934
|
+
var _a, _b;
|
|
8935
|
+
const events = [];
|
|
8936
|
+
const config = this.EntityConfig[op.entityType];
|
|
8937
|
+
const mutualSchema = (_a = config == null ? void 0 : config.mutual) == null ? void 0 : _a.mutualSchema;
|
|
8938
|
+
if (mutualSchema) {
|
|
8939
|
+
const parsedMutualPayload = mutualSchema.parse(op.payload);
|
|
8940
|
+
if (parsedMutualPayload) {
|
|
8941
|
+
for (const [fieldKey, fieldConfig] of Object.entries(
|
|
8942
|
+
((_b = config.mutual) == null ? void 0 : _b.mutualFields) || {}
|
|
8943
|
+
)) {
|
|
8944
|
+
const toMutualIds = fieldConfig.toMutualIds;
|
|
8945
|
+
const mutualPayload = parsedMutualPayload[fieldKey];
|
|
8946
|
+
if (!mutualPayload) continue;
|
|
8947
|
+
events.push({
|
|
8948
|
+
event: EVENT.CORE.ENTITY_MUTUAL_TO_UPDATE,
|
|
8949
|
+
payload: {
|
|
8950
|
+
byEntityType: op.entityType,
|
|
8951
|
+
byEntityId: op.entityId,
|
|
8952
|
+
entityType: fieldConfig.entityType,
|
|
8953
|
+
field: fieldKey,
|
|
8954
|
+
mutualIds: toMutualIds ? toMutualIds(mutualPayload) : mutualPayload,
|
|
8955
|
+
customContext: toMutualIds ? mutualPayload : {},
|
|
8956
|
+
publishedAt: updatedAt
|
|
8957
|
+
}
|
|
8958
|
+
});
|
|
8959
|
+
}
|
|
8960
|
+
}
|
|
8961
|
+
}
|
|
8962
|
+
events.push({
|
|
8963
|
+
event: EVENT.CORE.ENTITY_UPDATED,
|
|
8964
|
+
payload: {
|
|
8965
|
+
entityType: op.entityType,
|
|
8966
|
+
entityId: op.entityId,
|
|
8967
|
+
updatedByAccountId: accountId,
|
|
8968
|
+
publishedAt: updatedAt
|
|
8969
|
+
}
|
|
8970
|
+
});
|
|
8971
|
+
return events;
|
|
8972
|
+
}
|
|
8973
|
+
};
|
|
8974
|
+
|
|
8451
8975
|
// services/DependencyContainer.ts
|
|
8452
8976
|
var DependencyContainer = class {
|
|
8453
8977
|
constructor(config) {
|
|
@@ -8624,6 +9148,59 @@ var DependencyContainer = class {
|
|
|
8624
9148
|
get listTagsController() {
|
|
8625
9149
|
return this.createCachedInstance(ListTagsController, this.tagRepository);
|
|
8626
9150
|
}
|
|
9151
|
+
get transactionService() {
|
|
9152
|
+
return this.createCachedInstance(
|
|
9153
|
+
TransactionService,
|
|
9154
|
+
this.config.EntityConfig,
|
|
9155
|
+
this.config.EmailAuthEnabledEntities,
|
|
9156
|
+
this.entityRepository,
|
|
9157
|
+
this.dynamodbClient,
|
|
9158
|
+
this.publishEvent,
|
|
9159
|
+
this.entityServiceLifeCycle,
|
|
9160
|
+
this.eventUtils
|
|
9161
|
+
);
|
|
9162
|
+
}
|
|
9163
|
+
get executeTransactionController() {
|
|
9164
|
+
return this.createCachedInstance(
|
|
9165
|
+
ExecuteTransactionController,
|
|
9166
|
+
this.transactionService
|
|
9167
|
+
);
|
|
9168
|
+
}
|
|
9169
|
+
};
|
|
9170
|
+
|
|
9171
|
+
// helpers/transactional.ts
|
|
9172
|
+
var transactional = {
|
|
9173
|
+
createEntity: (entityType, payload) => {
|
|
9174
|
+
const _a = payload, { entityId } = _a, rest = __objRest(_a, ["entityId"]);
|
|
9175
|
+
return __spreadValues({
|
|
9176
|
+
operation: "createEntity",
|
|
9177
|
+
entityType,
|
|
9178
|
+
payload: rest
|
|
9179
|
+
}, entityId && { entityId });
|
|
9180
|
+
},
|
|
9181
|
+
updateEntity: (entityType, entityId, payload) => {
|
|
9182
|
+
const _a = payload, { $condition } = _a, rest = __objRest(_a, ["$condition"]);
|
|
9183
|
+
return __spreadValues({
|
|
9184
|
+
operation: "updateEntity",
|
|
9185
|
+
entityType,
|
|
9186
|
+
entityId,
|
|
9187
|
+
payload: rest
|
|
9188
|
+
}, $condition && { condition: $condition });
|
|
9189
|
+
},
|
|
9190
|
+
adjustEntity: (entityType, entityId, adjustments) => {
|
|
9191
|
+
const _a = adjustments, { $condition } = _a, rest = __objRest(_a, ["$condition"]);
|
|
9192
|
+
return __spreadValues({
|
|
9193
|
+
operation: "adjustEntity",
|
|
9194
|
+
entityType,
|
|
9195
|
+
entityId,
|
|
9196
|
+
adjustments: rest
|
|
9197
|
+
}, $condition && { condition: $condition });
|
|
9198
|
+
},
|
|
9199
|
+
deleteEntity: (entityType, entityId) => ({
|
|
9200
|
+
operation: "deleteEntity",
|
|
9201
|
+
entityType,
|
|
9202
|
+
entityId
|
|
9203
|
+
})
|
|
8627
9204
|
};
|
|
8628
9205
|
|
|
8629
9206
|
// index.ts
|
|
@@ -8654,6 +9231,7 @@ export {
|
|
|
8654
9231
|
StandardError,
|
|
8655
9232
|
StandardErrorCode,
|
|
8656
9233
|
TagRepository,
|
|
9234
|
+
TransactionService,
|
|
8657
9235
|
appHandler,
|
|
8658
9236
|
handler as createEntityProcessor,
|
|
8659
9237
|
index_default as default,
|
|
@@ -8661,6 +9239,7 @@ export {
|
|
|
8661
9239
|
handler3 as prejoinProcessor,
|
|
8662
9240
|
handler4 as replicationProcessor,
|
|
8663
9241
|
setupCommonRoutes,
|
|
8664
|
-
handler5 as tagProcessor
|
|
9242
|
+
handler5 as tagProcessor,
|
|
9243
|
+
transactional
|
|
8665
9244
|
};
|
|
8666
9245
|
//# sourceMappingURL=index.js.map
|