@crossdelta/cloudevents 0.1.1 → 0.1.3

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 (2) hide show
  1. package/README.md +37 -67
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,30 +1,37 @@
1
- # Orderboss CloudEvents Toolkit
1
+ # @crossdelta/cloudevents
2
2
 
3
- [![Architecture](https://img.shields.io/badge/architecture-arc42-blue?style=flat-square&logo=gitbook)](docs/architecture.md)
4
-
5
- CloudEvents middleware, publishers, and consumers that integrate cleanly with [Hono](https://hono.dev/). Ship handler discovery, DLQ-safe processing for Google Pub/Sub & Eventarc, and NATS utilities without wiring everything yourself.
3
+ CloudEvents toolkit for TypeScript. Handler discovery, DLQ-safe processing, NATS streaming, and optional Hono middleware.
6
4
 
7
5
  ## Features
8
6
 
9
- - Automatic handler discovery for `*.event.(ts|js)` files with caching
10
- - CloudEvents parsing for structured, binary, Pub/Sub push, and raw payloads
11
- - DLQ-safe mode that quarantines invalid messages and reports recoverable errors
12
- - First-class Zod support with optional safe-parse fallback
13
- - Shared tooling for Google Pub/Sub and NATS (publish & consume)
7
+ - Automatic handler discovery for `*.event.(ts|js)` files
8
+ - CloudEvents parsing (structured, binary, Pub/Sub push, raw)
9
+ - DLQ-safe mode with quarantine for invalid messages
10
+ - Zod validation with optional safe-parse fallback
11
+ - NATS publish & consume support
12
+ - Google Pub/Sub support (optional dependency)
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ bun add @crossdelta/cloudevents
18
+ ```
14
19
 
15
- ## Getting started
20
+ ### Optional: Google Pub/Sub
16
21
 
17
- ### 1. Install the package
22
+ For Pub/Sub publishing, install the optional dependency:
18
23
 
19
24
  ```bash
20
- bun add @orderboss/cloudevents
25
+ bun add @google-cloud/pubsub
21
26
  ```
22
27
 
23
- ### 2. Define a typed event handler
28
+ ## Quick Start
29
+
30
+ ### Define a handler
24
31
 
25
32
  ```typescript
26
33
  import { z } from 'zod'
27
- import { eventSchema, handleEvent } from '@orderboss/cloudevents'
34
+ import { eventSchema, handleEvent } from '@crossdelta/cloudevents'
28
35
 
29
36
  const CustomerCreatedSchema = eventSchema({
30
37
  type: z.literal('customer.created'),
@@ -39,87 +46,50 @@ export const CustomerCreatedHandler = handleEvent(CustomerCreatedSchema, async (
39
46
  })
40
47
  ```
41
48
 
42
- > Need a softer failure mode? Set `CustomerCreatedHandler.__eventarcMetadata.safeParse = true` before registering it to skip invalid payloads in favour of quarantine logs.
43
-
44
- ### 3. Register the middleware in Hono
49
+ ### Register middleware
45
50
 
46
51
  ```typescript
47
52
  import { Hono } from 'hono'
48
- import { cloudEvents } from '@orderboss/cloudevents'
53
+ import { cloudEvents } from '@crossdelta/cloudevents'
49
54
 
50
55
  const app = new Hono()
51
56
 
52
57
  app.use('/events', cloudEvents({
53
58
  discover: 'src/events/**/*.event.{ts,js}',
54
- quarantineTopic: process.env.QUARANTINE_TOPIC,
55
- errorTopic: process.env.ERROR_TOPIC,
56
- projectId: process.env.GCP_PROJECT_ID,
57
- log: process.env.NODE_ENV === 'production' ? 'structured' : 'pretty',
58
59
  }))
59
60
  ```
60
61
 
61
- DLQ-safe mode activates automatically when `quarantineTopic` or `errorTopic` is provided.
62
-
63
- ## Publishing events
62
+ ## Publishing
64
63
 
65
64
  ```typescript
66
- import {
67
- publishEvent,
68
- publishRawEvent,
69
- publishNatsEvent,
70
- publishNatsRawEvent,
71
- } from '@orderboss/cloudevents'
72
-
73
- // Google Pub/Sub
74
- await publishEvent('customer-events', CustomerCreatedSchema, {
75
- payload: { id: 'cust_1', email: 'jane@example.com' },
76
- })
65
+ import { publishNatsEvent } from '@crossdelta/cloudevents'
77
66
 
78
- await publishRawEvent('customer-events', 'customer.deleted', { id: 'cust_1' }, {
79
- source: 'orderboss://customers',
80
- projectId: 'my-project',
81
- })
82
-
83
- // NATS Streaming (reuse the schema you defined for your handler)
84
67
  await publishNatsEvent('orders.placed', OrderPlacedSchema, {
85
68
  payload: { id: 'ord_42', total: 149.9 },
86
69
  })
87
-
88
- await publishNatsRawEvent('orders.canceled', 'order.canceled', { id: 'ord_42' }, {
89
- servers: process.env.NATS_URL,
90
- })
91
70
  ```
92
71
 
93
72
  ## Consuming from NATS
94
73
 
95
74
  ```typescript
96
- import { consumeNatsEvents } from '@orderboss/cloudevents/transports/nats'
75
+ import { consumeNatsEvents } from '@crossdelta/cloudevents/transports/nats'
97
76
 
98
77
  await consumeNatsEvents({
99
78
  servers: process.env.NATS_URL,
100
79
  subject: 'orders.placed',
101
80
  discover: 'dist/events/*.event.js',
102
81
  consumerName: 'orders-api',
103
- quarantineTopic: 'projects/my-app/topics/nats-quarantine',
104
- errorTopic: 'projects/my-app/topics/nats-errors',
105
82
  })
106
83
  ```
107
84
 
108
- The consumer reuses your handler definitions, honours `safeParse`, and mirrors the DLQ-safe behaviour of the middleware.
109
-
110
- ## API surface
111
-
112
- - `cloudEvents(options)` Hono middleware with discovery, dedupe, and DLQ-safe semantics
113
- - `clearHandlerCache()` resets the discovery cache (tests, hot reload)
114
- - `eventSchema(schema)` wraps a Zod object that includes a `type` literal
115
- - `handleEvent(schemaOrOptions, handler)` builds discovery-ready handler classes
116
- - `parseEventFromContext(ctx)` normalises incoming CloudEvents for manual flows
117
- - `publishEvent` / `publishRawEvent` publish to Google Pub/Sub
118
- - `publishNatsEvent` / `publishNatsRawEvent` publish to NATS subjects
119
- - `consumeNatsEvents` – subscribe to NATS and execute discovered handlers
120
-
121
- ## Further reading
122
-
123
- - [Architecture notes](docs/architecture.md)
124
- - Examples in `packages/cloudevents/test`
125
- - Project changelog in the repository root
85
+ ## API
86
+
87
+ | Function | Description |
88
+ |----------|-------------|
89
+ | `cloudEvents(options)` | Hono middleware with discovery and DLQ-safe semantics |
90
+ | `eventSchema(schema)` | Wraps a Zod schema with `type` literal |
91
+ | `handleEvent(schema, handler)` | Creates discovery-ready handler |
92
+ | `publishNatsEvent` / `publishNatsRawEvent` | Publish to NATS |
93
+ | `publishEvent` / `publishRawEvent` | Publish to Google Pub/Sub (requires optional dep) |
94
+ | `consumeNatsEvents` | Subscribe to NATS and execute handlers |
95
+ | `clearHandlerCache()` | Reset discovery cache |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crossdelta/cloudevents",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",