@crossdelta/platform-sdk 0.3.35 → 0.3.36

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.
@@ -62,16 +62,19 @@ Bun.serve({ port, fetch: app.fetch })
62
62
  ### Publishing Events
63
63
 
64
64
  ```ts
65
- import { publishNatsRawEvent } from '@crossdelta/cloudevents'
66
-
67
- await publishNatsRawEvent(
68
- 'orders.created', // NATS subject
69
- '{{projectName}}.orders.created', // CloudEvent type
70
- { orderId, customerId, total },
71
- { source: '{{projectName}}://orders-service', subject: orderId }
72
- )
65
+ import { publish } from '@crossdelta/cloudevents'
66
+
67
+ await publish('orders.created', { orderId, customerId, total }, {
68
+ source: '{{projectName}}://orders-service',
69
+ subject: orderId
70
+ })
73
71
  ```
74
72
 
73
+ The `publish` function automatically:
74
+ - Constructs the CloudEvent type from the subject (e.g., `orders.created` → `{{projectName}}.orders.created`)
75
+ - Adds required CloudEvent metadata (id, time, specversion, datacontenttype)
76
+ - Publishes to NATS JetStream
77
+
75
78
  ### Consuming Events (Auto-Discovery)
76
79
 
77
80
  Create handler files in `src/handlers/*.event.ts`:
@@ -80,13 +83,29 @@ Create handler files in `src/handlers/*.event.ts`:
80
83
  // services/notifications/src/handlers/order-created.event.ts
81
84
  import { handleEvent } from '@crossdelta/cloudevents'
82
85
  import { z } from 'zod'
86
+ import { sendNotification } from '../use-cases/send-notification.use-case'
87
+
88
+ const OrderCreatedSchema = z.object({
89
+ type: z.literal('orders.created'),
90
+ orderId: z.string(),
91
+ customerId: z.string(),
92
+ total: z.number(),
93
+ items: z.array(
94
+ z.object({
95
+ productId: z.string(),
96
+ quantity: z.number(),
97
+ price: z.number(),
98
+ }),
99
+ ).optional(),
100
+ })
83
101
 
84
- export default handleEvent(
85
- { type: '{{projectName}}.orders.created', schema: z.object({ orderId: z.string(), ... }) },
86
- async (data) => { /* data is fully typed */ }
87
- )
102
+ export default handleEvent(OrderCreatedSchema, async (data) => {
103
+ await sendNotification(data)
104
+ })
88
105
  ```
89
106
 
107
+ **Schema naming:** Use PascalCase for schema constants (e.g., `OrderCreatedSchema`, `UserUpdatedSchema`)
108
+
90
109
  ### Service Folder Structure
91
110
 
92
111
  Organize service code with this structure:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crossdelta/platform-sdk",
3
- "version": "0.3.35",
3
+ "version": "0.3.36",
4
4
  "description": "CLI toolkit for scaffolding Turborepo workspaces with Pulumi infrastructure and Hono/NestJS microservices",
5
5
  "keywords": [
6
6
  "cli",