monorise 1.4.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.
Files changed (71) hide show
  1. package/dist/base/index.d.ts +95 -1
  2. package/dist/base/index.js.map +1 -1
  3. package/dist/cli/cli.js +2 -2
  4. package/dist/core/index.d.ts +96 -30
  5. package/dist/core/index.js +785 -27
  6. package/dist/core/index.js.map +1 -1
  7. package/dist/react/chunk-5XIRNUBL.js +43 -0
  8. package/dist/react/chunk-5XIRNUBL.js.map +1 -0
  9. package/dist/react/chunk-7JDOKZGQ.js +172 -0
  10. package/dist/react/chunk-7JDOKZGQ.js.map +1 -0
  11. package/dist/react/chunk-A5TI2FW3.js +13 -0
  12. package/dist/react/chunk-A5TI2FW3.js.map +1 -0
  13. package/dist/react/chunk-AYQDOLYF.js +628 -0
  14. package/dist/react/chunk-AYQDOLYF.js.map +1 -0
  15. package/dist/react/chunk-BUTF5RJU.js +29 -0
  16. package/dist/react/chunk-BUTF5RJU.js.map +1 -0
  17. package/dist/react/chunk-EYG2DL3D.js +893 -0
  18. package/dist/react/chunk-EYG2DL3D.js.map +1 -0
  19. package/dist/react/chunk-GEN4TSCQ.js +5179 -0
  20. package/dist/react/chunk-GEN4TSCQ.js.map +1 -0
  21. package/dist/react/chunk-GFVCNWVT.js +54 -0
  22. package/dist/react/chunk-GFVCNWVT.js.map +1 -0
  23. package/dist/react/chunk-KJX5LOMN.js +43 -0
  24. package/dist/react/chunk-KJX5LOMN.js.map +1 -0
  25. package/dist/react/chunk-KLXK4V6G.js +65 -0
  26. package/dist/react/chunk-KLXK4V6G.js.map +1 -0
  27. package/dist/react/chunk-L6MAS3AX.js +482 -0
  28. package/dist/react/chunk-L6MAS3AX.js.map +1 -0
  29. package/dist/react/chunk-LPXR5V4J.js +582 -0
  30. package/dist/react/chunk-LPXR5V4J.js.map +1 -0
  31. package/dist/react/chunk-MIXAYX55.js +147 -0
  32. package/dist/react/chunk-MIXAYX55.js.map +1 -0
  33. package/dist/react/chunk-OEHQ546W.js +182 -0
  34. package/dist/react/chunk-OEHQ546W.js.map +1 -0
  35. package/dist/react/chunk-RPNCWADG.js +248 -0
  36. package/dist/react/chunk-RPNCWADG.js.map +1 -0
  37. package/dist/react/chunk-S6RDMHHH.js +47 -0
  38. package/dist/react/chunk-S6RDMHHH.js.map +1 -0
  39. package/dist/react/chunk-VVCM7N22.js +101 -0
  40. package/dist/react/chunk-VVCM7N22.js.map +1 -0
  41. package/dist/react/dist-es-5WYA7CWK.js +379 -0
  42. package/dist/react/dist-es-5WYA7CWK.js.map +1 -0
  43. package/dist/react/dist-es-DLWQXBOR.js +333 -0
  44. package/dist/react/dist-es-DLWQXBOR.js.map +1 -0
  45. package/dist/react/dist-es-EMJCB37T.js +71 -0
  46. package/dist/react/dist-es-EMJCB37T.js.map +1 -0
  47. package/dist/react/dist-es-Q7IAXWRB.js +494 -0
  48. package/dist/react/dist-es-Q7IAXWRB.js.map +1 -0
  49. package/dist/react/dist-es-QF65HH5Y.js +169 -0
  50. package/dist/react/dist-es-QF65HH5Y.js.map +1 -0
  51. package/dist/react/dist-es-R4TRTT45.js +22 -0
  52. package/dist/react/dist-es-R4TRTT45.js.map +1 -0
  53. package/dist/react/dist-es-XNAC47MK.js +90 -0
  54. package/dist/react/dist-es-XNAC47MK.js.map +1 -0
  55. package/dist/react/event-streams-6APKUBMC.js +270 -0
  56. package/dist/react/event-streams-6APKUBMC.js.map +1 -0
  57. package/dist/react/index.d.ts +23 -2
  58. package/dist/react/index.d.ts.map +1 -1
  59. package/dist/react/index.js +8724 -160
  60. package/dist/react/index.js.map +1 -1
  61. package/dist/react/loadSso-WMS367NT.js +595 -0
  62. package/dist/react/loadSso-WMS367NT.js.map +1 -0
  63. package/dist/react/services/core.service.d.ts +11 -1
  64. package/dist/react/services/core.service.d.ts.map +1 -1
  65. package/dist/react/signin-2I7AG6XI.js +707 -0
  66. package/dist/react/signin-2I7AG6XI.js.map +1 -0
  67. package/dist/react/sso-oidc-OAJ7SALL.js +825 -0
  68. package/dist/react/sso-oidc-OAJ7SALL.js.map +1 -0
  69. package/dist/react/sts-LKM23TRV.js +3866 -0
  70. package/dist/react/sts-LKM23TRV.js.map +1 -0
  71. package/package.json +1 -1
