@kensio/yulin 1.21.26 → 1.21.27

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 (74) hide show
  1. package/dist/service/eventbridge/bus/sim-event-bus-name.d.ts +4 -0
  2. package/dist/service/eventbridge/bus/sim-event-bus-name.js +17 -12
  3. package/dist/service/eventbridge/cfn/bus/sim-cfn-event-bus-creator.js +8 -1
  4. package/dist/service/eventbridge/cfn/bus/sim-cfn-event-bus-properties.d.ts +5 -0
  5. package/dist/service/eventbridge/cfn/bus/sim-cfn-event-bus-properties.js +14 -1
  6. package/dist/service/eventbridge/cfn/rule/sim-cfn-event-rule-creator.js +2 -0
  7. package/dist/service/eventbridge/cfn/rule/sim-cfn-event-rule-target-delivery.d.ts +15 -0
  8. package/dist/service/eventbridge/cfn/rule/sim-cfn-event-rule-target-delivery.js +53 -0
  9. package/dist/service/eventbridge/cfn/rule/sim-cfn-event-rule-targets.d.ts +4 -0
  10. package/dist/service/eventbridge/cfn/rule/sim-cfn-event-rule-targets.js +7 -3
  11. package/dist/service/eventbridge/command/authorize/sim-event-bridge-authorizer.d.ts +5 -0
  12. package/dist/service/eventbridge/command/authorize/sim-event-bridge-authorizer.js +7 -0
  13. package/dist/service/eventbridge/command/bus/sim-event-bridge-create-event-bus.d.ts +7 -1
  14. package/dist/service/eventbridge/command/bus/sim-event-bridge-create-event-bus.js +7 -1
  15. package/dist/service/eventbridge/command/bus/sim-event-bridge-partner-bus.d.ts +24 -0
  16. package/dist/service/eventbridge/command/bus/sim-event-bridge-partner-bus.js +44 -0
  17. package/dist/service/eventbridge/command/bus/sim-event-bridge-unsimulated-bus-input.js +0 -5
  18. package/dist/service/eventbridge/command/put-events/sim-event-bridge-authorized-entries.js +8 -0
  19. package/dist/service/eventbridge/command/sim-event-bridge-command.types.d.ts +1 -0
  20. package/dist/service/eventbridge/command/sim-event-bridge-commands.d.ts +6 -0
  21. package/dist/service/eventbridge/command/sim-event-bridge-commands.js +19 -1
  22. package/dist/service/eventbridge/command/source/sim-event-bridge-describe-event-source.d.ts +35 -0
  23. package/dist/service/eventbridge/command/source/sim-event-bridge-describe-event-source.js +46 -0
  24. package/dist/service/eventbridge/command/source/sim-event-bridge-put-partner-events.d.ts +41 -0
  25. package/dist/service/eventbridge/command/source/sim-event-bridge-put-partner-events.js +82 -0
  26. package/dist/service/eventbridge/command/source/source.command.d.ts +59 -0
  27. package/dist/service/eventbridge/command/source/source.command.js +1 -0
  28. package/dist/service/eventbridge/command/target/sim-event-bridge-target-commands.js +2 -0
  29. package/dist/service/eventbridge/command/target/sim-event-bridge-unsimulated-target-input.js +2 -12
  30. package/dist/service/eventbridge/command/target/target.command.d.ts +8 -5
  31. package/dist/service/eventbridge/delivery/sim-aws-event-bridge-delivery-targets.d.ts +6 -1
  32. package/dist/service/eventbridge/delivery/sim-aws-event-bridge-delivery-targets.js +16 -0
  33. package/dist/service/eventbridge/delivery/sim-event-bridge-dead-letter-attributes.d.ts +9 -0
  34. package/dist/service/eventbridge/delivery/sim-event-bridge-dead-letter-attributes.js +47 -0
  35. package/dist/service/eventbridge/delivery/sim-event-bridge-dead-letter-queue.d.ts +24 -0
  36. package/dist/service/eventbridge/delivery/sim-event-bridge-dead-letter-queue.js +28 -0
  37. package/dist/service/eventbridge/delivery/sim-event-bridge-delivery-attempt.d.ts +41 -0
  38. package/dist/service/eventbridge/delivery/sim-event-bridge-delivery-attempt.js +97 -0
  39. package/dist/service/eventbridge/delivery/sim-event-bridge-delivery-queue.js +7 -37
  40. package/dist/service/eventbridge/delivery/sim-event-bridge-delivery-retries.test-support.d.ts +25 -0
  41. package/dist/service/eventbridge/delivery/sim-event-bridge-delivery-retries.test-support.js +60 -0
  42. package/dist/service/eventbridge/delivery/sim-event-bridge-delivery.d.ts +22 -0
  43. package/dist/service/eventbridge/delivery/sim-event-bridge-failing-targets.test-support.d.ts +23 -0
  44. package/dist/service/eventbridge/delivery/sim-event-bridge-failing-targets.test-support.js +28 -0
  45. package/dist/service/eventbridge/delivery/sim-event-bridge-no-delivery-targets.d.ts +5 -1
  46. package/dist/service/eventbridge/delivery/sim-event-bridge-no-delivery-targets.js +9 -0
  47. package/dist/service/eventbridge/delivery/sim-event-bridge-queue-message.d.ts +28 -0
  48. package/dist/service/eventbridge/delivery/sim-event-bridge-queue-message.js +45 -0
  49. package/dist/service/eventbridge/delivery/sim-event-bridge-target-delivery.d.ts +4 -1
  50. package/dist/service/eventbridge/delivery/sim-event-bridge-target-delivery.js +19 -14
  51. package/dist/service/eventbridge/index.d.ts +2 -0
  52. package/dist/service/eventbridge/index.js +2 -0
  53. package/dist/service/eventbridge/routing/sim-event-bridge-router.js +1 -0
  54. package/dist/service/eventbridge/sdk/sim-event-bridge-sdk-command-router.js +4 -0
  55. package/dist/service/eventbridge/sim-event-bridge-inspection.d.ts +10 -0
  56. package/dist/service/eventbridge/sim-event-bridge-inspection.js +9 -0
  57. package/dist/service/eventbridge/sim-event-bridge-partners.d.ts +38 -0
  58. package/dist/service/eventbridge/sim-event-bridge-partners.js +43 -0
  59. package/dist/service/eventbridge/sim-event-bridge.d.ts +12 -12
  60. package/dist/service/eventbridge/sim-event-bridge.js +14 -11
  61. package/dist/service/eventbridge/source/sim-partner-event-source-name.d.ts +28 -0
  62. package/dist/service/eventbridge/source/sim-partner-event-source-name.js +62 -0
  63. package/dist/service/eventbridge/source/sim-partner-event-source-store.d.ts +18 -0
  64. package/dist/service/eventbridge/source/sim-partner-event-source-store.js +29 -0
  65. package/dist/service/eventbridge/source/sim-partner-event-source.d.ts +46 -0
  66. package/dist/service/eventbridge/source/sim-partner-event-source.js +43 -0
  67. package/dist/service/eventbridge/target/sim-event-target-dead-letter-config.d.ts +28 -0
  68. package/dist/service/eventbridge/target/sim-event-target-dead-letter-config.js +42 -0
  69. package/dist/service/eventbridge/target/sim-event-target-retry-policy.d.ts +28 -0
  70. package/dist/service/eventbridge/target/sim-event-target-retry-policy.js +53 -0
  71. package/dist/service/eventbridge/target/sim-event-target.d.ts +17 -0
  72. package/dist/service/eventbridge/target/sim-event-target.js +19 -0
  73. package/docs/services/eventbridge/README.md +223 -6
  74. package/package.json +1 -1
