@newhomestar/sdk 0.8.10 → 0.8.12

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/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import dotenv from "dotenv";
2
+ import cors from "cors";
2
3
  import { createClient } from "@supabase/supabase-js";
3
4
  import { OpenFgaClient } from "@openfga/sdk";
4
5
  import { createServer } from "node:http";
@@ -648,6 +649,17 @@ import { auth } from "express-oauth2-jwt-bearer";
648
649
  */
649
650
  export function runHttpServer(def, opts = {}) {
650
651
  const app = express();
652
+ // ── CORS (must be registered BEFORE auth so OPTIONS preflight bypasses JWKS) ──
653
+ // Permissive by default — integrations are called by the Odyssey admin UI
654
+ // from browser origins (localhost:3000, admin dashboards, etc.). The actual
655
+ // security boundary is the JWT Bearer token verified by JWKS below.
656
+ app.use(cors({
657
+ origin: true, // reflect request origin
658
+ credentials: true,
659
+ methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
660
+ allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
661
+ maxAge: 86400,
662
+ }));
651
663
  app.use(bodyParser.json());
652
664
  // ── Determine whether auth is enabled ──
653
665
  const skipAuth = opts.skipAuth ??
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newhomestar/sdk",
3
- "version": "0.8.10",
3
+ "version": "0.8.12",
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": {
@@ -41,6 +41,7 @@
41
41
  "@orpc/server": "1.7.4",
42
42
  "@supabase/supabase-js": "^2.39.0",
43
43
  "body-parser": "^1.20.2",
44
+ "cors": "^2.8.6",
44
45
  "dotenv": "^16.4.3",
45
46
  "express": "^4.18.2",
46
47
  "express-oauth2-jwt-bearer": "^1.7.4",
@@ -51,6 +52,7 @@
51
52
  "zod": ">=4.0.0"
52
53
  },
53
54
  "devDependencies": {
55
+ "@types/cors": "^2.8.19",
54
56
  "@types/node": "^20.11.17",
55
57
  "typescript": "^5.4.4",
56
58
  "zod": "^4.3.0"