@@ -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
 
@@ -175,6 +176,7 @@ var StandardErrorCode = {
175
176
  ENTITY_ID_IS_UNDEFINED: "ENTITY_ID_IS_UNDEFINED",
176
177
  ENTITY_IS_UNDEFINED: "ENTITY_IS_UNDEFINED",
177
178
  ENTITY_NOT_FOUND: "ENTITY_NOT_FOUND",
179
+ INVALID_CONDITION: "INVALID_CONDITION",
178
180
  INVALID_ENTITY_TYPE: "INVALID_ENTITY_TYPE",
179
181
  INVALID_MUTUAL: "INVALID_MUTUAL",
180
182
  INVALID_QUERY: "INVALID_QUERY",
@@ -187,7 +189,12 @@ var StandardErrorCode = {
187
189
  REPLICATION_ERROR: "REPLICATION_ERROR",
188
190
  RETRYABLE_MUTUAL_LOCK_CONFLICT: "RETRYABLE_MUTUAL_LOCK_CONFLICT",
189
191
  TAG_IS_UNDEFINED: "TAG_IS_UNDEFINED",
192
+ TRANSACTION_EMPTY: "TRANSACTION_EMPTY",
190
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",
191
198
  UNIQUE_VALUE_EXISTS: "UNIQUE_VALUE_EXISTS"
192
199
  };
193
200
 
@@ -947,22 +954,22 @@ var EntityRepository = class extends Repository {
947
954
  }
948
955
  });
949
956
  }