@@ -921,6 +921,91 @@ and a rule routes the same events whether it carries them or not. They are recor
921
921
  property and the deploy stands. Nothing reads them back. A rule or a bus deployed with tags behaves
922
922
  as though the template had never named them.
923
923
 
924
+ ## Receiving events from a SaaS partner
925
+
926
+ A SaaS partner such as Stripe sends events to an account through a partner event source, named like
927
+ `aws.partner/stripe.com/ed_...`. The partner creates the source from its own account, so a test
928
+ shares one with `addPartnerEventSource(...)`. The account then creates a partner event bus with the
929
+ same `Name` and `EventSourceName`, and `putPartnerEvents(...)` sends events onto it as the partner
930
+ would.
931
+
932
+ ```typescript sim-event-bridge-partner-events
933
+ /**
934
+ * Receiving Stripe's events on a partner event bus.
935
+ */
936
+
937
+ import {
938
+ CreateEventBusCommand,
939
+ PutPartnerEventsCommand,
940
+ PutRuleCommand,
941
+ } from "@aws-sdk/client-eventbridge";
942
+
943
+ import { SimAws } from "@kensio/yulin";
944
+
945
+ const simAws = new SimAws();
946
+ const events = simAws.eventBridge();
947
+ const source = "aws.partner/stripe.com/ed_test_billing";
948
+
949
+ // What Stripe does when an event destination is set up for the account.
950
+ events.addPartnerEventSource(source);
951
+
952
+ // What the account does to receive from it.
953
+ await events.createEventBus(
954
+ new CreateEventBusCommand({ Name: source, EventSourceName: source }),
955
+ );
956
+ await events.putRule(
957
+ new PutRuleCommand({
958
+ Name: "subscriptions",
959
+ EventBusName: source,
960
+ EventPattern: JSON.stringify({
961
+ source: [{ prefix: "aws.partner/stripe.com" }],
962
+ "detail-type": ["customer.subscription.created"],
963
+ }),
964
+ }),
965
+ );
966
+
967
+ // What Stripe sends when a subscription starts.
968
+ await events.putPartnerEvents(
969
+ new PutPartnerEventsCommand({
970
+ Entries: [
971
+ {
972
+ Source: source,
973
+ DetailType: "customer.subscription.created",
974
+ Detail: JSON.stringify({
975
+ id: "evt_test_subscription",
976
+ type: "customer.subscription.created",
977
+ data: { object: { id: "sub_test" } },
978
+ }),
979
+ },
980
+ ],
981
+ }),
982
+ );
983
+
984
+ console.log(events.receiptsOn(source)[0]?.matchedRuleNames); // ["subscriptions"]
985
+ ```
986
+
987
+ `putPartnerEvents(...)` takes the entries of the partner's `PutPartnerEvents` request. Each entry's
988
+ `Source` names a shared source, and the event goes to the bus of the same name. Rules match it on
989
+ `source`, `detail-type` and `detail` like any other event. A target receives the usual envelope, with
990
+ `account` set to the receiving account. Stripe puts its event type in `DetailType` and the whole
991
+ Stripe event object, as JSON, in `Detail`. An entry whose `Source` names no shared source fails the
992
+ whole request with `ResourceNotFoundException`.
993
+
994
+ An `AWS::Events::EventBus` with `Name` and `EventSourceName` both set to the source name creates the
995
+ same bus from a template, and a rule names it with a `Ref` to the bus.
996
+
997
+ The source has to be shared before the bus is created. `CreateEventBus` fails with
998
+ `ResourceNotFoundException` when it is missing, and a template creating the bus fails its stack, as
999
+ both do on AWS. A `Name` that differs from the `EventSourceName` is a `ValidationException`, as is a
1000
+ `/` in the name of a bus created without one.
1001
+
1002
+ `DescribeEventSource` reports the source as `PENDING` until its bus exists, and `ACTIVE` after.
1003
+ Deleting the bus puts it back to `PENDING`. An event sent while the source is pending is dropped,
1004
+ as AWS documents.
1005
+
1006
+ Only the partner sends events to a partner event bus. `PutEvents` naming one is refused with a
1007
+ `ValidationException` (its `EventBusName` takes no `/`).
1008
+
924
1009
  ## Reading back a failed delivery
