@newhomestar/sdk 0.8.10 → 0.8.11

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/dist/events.d.ts CHANGED
@@ -1,14 +1,18 @@
1
1
  /**
2
2
  * Register a Zod payload schema for emit-time validation.
3
3
  * Called by `novaEndpoint()` in next.ts for each event that has a `payload` field.
4
+ * The key is normalized so both slug format ('TICKET_CREATED') and topic format
5
+ * ('ticket.created') resolve to the same canonical key.
4
6
  * @internal
5
7
  */
6
8
  export declare function registerEventPayloadSchema(slug: string, schema: {
7
9
  safeParse: (data: unknown) => any;
8
10
  }): void;
9
11
  /**
10
- * Look up a registered payload schema by event slug.
12
+ * Look up a registered payload schema by event slug or topic.
11
13
  * Returns `undefined` if no schema was registered (validation is skipped).
14
+ * The key is normalized so both slug format ('TICKET_CREATED') and topic format
15
+ * ('ticket.created') resolve to the same canonical key.
12
16
  * @internal
13
17
  */
14
18
  export declare function getEventPayloadSchema(slug: string): {
package/dist/events.js CHANGED
@@ -48,21 +48,47 @@ if (!process.env.NOVA_EVENTS_SERVICE_URL) {
48
48
  // `.safeParse()` on whatever object was registered (duck-typed).
49
49
  /** @internal */
50
50
  const _eventPayloadSchemas = new Map();
51
+ /**
52
+ * Normalize an event key to the canonical `entity.action` format so that
53
+ * registration (slug: 'TICKET_CREATED') and lookup (topic: 'ticket.created')
54
+ * always resolve to the same map key.
55
+ *
56
+ * Conversions:
57
+ * 'TICKET_CREATED' → 'ticket.created'
58
+ * 'ticket.created' → 'ticket.created' (no-op)
59
+ * 'COMMENT_CREATED' → 'comment.created'
60
+ *
61
+ * @internal
62
+ */
63
+ function normalizeEventKey(key) {
64
+ // Already in dot-separated topic format
65
+ if (key.includes('.'))
66
+ return key.toLowerCase();
67
+ // SLUG format (ENTITY_ACTION): split on the last underscore → entity.action
68
+ const idx = key.lastIndexOf('_');
69
+ if (idx === -1)
70
+ return key.toLowerCase();
71
+ return `${key.slice(0, idx)}.${key.slice(idx + 1)}`.toLowerCase();
72
+ }
51
73
  /**
52
74
  * Register a Zod payload schema for emit-time validation.
53
75
  * Called by `novaEndpoint()` in next.ts for each event that has a `payload` field.
76
+ * The key is normalized so both slug format ('TICKET_CREATED') and topic format
77
+ * ('ticket.created') resolve to the same canonical key.
54
78
  * @internal
55
79
  */
56
80
  export function registerEventPayloadSchema(slug, schema) {
57
- _eventPayloadSchemas.set(slug, schema);
81
+ _eventPayloadSchemas.set(normalizeEventKey(slug), schema);
58
82
  }
59
83
  /**
60
- * Look up a registered payload schema by event slug.
84
+ * Look up a registered payload schema by event slug or topic.
61
85
  * Returns `undefined` if no schema was registered (validation is skipped).
86
+ * The key is normalized so both slug format ('TICKET_CREATED') and topic format
87
+ * ('ticket.created') resolve to the same canonical key.
62
88
  * @internal
63
89
  */
64
90
  export function getEventPayloadSchema(slug) {
65
- return _eventPayloadSchemas.get(slug);
91
+ return _eventPayloadSchemas.get(normalizeEventKey(slug));
66
92
  }
67
93
  // ── Internal helpers ───────────────────────────────────────────────────────────
68
94
  function _getEnvOrThrow(key, context) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newhomestar/sdk",
3
- "version": "0.8.10",
3
+ "version": "0.8.11",
4
4
  "description": "Type-safe SDK for building Nova pipelines (workers & functions)",
5
5
  "homepage": "https://github.com/newhomestar/nova-node-sdk#readme",
6
6
  "bugs": {