@eventcatalog/create-eventcatalog 4.3.12 → 4.3.14-beta.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/LICENSE +0 -10
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/templates/amazon-api-gateway/README-template.md +4 -0
- package/templates/asyncapi/README-template.md +4 -0
- package/templates/asyncapi/env +0 -5
- package/templates/confluent/README-template.md +4 -0
- package/templates/default/README-template.md +4 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/commands/CreateProduct/examples/index.mdx +194 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/commands/DeleteProduct/examples/index.mdx +161 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/commands/UpdateProduct/examples/index.mdx +182 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/events/ProductCreated/examples/index.mdx +227 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/events/ProductDeleted/examples/index.mdx +175 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/events/ProductUpdated/examples/index.mdx +205 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/queries/GetProduct/examples/index.mdx +205 -0
- package/templates/default/domains/Catalog/systems/search-system/services/SearchAPI/queries/SearchProducts/examples/index.mdx +369 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/commands/RegisterCustomer/examples/index.mdx +168 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/commands/UpdateCustomer/examples/index.mdx +168 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/events/CustomerRegistered/examples/index.mdx +201 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/events/CustomerUpdated/examples/index.mdx +194 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/queries/GetCustomer/examples/index.mdx +194 -0
- package/templates/default/domains/Customer/systems/identity-provider/services/OAuthAPI/commands/AuthenticateCustomer/examples/index.mdx +198 -0
- package/templates/default/domains/Customer/systems/identity-provider/services/OAuthAPI/events/CustomerAuthenticated/examples/index.mdx +276 -0
- package/templates/default/domains/Fulfilment/systems/carrier/services/CarrierTrackingAPI/events/ShipmentCreated/examples/index.mdx +184 -0
- package/templates/default/domains/Fulfilment/systems/carrier/services/CarrierTrackingAPI/events/ShipmentDelivered/examples/index.mdx +173 -0
- package/templates/default/domains/Fulfilment/systems/carrier/services/CarrierTrackingAPI/events/ShipmentFailed/examples/index.mdx +265 -0
- package/templates/default/domains/Fulfilment/systems/inventory-system/services/InventoryService/commands/ReleaseInventory/examples/index.mdx +246 -0
- package/templates/default/domains/Fulfilment/systems/inventory-system/services/InventoryService/events/InventoryReserved/examples/index.mdx +227 -0
- package/templates/default/domains/Fulfilment/systems/inventory-system/services/InventoryService/events/InventoryUnavailable/examples/index.mdx +229 -0
- package/templates/default/domains/Fulfilment/systems/inventory-system/services/InventoryService/queries/GetStockLevel/examples/index.mdx +186 -0
- package/templates/default/domains/Fulfilment/systems/shipping-system/services/CarrierAdapter/commands/CreateShipment/examples/index.mdx +206 -0
- package/templates/default/domains/Fulfilment/systems/warehouse-system/services/PickingWorker/events/OrderPacked/examples/index.mdx +172 -0
- package/templates/default/domains/Fulfilment/systems/warehouse-system/services/WarehouseService/events/OrderReadyForShipping/examples/index.mdx +208 -0
- package/templates/default/domains/Ordering/systems/checkout-system/services/CheckoutOrchestrator/commands/AuthorizePayment/examples/index.mdx +179 -0
- package/templates/default/domains/Ordering/systems/checkout-system/services/CheckoutOrchestrator/commands/ReserveInventory/examples/index.mdx +215 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/commands/CancelOrder/examples/index.mdx +163 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/commands/CreateOrder/examples/index.mdx +246 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/events/OrderCancelled/examples/index.mdx +267 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/events/OrderCompleted/examples/index.mdx +171 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/events/OrderCreated/examples/index.mdx +190 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/queries/GetOrder/examples/index.mdx +343 -0
- package/templates/default/domains/Payments/systems/fraud-detection/services/FraudAPI/events/FraudCheckFailed/examples/index.mdx +271 -0
- package/templates/default/domains/Payments/systems/fraud-detection/services/FraudAPI/events/FraudCheckPassed/examples/index.mdx +173 -0
- package/templates/default/domains/Payments/systems/payment-processing-system/services/PaymentWorker/events/PaymentRequested/examples/index.mdx +191 -0
- package/templates/default/domains/Payments/systems/payment-processing-system/services/PaymentWorker/events/RefundRequested/examples/index.mdx +194 -0
- package/templates/default/domains/Payments/systems/stripe/services/StripeWebhookEndpoint/events/PaymentFailed/examples/index.mdx +265 -0
- package/templates/default/domains/Payments/systems/stripe/services/StripeWebhookEndpoint/events/PaymentSucceeded/examples/index.mdx +190 -0
- package/templates/default/domains/Payments/systems/stripe/services/StripeWebhookEndpoint/events/RefundProcessed/examples/index.mdx +186 -0
- package/templates/default/domains/Reviews/services/RatingAggregator/events/rating-updated/examples/index.mdx +183 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/commands/flag-review/examples/index.mdx +183 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/commands/submit-review/examples/index.mdx +195 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/commands/vote-review-helpful/examples/index.mdx +178 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/events/review-flagged/examples/index.mdx +186 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/events/review-helpful-voted/examples/index.mdx +177 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/events/review-submitted/examples/index.mdx +194 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/queries/get-product-reviews/examples/index.mdx +259 -0
- package/templates/default/domains/Reviews/services/ReviewModerationWorker/events/review-published/examples/index.mdx +183 -0
- package/templates/default/domains/Reviews/services/ReviewModerationWorker/events/review-rejected/examples/index.mdx +178 -0
- package/templates/default/domains/Shopping/systems/cart-system/services/CartAPI/commands/AddItemToCart/examples/index.mdx +171 -0
- package/templates/default/domains/Shopping/systems/cart-system/services/CartAPI/commands/CheckoutCart/examples/index.mdx +168 -0
- package/templates/default/domains/Shopping/systems/cart-system/services/CartAPI/commands/RemoveItemFromCart/examples/index.mdx +170 -0
- package/templates/default/domains/Shopping/systems/cart-system/services/CartAPI/events/CartCheckedOut/examples/index.mdx +275 -0
- package/templates/default/domains/Shopping/systems/promotion-system/services/PromotionService/commands/CalculateDiscount/examples/index.mdx +207 -0
- package/templates/default/domains/Shopping/systems/promotion-system/services/PromotionService/events/DiscountCalculated/examples/index.mdx +190 -0
- package/templates/default/env +0 -5
- package/templates/empty/README-template.md +4 -0
- package/templates/empty/env +0 -5
- package/templates/eventbridge/README-template.md +4 -0
- package/templates/graphql/README-template.md +4 -0
- package/templates/graphql/env +0 -5
- package/templates/openapi/README-template.md +4 -0
- package/templates/openapi/env +0 -5
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
<Columns cols={2}>
|
|
2
|
+
|
|
3
|
+
<Column>
|
|
4
|
+
|
|
5
|
+
## 1. Authorise payment for a UK cart
|
|
6
|
+
|
|
7
|
+
Once stock is reserved for two T-shirts and a cap, the Checkout Orchestrator asks the payment provider to place a hold for the cart total. The funds are captured after the order is created.
|
|
8
|
+
|
|
9
|
+
### Payload details
|
|
10
|
+
|
|
11
|
+
- `cartId` matches the cart whose stock has just been reserved.
|
|
12
|
+
- `customerId` identifies the paying customer.
|
|
13
|
+
- `amount` is in pence: 2 × 1,999 (T-shirts) + 1 × 1,499 (cap).
|
|
14
|
+
- `currency` is `GBP`, a three-letter ISO 4217 code.
|
|
15
|
+
|
|
16
|
+
The amount to authorise is **5,497 pence (£54.97)**.
|
|
17
|
+
|
|
18
|
+
### Using this example
|
|
19
|
+
|
|
20
|
+
The payment handler should place a hold of exactly 5,497 pence on the customer's payment method and return an authorisation ID for the `CreateOrder` step.
|
|
21
|
+
|
|
22
|
+
The examples use a **fictional Acme Events SDK** to send a payload matching the AuthorizePayment schema. The package names and send methods are illustrative.
|
|
23
|
+
|
|
24
|
+
</Column>
|
|
25
|
+
|
|
26
|
+
<Column>
|
|
27
|
+
|
|
28
|
+
<CodeGroup dropdown>
|
|
29
|
+
|
|
30
|
+
```typescript send-authorize-payment.ts
|
|
31
|
+
import { EventsClient } from '@acme/events';
|
|
32
|
+
import type { AuthorizePayment } from './schemas/authorize-payment';
|
|
33
|
+
|
|
34
|
+
const client = new EventsClient({
|
|
35
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const command: AuthorizePayment = {
|
|
39
|
+
cartId: 'c1a2b3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d',
|
|
40
|
+
customerId: '3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d',
|
|
41
|
+
amount: 5497,
|
|
42
|
+
currency: 'GBP',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
await client.send('AuthorizePayment', command);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```python send_authorize_payment.py
|
|
49
|
+
import os
|
|
50
|
+
from acme_events import EventsClient
|
|
51
|
+
|
|
52
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
53
|
+
|
|
54
|
+
command = {
|
|
55
|
+
"cartId": "c1a2b3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
|
|
56
|
+
"customerId": "3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d",
|
|
57
|
+
"amount": 5497,
|
|
58
|
+
"currency": "GBP",
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
client.send("AuthorizePayment", command)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```java SendAuthorizePayment.java
|
|
65
|
+
import com.acme.events.EventsClient;
|
|
66
|
+
import java.util.Map;
|
|
67
|
+
|
|
68
|
+
public class SendAuthorizePayment {
|
|
69
|
+
public static void main(String[] args) {
|
|
70
|
+
var client = new EventsClient(
|
|
71
|
+
System.getenv("ACME_API_KEY")
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
var command = Map.of(
|
|
75
|
+
"cartId", "c1a2b3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
|
|
76
|
+
"customerId", "3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d",
|
|
77
|
+
"amount", 5497,
|
|
78
|
+
"currency", "GBP"
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
client.send("AuthorizePayment", command);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
</CodeGroup>
|
|
87
|
+
|
|
88
|
+
</Column>
|
|
89
|
+
|
|
90
|
+
</Columns>
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
<Columns cols={2}>
|
|
95
|
+
|
|
96
|
+
<Column>
|
|
97
|
+
|
|
98
|
+
## 2. Authorise a euro payment with only the required fields
|
|
99
|
+
|
|
100
|
+
A cart with one hoodie is priced in euros. The orchestrator sends only the required fields, leaving out the optional `customerId`.
|
|
101
|
+
|
|
102
|
+
### Payload details
|
|
103
|
+
|
|
104
|
+
- `cartId` identifies the cart; there is no `customerId`.
|
|
105
|
+
- `amount` is in cents: 1 × 5,799 for the hoodie.
|
|
106
|
+
- `currency` is `EUR`, showing that amounts are not always in pounds.
|
|
107
|
+
|
|
108
|
+
The amount to authorise is **5,799 cents (€57.99)**.
|
|
109
|
+
|
|
110
|
+
### Using this example
|
|
111
|
+
|
|
112
|
+
Use this to check that the payment handler reads `amount` in the minor units of `currency`, and does not need a `customerId` to authorise.
|
|
113
|
+
|
|
114
|
+
The examples use a **fictional Acme Events SDK** to send a payload matching the AuthorizePayment schema. The package names and send methods are illustrative.
|
|
115
|
+
|
|
116
|
+
</Column>
|
|
117
|
+
|
|
118
|
+
<Column>
|
|
119
|
+
|
|
120
|
+
<CodeGroup dropdown>
|
|
121
|
+
|
|
122
|
+
```typescript send-authorize-payment.ts
|
|
123
|
+
import { EventsClient } from '@acme/events';
|
|
124
|
+
import type { AuthorizePayment } from './schemas/authorize-payment';
|
|
125
|
+
|
|
126
|
+
const client = new EventsClient({
|
|
127
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const command: AuthorizePayment = {
|
|
131
|
+
cartId: 'd2b3c4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e',
|
|
132
|
+
amount: 5799,
|
|
133
|
+
currency: 'EUR',
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
await client.send('AuthorizePayment', command);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```python send_authorize_payment.py
|
|
140
|
+
import os
|
|
141
|
+
from acme_events import EventsClient
|
|
142
|
+
|
|
143
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
144
|
+
|
|
145
|
+
command = {
|
|
146
|
+
"cartId": "d2b3c4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",
|
|
147
|
+
"amount": 5799,
|
|
148
|
+
"currency": "EUR",
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
client.send("AuthorizePayment", command)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
```java SendAuthorizePayment.java
|
|
155
|
+
import com.acme.events.EventsClient;
|
|
156
|
+
import java.util.Map;
|
|
157
|
+
|
|
158
|
+
public class SendAuthorizePayment {
|
|
159
|
+
public static void main(String[] args) {
|
|
160
|
+
var client = new EventsClient(
|
|
161
|
+
System.getenv("ACME_API_KEY")
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
var command = Map.of(
|
|
165
|
+
"cartId", "d2b3c4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",
|
|
166
|
+
"amount", 5799,
|
|
167
|
+
"currency", "EUR"
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
client.send("AuthorizePayment", command);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
</CodeGroup>
|
|
176
|
+
|
|
177
|
+
</Column>
|
|
178
|
+
|
|
179
|
+
</Columns>
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
<Columns cols={2}>
|
|
2
|
+
|
|
3
|
+
<Column>
|
|
4
|
+
|
|
5
|
+
## 1. Reserve stock for a multi-item cart
|
|
6
|
+
|
|
7
|
+
A signed-in customer checks out a cart with two T-shirts and a cap. The Checkout Orchestrator sends this command first, so the stock is held while payment is authorised.
|
|
8
|
+
|
|
9
|
+
### Payload details
|
|
10
|
+
|
|
11
|
+
- `cartId` identifies the cart being checked out; the same ID is used for the payment authorisation and the order that follow.
|
|
12
|
+
- `customerId` is included because the customer is signed in, so the reservation can be traced back to them.
|
|
13
|
+
- `items` holds one entry per product: 2 Classic White T-shirts and 1 Logo Cap, each identified by its `productId`.
|
|
14
|
+
- Every `quantity` is a whole number of at least 1.
|
|
15
|
+
|
|
16
|
+
In total, **3 units** across **2 products** are reserved.
|
|
17
|
+
|
|
18
|
+
### Using this example
|
|
19
|
+
|
|
20
|
+
The inventory handler should hold 2 T-shirts and 1 cap against this `cartId` and reply with a successful reservation. Release the hold if the saga later compensates.
|
|
21
|
+
|
|
22
|
+
The examples use a **fictional Acme Events SDK** to send a payload matching the ReserveInventory schema. The package names and send methods are illustrative.
|
|
23
|
+
|
|
24
|
+
</Column>
|
|
25
|
+
|
|
26
|
+
<Column>
|
|
27
|
+
|
|
28
|
+
<CodeGroup dropdown>
|
|
29
|
+
|
|
30
|
+
```typescript send-reserve-inventory.ts
|
|
31
|
+
import { EventsClient } from '@acme/events';
|
|
32
|
+
import type { ReserveInventory } from './schemas/reserve-inventory';
|
|
33
|
+
|
|
34
|
+
const client = new EventsClient({
|
|
35
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const command: ReserveInventory = {
|
|
39
|
+
cartId: 'c1a2b3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d',
|
|
40
|
+
customerId: '3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d',
|
|
41
|
+
items: [
|
|
42
|
+
{
|
|
43
|
+
productId: '5e8f2a1b-3c4d-4e5f-8a6b-7c8d9e0f1a2b',
|
|
44
|
+
quantity: 2,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
productId: '6f9a3b2c-4d5e-4f6a-9b7c-8d9e0f1a2b3c',
|
|
48
|
+
quantity: 1,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
await client.send('ReserveInventory', command);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```python send_reserve_inventory.py
|
|
57
|
+
import os
|
|
58
|
+
from acme_events import EventsClient
|
|
59
|
+
|
|
60
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
61
|
+
|
|
62
|
+
command = {
|
|
63
|
+
"cartId": "c1a2b3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
|
|
64
|
+
"customerId": "3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d",
|
|
65
|
+
"items": [
|
|
66
|
+
{
|
|
67
|
+
"productId": "5e8f2a1b-3c4d-4e5f-8a6b-7c8d9e0f1a2b",
|
|
68
|
+
"quantity": 2,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"productId": "6f9a3b2c-4d5e-4f6a-9b7c-8d9e0f1a2b3c",
|
|
72
|
+
"quantity": 1,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
client.send("ReserveInventory", command)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```java SendReserveInventory.java
|
|
81
|
+
import com.acme.events.EventsClient;
|
|
82
|
+
import java.util.List;
|
|
83
|
+
import java.util.Map;
|
|
84
|
+
|
|
85
|
+
public class SendReserveInventory {
|
|
86
|
+
public static void main(String[] args) {
|
|
87
|
+
var client = new EventsClient(
|
|
88
|
+
System.getenv("ACME_API_KEY")
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
var command = Map.of(
|
|
92
|
+
"cartId", "c1a2b3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
|
|
93
|
+
"customerId", "3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d",
|
|
94
|
+
"items", List.of(
|
|
95
|
+
Map.of(
|
|
96
|
+
"productId", "5e8f2a1b-3c4d-4e5f-8a6b-7c8d9e0f1a2b",
|
|
97
|
+
"quantity", 2
|
|
98
|
+
),
|
|
99
|
+
Map.of(
|
|
100
|
+
"productId", "6f9a3b2c-4d5e-4f6a-9b7c-8d9e0f1a2b3c",
|
|
101
|
+
"quantity", 1
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
client.send("ReserveInventory", command);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
</CodeGroup>
|
|
112
|
+
|
|
113
|
+
</Column>
|
|
114
|
+
|
|
115
|
+
</Columns>
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
<Columns cols={2}>
|
|
120
|
+
|
|
121
|
+
<Column>
|
|
122
|
+
|
|
123
|
+
## 2. Reserve a single item with only the required fields
|
|
124
|
+
|
|
125
|
+
A cart holds one hoodie and the orchestrator has no customer to attach. It sends the smallest valid command: the cart and its items.
|
|
126
|
+
|
|
127
|
+
### Payload details
|
|
128
|
+
|
|
129
|
+
- `cartId` is the only identifier sent; the optional `customerId` is omitted.
|
|
130
|
+
- `items` holds a single entry: 1 Heavyweight Hoodie.
|
|
131
|
+
- `productId` and `quantity` are both required for every item.
|
|
132
|
+
|
|
133
|
+
### Using this example
|
|
134
|
+
|
|
135
|
+
Use this to check that the inventory handler accepts a reservation without a `customerId` and keys the hold on `cartId` alone.
|
|
136
|
+
|
|
137
|
+
The examples use a **fictional Acme Events SDK** to send a payload matching the ReserveInventory schema. The package names and send methods are illustrative.
|
|
138
|
+
|
|
139
|
+
</Column>
|
|
140
|
+
|
|
141
|
+
<Column>
|
|
142
|
+
|
|
143
|
+
<CodeGroup dropdown>
|
|
144
|
+
|
|
145
|
+
```typescript send-reserve-inventory.ts
|
|
146
|
+
import { EventsClient } from '@acme/events';
|
|
147
|
+
import type { ReserveInventory } from './schemas/reserve-inventory';
|
|
148
|
+
|
|
149
|
+
const client = new EventsClient({
|
|
150
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const command: ReserveInventory = {
|
|
154
|
+
cartId: 'd2b3c4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e',
|
|
155
|
+
items: [
|
|
156
|
+
{
|
|
157
|
+
productId: '7a0b4c3d-5e6f-4a7b-8c8d-9e0f1a2b3c4d',
|
|
158
|
+
quantity: 1,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
await client.send('ReserveInventory', command);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
```python send_reserve_inventory.py
|
|
167
|
+
import os
|
|
168
|
+
from acme_events import EventsClient
|
|
169
|
+
|
|
170
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
171
|
+
|
|
172
|
+
command = {
|
|
173
|
+
"cartId": "d2b3c4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",
|
|
174
|
+
"items": [
|
|
175
|
+
{
|
|
176
|
+
"productId": "7a0b4c3d-5e6f-4a7b-8c8d-9e0f1a2b3c4d",
|
|
177
|
+
"quantity": 1,
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
client.send("ReserveInventory", command)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
```java SendReserveInventory.java
|
|
186
|
+
import com.acme.events.EventsClient;
|
|
187
|
+
import java.util.List;
|
|
188
|
+
import java.util.Map;
|
|
189
|
+
|
|
190
|
+
public class SendReserveInventory {
|
|
191
|
+
public static void main(String[] args) {
|
|
192
|
+
var client = new EventsClient(
|
|
193
|
+
System.getenv("ACME_API_KEY")
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
var command = Map.of(
|
|
197
|
+
"cartId", "d2b3c4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",
|
|
198
|
+
"items", List.of(
|
|
199
|
+
Map.of(
|
|
200
|
+
"productId", "7a0b4c3d-5e6f-4a7b-8c8d-9e0f1a2b3c4d",
|
|
201
|
+
"quantity", 1
|
|
202
|
+
)
|
|
203
|
+
)
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
client.send("ReserveInventory", command);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
</CodeGroup>
|
|
212
|
+
|
|
213
|
+
</Column>
|
|
214
|
+
|
|
215
|
+
</Columns>
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
<Columns cols={2}>
|
|
2
|
+
|
|
3
|
+
<Column>
|
|
4
|
+
|
|
5
|
+
## 1. Cancel an order at the customer's request
|
|
6
|
+
|
|
7
|
+
Shortly after ordering a hoodie and two caps, the customer changes their mind and cancels from their account page. The storefront sends this command to the Order Service.
|
|
8
|
+
|
|
9
|
+
### Payload details
|
|
10
|
+
|
|
11
|
+
- `orderId` identifies the order to cancel; it must not be completed yet.
|
|
12
|
+
- `reason` is `CUSTOMER_REQUESTED`, the customer's own choice.
|
|
13
|
+
|
|
14
|
+
### Using this example
|
|
15
|
+
|
|
16
|
+
The Order Service should release the reserved stock, void the payment authorisation and publish `OrderCancelled` with the same `orderId` and `reason`.
|
|
17
|
+
|
|
18
|
+
The examples use a **fictional Acme Events SDK** to send a payload matching the CancelOrder schema. The package names and send methods are illustrative.
|
|
19
|
+
|
|
20
|
+
</Column>
|
|
21
|
+
|
|
22
|
+
<Column>
|
|
23
|
+
|
|
24
|
+
<CodeGroup dropdown>
|
|
25
|
+
|
|
26
|
+
```typescript send-cancel-order.ts
|
|
27
|
+
import { EventsClient } from '@acme/events';
|
|
28
|
+
import type { CancelOrder } from './schemas/cancel-order';
|
|
29
|
+
|
|
30
|
+
const client = new EventsClient({
|
|
31
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const command: CancelOrder = {
|
|
35
|
+
orderId: 'e3f4a5b6-7c8d-4e9f-a0b1-c2d3e4f5a6b7',
|
|
36
|
+
reason: 'CUSTOMER_REQUESTED',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
await client.send('CancelOrder', command);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```python send_cancel_order.py
|
|
43
|
+
import os
|
|
44
|
+
from acme_events import EventsClient
|
|
45
|
+
|
|
46
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
47
|
+
|
|
48
|
+
command = {
|
|
49
|
+
"orderId": "e3f4a5b6-7c8d-4e9f-a0b1-c2d3e4f5a6b7",
|
|
50
|
+
"reason": "CUSTOMER_REQUESTED",
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
client.send("CancelOrder", command)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```java SendCancelOrder.java
|
|
57
|
+
import com.acme.events.EventsClient;
|
|
58
|
+
import java.util.Map;
|
|
59
|
+
|
|
60
|
+
public class SendCancelOrder {
|
|
61
|
+
public static void main(String[] args) {
|
|
62
|
+
var client = new EventsClient(
|
|
63
|
+
System.getenv("ACME_API_KEY")
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
var command = Map.of(
|
|
67
|
+
"orderId", "e3f4a5b6-7c8d-4e9f-a0b1-c2d3e4f5a6b7",
|
|
68
|
+
"reason", "CUSTOMER_REQUESTED"
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
client.send("CancelOrder", command);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
</CodeGroup>
|
|
77
|
+
|
|
78
|
+
</Column>
|
|
79
|
+
|
|
80
|
+
</Columns>
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
<Columns cols={2}>
|
|
85
|
+
|
|
86
|
+
<Column>
|
|
87
|
+
|
|
88
|
+
## 2. Cancel an order flagged as fraud
|
|
89
|
+
|
|
90
|
+
The fraud team reviews a suspicious order and blocks it before it ships. Their tooling sends this command so the order never reaches fulfilment.
|
|
91
|
+
|
|
92
|
+
### Payload details
|
|
93
|
+
|
|
94
|
+
- `orderId` identifies the flagged order.
|
|
95
|
+
- `reason` is `FRAUD`, which downstream systems can use to skip customer notifications and refund flows.
|
|
96
|
+
|
|
97
|
+
### Using this example
|
|
98
|
+
|
|
99
|
+
Use this to check that the handler accepts the `FRAUD` reason and that the resulting `OrderCancelled` event carries it unchanged.
|
|
100
|
+
|
|
101
|
+
The examples use a **fictional Acme Events SDK** to send a payload matching the CancelOrder schema. The package names and send methods are illustrative.
|
|
102
|
+
|
|
103
|
+
</Column>
|
|
104
|
+
|
|
105
|
+
<Column>
|
|
106
|
+
|
|
107
|
+
<CodeGroup dropdown>
|
|
108
|
+
|
|
109
|
+
```typescript send-cancel-order.ts
|
|
110
|
+
import { EventsClient } from '@acme/events';
|
|
111
|
+
import type { CancelOrder } from './schemas/cancel-order';
|
|
112
|
+
|
|
113
|
+
const client = new EventsClient({
|
|
114
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const command: CancelOrder = {
|
|
118
|
+
orderId: 'a6b7c8d9-0e1f-4a2b-8c3d-e4f5a6b7c8d9',
|
|
119
|
+
reason: 'FRAUD',
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
await client.send('CancelOrder', command);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```python send_cancel_order.py
|
|
126
|
+
import os
|
|
127
|
+
from acme_events import EventsClient
|
|
128
|
+
|
|
129
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
130
|
+
|
|
131
|
+
command = {
|
|
132
|
+
"orderId": "a6b7c8d9-0e1f-4a2b-8c3d-e4f5a6b7c8d9",
|
|
133
|
+
"reason": "FRAUD",
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
client.send("CancelOrder", command)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```java SendCancelOrder.java
|
|
140
|
+
import com.acme.events.EventsClient;
|
|
141
|
+
import java.util.Map;
|
|
142
|
+
|
|
143
|
+
public class SendCancelOrder {
|
|
144
|
+
public static void main(String[] args) {
|
|
145
|
+
var client = new EventsClient(
|
|
146
|
+
System.getenv("ACME_API_KEY")
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
var command = Map.of(
|
|
150
|
+
"orderId", "a6b7c8d9-0e1f-4a2b-8c3d-e4f5a6b7c8d9",
|
|
151
|
+
"reason", "FRAUD"
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
client.send("CancelOrder", command);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
</CodeGroup>
|
|
160
|
+
|
|
161
|
+
</Column>
|
|
162
|
+
|
|
163
|
+
</Columns>
|