925
1010
 
926
1011
  Real EventBridge tells the caller nothing about a failed delivery. A `PutEvents` that matched a rule
@@ -981,6 +1066,125 @@ no is a modelled outcome a test may be asking for on purpose.
981
1066
  `JSON.stringify` on a failure carries the message alongside the rule, the target and the event it
982
1067
  names.
983
1068
 
1069
+ ## Retrying and dead-lettering a delivery
1070
+
1071
+ A target can carry a `RetryPolicy` and a `DeadLetterConfig`, from `PutTargets` or from a target in an
1072
+ `AWS::Events::Rule`. The dead-letter queue receives an event once EventBridge gives up delivering it.
1073
+
1074
+ ```typescript sim-event-bridge-dead-letter
1075
+ /**
1076
+ * Sending an event a target refused to its dead-letter queue.
1077
+ */
1078
+
1079
+ import {
1080
+ PutEventsCommand,
1081
+ PutRuleCommand,
1082
+ PutTargetsCommand,
1083
+ } from "@aws-sdk/client-eventbridge";
1084
+ import {
1085
+ CreateQueueCommand,
1086
+ ReceiveMessageCommand,
1087
+ SetQueueAttributesCommand,
1088
+ } from "@aws-sdk/client-sqs";
1089
+
1090
+ import { SimAws } from "@kensio/yulin";
1091
+
1092
+ const simAws = new SimAws();
1093
+ const dlqArn = "arn:aws:sqs:us-east-1:888888888888:undelivered-orders";
1094
+
1095
+ // A dead-letter queue admitting EventBridge for the rule.
1096
+ const { QueueUrl } = await simAws
1097
+ .sqs()
1098
+ .createQueue(new CreateQueueCommand({ QueueName: "undelivered-orders" }));
1099
+ await simAws.sqs().setQueueAttributes(
1100
+ new SetQueueAttributesCommand({
1101
+ QueueUrl,
1102
+ Attributes: {
1103
+ Policy: JSON.stringify({
1104
+ Version: "2012-10-17",
1105
+ Statement: [
1106
+ {
1107
+ Effect: "Allow",
1108
+ Principal: { Service: "events.amazonaws.com" },
1109
+ Action: "sqs:SendMessage",
1110
+ Resource: dlqArn,
1111
+ Condition: {
1112
+ ArnEquals: {
1113
+ "aws:SourceArn":
1114
+ "arn:aws:events:us-east-1:888888888888:rule/orders",
1115
+ },
1116
+ },
1117
+ },
1118
+ ],
1119
+ }),
1120
+ },
1121
+ }),
1122
+ );
1123
+
1124
+ // A target queue that was never created, so every delivery fails.
1125
+ await simAws.eventBridge().putRule(
1126
+ new PutRuleCommand({
1127
+ Name: "orders",
1128
+ EventPattern: JSON.stringify({ source: ["orders.service"] }),
1129
+ }),
1130
+ );
1131
+ await simAws.eventBridge().putTargets(
1132
+ new PutTargetsCommand({
1133
+ Rule: "orders",
1134
+ Targets: [
1135
+ {
1136
+ Id: "fulfilment",
1137
+ Arn: "arn:aws:sqs:us-east-1:888888888888:fulfilment",
1138
+ RetryPolicy: { MaximumRetryAttempts: 2 },
1139
+ DeadLetterConfig: { Arn: dlqArn },
1140
+ },
1141
+ ],
1142
+ }),
1143
+ );
1144
+
1145
+ await simAws.eventBridge().putEvents(
1146
+ new PutEventsCommand({
1147
+ Entries: [
1148
+ { Source: "orders.service", DetailType: "OrderPlaced", Detail: "{}" },
1149
+ ],
1150
+ }),
1151
+ );
1152
+ await simAws.backgroundTasksComplete();
1153
+
1154
+ const { Messages } = await simAws
1155
+ .sqs()
1156
+ .receiveMessage(
1157
+ new ReceiveMessageCommand({ QueueUrl, MessageAttributeNames: ["All"] }),
1158
+ );
1159
+
1160
+ console.log(Messages?.[0]?.MessageAttributes?.["ERROR_CODE"]?.StringValue);
1161
+ // "NO_RESOURCE"
1162
+ ```
1163
+
1164
+ The message body is the event, as JSON. Its attributes are the ones EventBridge documents.
1165
+ `RULE_ARN` and `TARGET_ARN` name where the event was going. `ERROR_CODE` and `ERROR_MESSAGE` say why
1166
+ it failed, and `RETRY_ATTEMPTS` counts the retries made. `EXHAUSTED_RETRY_CONDITION` is
1167
+ `MaximumRetryAttempts` or `MaximumEventAgeInSeconds` when a retry limit ran out.
1168
+
1169
+ `ERROR_CODE` is `NO_PERMISSIONS` for a target that refused EventBridge and `NO_RESOURCE` for one
1170
+ that is not there. Every other failure is `ERROR_FROM_TARGET`. EventBridge lists these codes
1171
+ without saying which failure gets which.
1172
+
1173
+ A missing target and a refusal are never retried, because the same request gets the same answer.
1174
+ EventBridge sends both straight to the dead-letter queue, and so does Yulin. Any other failure is
1175
+ retried on the simulation's clock. The first retry is due one second after the failed attempt, and
1176
+ each following wait doubles to 2, 4, 8 seconds and so on. Retries stop at `MaximumRetryAttempts`, or
1177
+ once the event is `MaximumEventAgeInSeconds` old. A retry only runs as `advanceBy(...)` moves the
1178
+ clock past it.
1179
+
1180
+ EventBridge sends to the dead-letter queue as `events.amazonaws.com`, with the rule ARN as
1181
+ `aws:SourceArn`, so the queue policy has to admit it. A dead-letter queue that is missing or refuses
1182
+ EventBridge leaves the failure in `deliveryFailures`. An event that reached its dead-letter queue
1183
+ leaves nothing there.
1184
+
1185
+ A Lambda target is invoked asynchronously. Once Lambda accepts the invocation the delivery is done,
1186
+ and a handler error is left to the function's own retries and destinations.
1187
+
984
1188
  ## Permissions