950
- adjustEntity(entityType, entityId, adjustments, constraints) {
957
+ adjustEntity(entityType, entityId, adjustments, opts) {
951
958
  return __async(this, null, function* () {
952
959
  const entity = new Entity(entityType, entityId);
953
- const { UpdateExpression, ConditionExpression, ExpressionAttributeNames, ExpressionAttributeValues } = this.toAdjustUpdate(adjustments, constraints);
960
+ const { UpdateExpression, ExpressionAttributeNames, ExpressionAttributeValues } = this.toAdjustUpdate(adjustments);
954
961
  const updatedAtExpression = ", #updatedAt = :updatedAt";
955
962
  ExpressionAttributeNames["#updatedAt"] = "updatedAt";
956
963
  ExpressionAttributeValues[":updatedAt"] = { S: (/* @__PURE__ */ new Date()).toISOString() };
957
- const resp = yield this.dynamodbClient.updateItem(__spreadProps(__spreadValues({
964
+ const resp = yield this.dynamodbClient.updateItem({
958
965
  TableName: this.TABLE_NAME,
959
966
  Key: entity.keys(),
960
- UpdateExpression: UpdateExpression + updatedAtExpression
961
- }, ConditionExpression && { ConditionExpression }), {
962
- ExpressionAttributeNames,
963
- ExpressionAttributeValues,
967
+ UpdateExpression: UpdateExpression + updatedAtExpression,
968
+ ConditionExpression: (opts == null ? void 0 : opts.ConditionExpression) || "attribute_exists(PK)",
969
+ ExpressionAttributeNames: __spreadValues(__spreadValues({}, ExpressionAttributeNames), opts == null ? void 0 : opts.ExpressionAttributeNames),
970
+ ExpressionAttributeValues: __spreadValues(__spreadValues({}, ExpressionAttributeValues), opts == null ? void 0 : opts.ExpressionAttributeValues),
964
971
  ReturnValues: "ALL_NEW"
965
- }));
972
+ });
966
973
  return Entity.fromItem(resp.Attributes);
967
974
  });
968
975
  }
@@ -7301,7 +7308,16 @@ var UpdateEntityController = class {
7301
7308
  const accountId = c.req.header("account-id");
7302
7309
  const { entityType, entityId } = c.req.param();
7303
7310
  const body = yield c.req.json();
7304
- const _a = body, { $where: where } = _a, entityPayload = __objRest(_a, ["$where"]);
7311
+ const _a = body, { $condition: condition, $where: where } = _a, entityPayload = __objRest(_a, ["$condition", "$where"]);
7312
+ if (condition !== void 0) {
7313
+ if (typeof condition !== "string" || condition.trim().length === 0) {
7314
+ c.status(httpStatus8.BAD_REQUEST);
7315
+ return c.json({
7316
+ code: "API_VALIDATION_ERROR",
7317
+ message: "$condition must be a non-empty string"
7318
+ });
7319
+ }
7320
+ }
7305
7321
  const errorContext = {
7306
7322
  accountId,
7307
7323
  "req.params": c.req.param(),
@@ -7313,6 +7329,7 @@ var UpdateEntityController = class {
7313
7329
  entityId,
7314
7330
  entityPayload,
7315
7331
  accountId,
7332
+ condition,
7316
7333
  where
7317
7334
  });
7318
7335
  errorContext.entity = entity;
@@ -7331,6 +7348,10 @@ var UpdateEntityController = class {
7331
7348
  c.status(httpStatus8.NOT_FOUND);
7332
7349
  return c.json(__spreadValues({}, err.toJSON()));
7333
7350
  }
7351
+ if (err instanceof StandardError && err.code === StandardErrorCode.INVALID_CONDITION) {
7352
+ c.status(httpStatus8.BAD_REQUEST);
7353
+ return c.json(__spreadValues({}, err.toJSON()));
7354
+ }
7334
7355
  if (err instanceof StandardError && err.code === StandardErrorCode.UNIQUE_VALUE_EXISTS) {
7335
7356
  c.status(httpStatus8.BAD_REQUEST);
7336
7357
  return c.json(__spreadValues({}, err.toJSON()));
@@ -7357,11 +7378,21 @@ var AdjustEntityController = class {
7357
7378
  constructor(entityService) {
7358
7379
  this.entityService = entityService;
7359
7380
  this.controller = createMiddleware9((c) => __async(this, null, function* () {
7360
- var _a;
7381
+ var _b;
7361
7382
  const accountId = c.req.header("account-id") || "";
7362
7383
  const { entityType, entityId } = c.req.param();
7363
7384
  const body = yield c.req.json();
7364
- for (const [key, value] of Object.entries(body)) {
7385
+ const _a = body, { $condition: condition } = _a, adjustments = __objRest(_a, ["$condition"]);
7386
+ if (condition !== void 0) {
7387
+ if (typeof condition !== "string" || condition.trim().length === 0) {
7388
+ c.status(httpStatus9.BAD_REQUEST);
7389
+ return c.json({
7390
+ code: "API_VALIDATION_ERROR",
7391
+ message: "$condition must be a non-empty string"
7392
+ });
7393
+ }
7394
+ }
7395
+ for (const [key, value] of Object.entries(adjustments)) {
7365
7396
  if (typeof value !== "number") {
7366
7397
  c.status(httpStatus9.BAD_REQUEST);
7367
7398
  return c.json({
@@ -7374,8 +7405,9 @@ var AdjustEntityController = class {
7374
7405
  const entity = yield this.entityService.adjustEntity({
7375
7406
  entityType,
7376
7407
  entityId,
7377
- adjustments: body,
7378
- accountId
7408
+ adjustments,
7409
+ accountId,
7410
+ condition
7379
7411
  });
7380
7412
  c.status(httpStatus9.OK);
7381
7413
  return c.json(entity.toJSON());
@@ -7384,7 +7416,11 @@ var AdjustEntityController = class {
7384
7416
  c.status(httpStatus9.NOT_FOUND);
7385
7417
  return c.json(__spreadValues({}, err.toJSON()));
7386
7418
  }
7387
- if ((err == null ? void 0 : err.name) === "ConditionalCheckFailedException" || ((_a = err == null ? void 0 : err.__type) == null ? void 0 : _a.includes("ConditionalCheckFailed"))) {
7419
+ if (err instanceof StandardError && err.code === StandardErrorCode.INVALID_CONDITION) {
7420
+ c.status(httpStatus9.BAD_REQUEST);
7421
+ return c.json(__spreadValues({}, err.toJSON()));
7422
+ }
7423
+ if ((err == null ? void 0 : err.name) === "ConditionalCheckFailedException" || ((_b = err == null ? void 0 : err.__type) == null ? void 0 : _b.includes("ConditionalCheckFailed"))) {
7388
7424
  c.status(httpStatus9.CONFLICT);
7389
7425
  return c.json({
7390
7426
  code: "ADJUSTMENT_CONSTRAINT_VIOLATED",
@@ -7689,6 +7725,9 @@ var UpdateMutualController = class {
7689
7725
  }
7690
7726
  };
7691
7727
 
7728
+ // services/entity.service.ts
7729
+ import { marshall as marshall6 } from "@aws-sdk/util-dynamodb";
7730
+
7692
7731
  // data/utils/build-condition-expression.ts
7693
7732
  import { marshall as marshall5 } from "@aws-sdk/util-dynamodb";
7694
7733
  function buildConditionExpression(where) {
@@ -7750,7 +7789,62 @@ function buildConditionExpression(where) {
7750
7789
  };
7751
7790
  }
7752
7791
 
7792
+ // services/resolve-condition.ts
7793
+ function resolveAdjustmentCondition(_0) {
7794
+ return __async(this, arguments, function* ({
7795
+ conditionName,
7796
+ conditions,
7797
+ adjustments,
7798
+ getEntityData
7799
+ }) {
7800
+ if (!Object.hasOwn(conditions, conditionName)) {
7801
+ throw new StandardError(
7802
+ StandardErrorCode.INVALID_CONDITION,
7803
+ `Unknown adjustment condition: '${conditionName}'`
7804
+ );
7805
+ }
7806
+ const condition = conditions[conditionName];
7807
+ let resolved;
7808
+ if (typeof condition === "function") {
7809
+ const data = yield getEntityData();
7810
+ resolved = condition(data, adjustments);
7811
+ } else {
7812
+ resolved = condition;
7813
+ }
7814
+ return buildConditionExpression(resolved);
7815
+ });
7816
+ }
7817
+ function resolveUpdateCondition(_0) {
7818
+ return __async(this, arguments, function* ({
7819
+ conditionName,
7820
+ conditions,
7821
+ getEntityData
7822
+ }) {
7823
+ if (!Object.hasOwn(conditions, conditionName)) {
7824
+ throw new StandardError(
7825
+ StandardErrorCode.INVALID_CONDITION,
7826
+ `Unknown update condition: '${conditionName}'`
7827
+ );
7828
+ }
7829
+ const condition = conditions[conditionName];
7830
+ let resolved;
7831
+ if (typeof condition === "function") {
7832
+ const data = yield getEntityData();
7833
+ resolved = condition(data);
7834
+ } else {
7835
+ resolved = condition;
7836
+ }
7837
+ return buildConditionExpression(resolved);
7838
+ });
7839
+ }
7840
+
7753
7841
  // services/entity.service.ts
7842
+ var warnedOnce = /* @__PURE__ */ new Set();
7843
+ var deprecationWarnOnce = (key, message) => {
7844
+ if (warnedOnce.has(key)) return;
7845
+ warnedOnce.add(key);
7846
+ console.warn(message);
7847
+ };
7754
7848
  var EntityService = class {
7755
7849
  constructor(EntityConfig, EmailAuthEnabledEntities, entityRepository, publishEvent2, entityServiceLifeCycle) {
7756
7850
  this.EntityConfig = EntityConfig;
@@ -7805,34 +7899,65 @@ var EntityService = class {
7805
7899
  entityType,
7806
7900
  entityId,
7807
7901
  adjustments,
7808
- accountId
7902
+ accountId,
7903
+ condition
7809
7904
  }) {
7810
- var _a, _b, _c, _d;
7811
- const rawConstraints = (_a = this.EntityConfig[entityType]) == null ? void 0 : _a.adjustmentConstraints;
7812
- let resolvedConstraints = rawConstraints;
7813
- if (rawConstraints) {
7905
+ var _a, _b, _c;
7906
+ const entityConfig = this.EntityConfig[entityType];
7907
+ const adjustmentConditions = entityConfig == null ? void 0 : entityConfig.adjustmentConditions;
7908
+ const rawConstraints = entityConfig == null ? void 0 : entityConfig.adjustmentConstraints;
7909
+ let opts;
7910
+ if (adjustmentConditions) {
7911
+ if (!condition) {
7912
+ throw new StandardError(
7913
+ StandardErrorCode.INVALID_CONDITION,
7914
+ "Entity has adjustmentConditions defined; $condition is required for adjustEntity"
7915
+ );
7916
+ }
7917
+ opts = yield resolveAdjustmentCondition({
7918
+ conditionName: condition,
7919
+ conditions: adjustmentConditions,
7920
+ adjustments,
7921
+ getEntityData: () => __async(this, null, function* () {
7922
+ var _a2;
7923
+ const entity2 = yield this.entityRepository.getEntity(entityType, entityId);
7924
+ return (_a2 = entity2 == null ? void 0 : entity2.data) != null ? _a2 : {};
7925
+ })
7926
+ });
7927
+ } else if (condition) {
7928
+ throw new StandardError(
7929
+ StandardErrorCode.INVALID_CONDITION,
7930
+ `Entity '${entityType}' has no adjustmentConditions defined`
7931
+ );
7932
+ } else if (rawConstraints) {
7933
+ deprecationWarnOnce(
7934
+ "adjustmentConstraints",
7935
+ "[monorise] adjustmentConstraints is deprecated. Use adjustmentConditions instead."
7936
+ );
7937
+ let resolvedConstraints = rawConstraints;
7814
7938
  const hasDynamicFields = Object.values(rawConstraints).some(
7815
7939
  (c) => c.minField || c.maxField
7816
7940
  );
7817
7941
  if (hasDynamicFields) {
7818
7942
  const currentEntity = yield this.entityRepository.getEntity(entityType, entityId);
7819
- const data = (_b = currentEntity == null ? void 0 : currentEntity.data) != null ? _b : {};
7943
+ const data = (_a = currentEntity == null ? void 0 : currentEntity.data) != null ? _a : {};
7820
7944
  resolvedConstraints = {};
7821
7945
  for (const [field, constraint] of Object.entries(rawConstraints)) {
7822
7946
  const resolved = {};
7823
7947
  if (constraint.min !== void 0) resolved.min = constraint.min;
7824
7948
  if (constraint.max !== void 0) resolved.max = constraint.max;
7825
- if (constraint.minField) resolved.min = (_c = data[constraint.minField]) != null ? _c : 0;
7826
- if (constraint.maxField) resolved.max = (_d = data[constraint.maxField]) != null ? _d : Number.MAX_SAFE_INTEGER;
7949
+ if (constraint.minField) resolved.min = (_b = data[constraint.minField]) != null ? _b : 0;
7950
+ if (constraint.maxField) resolved.max = (_c = data[constraint.maxField]) != null ? _c : Number.MAX_SAFE_INTEGER;
7827
7951
  resolvedConstraints[field] = resolved;
7828
7952
  }
7829
7953
  }
7954
+ opts = this.buildLegacyAdjustCondition(adjustments, resolvedConstraints);
7830
7955
  }
7831
7956
  const entity = yield this.entityRepository.adjustEntity(
7832
7957
  entityType,
7833
7958
  entityId,
7834
7959
  adjustments,
7835
- resolvedConstraints
7960
+ opts
7836
7961
  );
7837
7962
  yield this.publishEvent({
7838
7963
  event: EVENT.CORE.ENTITY_UPDATED,
@@ -7851,9 +7976,10 @@ var EntityService = class {
7851
7976
  entityId,
7852
7977
  entityPayload,
7853
7978
  accountId,
7979
+ condition,
7854
7980
  where
7855
7981
  }) {
7856
- var _a, _b;
7982
+ var _a, _b, _c, _d;
7857
7983
  const errorContext = {};
7858
7984
  try {
7859
7985
  const entitySchema = this.EntityConfig[entityType].baseSchema;
@@ -7867,7 +7993,37 @@ var EntityService = class {
7867
7993
  const parsedEntityPayload = entitySchema.parse(entityPayload);
7868
7994
  const parsedMutualPayload = mutualSchema == null ? void 0 : mutualSchema.parse(entityPayload);
7869
7995
  errorContext.parsedMutualPayload = parsedMutualPayload;
7870
- const opts = where && Object.keys(where).length > 0 ? buildConditionExpression(where) : void 0;
7996
+ let opts;
7997
+ if (condition) {
7998
+ const updateConditions = (_b = this.EntityConfig[entityType]) == null ? void 0 : _b.updateConditions;
7999
+ if (!updateConditions) {
8000
+ throw new StandardError(
8001
+ StandardErrorCode.INVALID_CONDITION,
8002
+ `Entity '${entityType}' has no updateConditions defined`
8003
+ );
8004
+ }
8005
+ opts = yield resolveUpdateCondition({
8006
+ conditionName: condition,
8007
+ conditions: updateConditions,
8008
+ getEntityData: () => __async(this, null, function* () {
8009
+ var _a2;
8010
+ const entity2 = yield this.entityRepository.getEntity(entityType, entityId);
8011
+ return (_a2 = entity2 == null ? void 0 : entity2.data) != null ? _a2 : {};
8012
+ })
8013
+ });
8014
+ } else if (where && Object.keys(where).length > 0) {
8015
+ if (!((_c = this.EntityConfig[entityType]) == null ? void 0 : _c.allowLegacyWhere)) {
8016
+ throw new StandardError(
8017
+ StandardErrorCode.INVALID_CONDITION,
8018
+ `Entity '${entityType}' has legacy $where disabled by default. Use named conditions via $condition, or set allowLegacyWhere: true to opt in (not recommended \u2014 re-exposes condition operators to clients).`
8019
+ );
8020
+ }
8021
+ deprecationWarnOnce(
8022
+ "where",
8023
+ "[monorise] $where is deprecated. Use named conditions via $condition instead."
8024
+ );
8025
+ opts = buildConditionExpression(where);
8026
+ }
7871
8027
  const entity = yield this.entityRepository.updateEntity(
7872
8028
  entityType,
7873
8029
  entityId,
@@ -7880,7 +8036,7 @@ var EntityService = class {
7880
8036
  const byEntityId = entityId;
7881
8037
  const publishEventPromises = [];
7882
8038
  for (const [fieldKey, config] of Object.entries(
7883
- ((_b = this.EntityConfig[entityType].mutual) == null ? void 0 : _b.mutualFields) || {}
8039
+ ((_d = this.EntityConfig[entityType].mutual) == null ? void 0 : _d.mutualFields) || {}
7884
8040
  )) {
7885
8041
  const toMutualIds = config.toMutualIds;
7886
8042
  const mutualPayload = parsedMutualPayload[fieldKey];
@@ -7936,6 +8092,35 @@ var EntityService = class {
7936
8092
  });
7937
8093
  });
7938
8094
  }
8095
+ /** @deprecated Converts legacy adjustmentConstraints to condition expression opts. */
8096
+ buildLegacyAdjustCondition(adjustments, constraints) {
8097
+ const conditionParts = [];
8098
+ const names = { "#data": "data" };
8099
+ const values = {};
8100
+ for (const [field, constraint] of Object.entries(constraints)) {
8101
+ const delta = adjustments[field];
8102
+ if (delta === void 0) continue;
8103
+ const namePlaceholder = `#where_${field}`;
8104
+ names[namePlaceholder] = field;
8105
+ const fieldRef = `#data.${namePlaceholder}`;
8106
+ if (constraint.min !== void 0 && delta < 0) {
8107
+ const valKey = `:where_${field}_min_threshold`;
8108
+ conditionParts.push(`${fieldRef} >= ${valKey}`);
8109
+ values[valKey] = constraint.min - delta;
8110
+ }
8111
+ if (constraint.max !== void 0 && delta > 0) {
8112
+ const valKey = `:where_${field}_max_threshold`;
8113
+ conditionParts.push(`${fieldRef} <= ${valKey}`);
8114
+ values[valKey] = constraint.max - delta;
8115
+ }
8116
+ }
8117
+ if (conditionParts.length === 0) return void 0;
8118
+ return {
8119
+ ConditionExpression: conditionParts.join(" AND "),
8120
+ ExpressionAttributeNames: names,
8121
+ ExpressionAttributeValues: marshall6(values)
8122
+ };
8123
+ }
7939
8124
  };
7940
8125
 
7941
8126
  // services/mutual.service.ts
@@ -8237,6 +8422,68 @@ var ListTagsController = class {
8237
8422
  }
8238
8423
  };
8239
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
+
8240
8487
  // services/entity-service-lifecycle.ts
8241
8488
  var EntityServiceLifeCycle = class {
8242
8489
  constructor(EntityConfig, publishEvent2, eventUtils) {
@@ -8269,6 +8516,462 @@ var EntityServiceLifeCycle = class {
8269
8516
  }
8270
8517
  };
8271
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
+
8272
8975
  // services/DependencyContainer.ts
8273
8976
  var DependencyContainer = class {
8274
8977
  constructor(config) {
@@ -8445,6 +9148,59 @@ var DependencyContainer = class {
8445
9148
  get listTagsController() {
8446
9149
  return this.createCachedInstance(ListTagsController, this.tagRepository);
8447
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
+ })
8448
9204
  };
8449
9205
 
8450
9206
  // index.ts
@@ -8475,6 +9231,7 @@ export {
8475
9231
  StandardError,
8476
9232
  StandardErrorCode,
8477
9233
  TagRepository,
9234
+ TransactionService,
8478
9235
  appHandler,
8479
9236
  handler as createEntityProcessor,
8480
9237
  index_default as default,
@@ -8482,6 +9239,7 @@ export {
8482
9239
  handler3 as prejoinProcessor,
8483
9240
  handler4 as replicationProcessor,
8484
9241
  setupCommonRoutes,
8485
- handler5 as tagProcessor
9242
+ handler5 as tagProcessor,
9243
+ transactional
8486
9244
  };
8487
9245
  //# sourceMappingURL=index.js.map