985
1189
 
986
1190
  Most operations are authorized by simulated IAM against the bus ARN. The two that name no bus
@@ -1048,6 +1252,8 @@ no permission for.
1048
1252
  ## Supported operations
1049
1253
 
1050
1254
  - `CreateEventBus`, `DeleteEventBus`, `DescribeEventBus`, `ListEventBuses` and `PutEvents`.
1255
+ - Partner event buses created with `EventSourceName`, and `DescribeEventSource`. A test acts as the
1256
+ partner through `addPartnerEventSource(...)` and `putPartnerEvents(...)`.
1051
1257
  - `PutRule`, `DeleteRule`, `DescribeRule`, `ListRules`, `EnableRule`, `DisableRule` and
1052
1258
  `TestEventPattern`.
1053
1259
  - Scheduled rules, with a `rate(...)` or six-field `cron(...)` `ScheduleExpression`, fired by
@@ -1061,6 +1267,8 @@ no permission for.
1061
1267
  - Targets in another account or region of the same simulation, admitted by the target's own resource
1062
1268
  policy on `aws:SourceArn` or `aws:SourceAccount`, as real EventBridge does.
1063
1269
  - A target's fixed `Input`, and `deliveryFailures` for a delivery that failed.
1270
+ - A target's `RetryPolicy`, retried on the simulation's clock, and its `DeadLetterConfig`, with the
1271
+ dead-letter message attributes EventBridge documents.
1064
1272
  - The `default` bus in every account and region, without one being created.
1065
1273
  - Bus descriptions, creation timestamps from the simulation's clock, and prefix-narrowed paged
1066
1274
  listings.
@@ -1073,9 +1281,13 @@ no permission for.
1073
1281
 
1074
1282
  - Targets deliver to Lambda, SQS and SNS, and run a task in ECS. A target ARN naming any other
1075
1283
  service is refused as the target is added, ahead of any matching event.
1076
- - Target `InputPath` and `InputTransformer` are refused, as are dead letter queues and retry
1077
- policies. A delivery is attempted once. A target `RoleArn` is refused except on an ECS target.
1078
- That is the one target type that runs as a role, where the others run as the service principal.
1284
+ - Target `InputPath` and `InputTransformer` are refused. A target `RoleArn` is refused except on an
1285
+ ECS target. That is the one target type that runs as a role, where the others run as the service
1286
+ principal.
1287
+ - A target with no `RetryPolicy` is delivered once. Real EventBridge retries such a target for up to
1288
+ 24 hours and 185 times. Retry waits are deterministic powers of two seconds, where real
1289
+ EventBridge uses exponential backoff with jitter. The fixed sequence lets a test move the clock to
1290
+ a known retry.
1079
1291
  - An ECS target's `EcsParameters` takes `TaskDefinitionArn` and `TaskCount`, and takes and ignores
1080
1292
  `LaunchType`, `PlatformVersion`, `NetworkConfiguration` and `CapacityProviderStrategy`, since
1081
1293
  there is no placement and no network here for them to apply to. Anything else it can carry, such
@@ -1115,8 +1327,13 @@ no permission for.
1115
1327
  attribute are all missing, and a caller from another account cannot be admitted to a bus. That is
1116
1328
  stricter than real AWS.
1117
1329
  - Putting an event onto another account's or region's bus is refused.
1118
- - Partner event buses and partner event sources are refused, as are event bus tags, encryption with
1119
- a customer managed key, dead letter queues, logging configuration and global endpoints. An
1120
- `AWS::Events::EventBus` carrying `Tags` deploys with the tags dropped and the property recorded.
1330
+ - Event bus tags, encryption with a customer managed key, dead letter queues, logging configuration
1331
+ and global endpoints are refused. An `AWS::Events::EventBus` carrying `Tags` deploys with the tags
1332
+ dropped and the property recorded.
1333
+ - A pending partner event source never expires, and `DescribeEventSource` leaves out
1334
+ `ExpirationTime`. Its `CreatedBy` is the segment after `aws.partner/`, such as `stripe.com`.
1335
+ `ListEventSources`, `ActivateEventSource` and `DeactivateEventSource` are absent, as are the
1336
+ partner's own commands. A partner is a test calling `addPartnerEventSource(...)` and
1337
+ `putPartnerEvents(...)`.
1121
1338
  - Archives, replay, schema registry and discovery, API destinations and connections are not
1122
1339
  simulated.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kensio/yulin",
3
- "version": "1.21.26",
3
+ "version": "1.21.27",
4
4
  "description": "AWS system behaviour simulation for isolated unit testing",
5
5
  "repository": "https://github.com/KensioSoftware/yulin",
6
6
  "homepage": "https://yulinsim.dev/",