@newhomestar/sdk 0.4.9 → 0.5.1

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/dist/index.js +66 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -122,10 +122,39 @@ const RUNTIME_SUPABASE_KEY = process.env.RUNTIME_SUPABASE_SERVICE_ROLE_KEY;
122
122
  const runtime = RUNTIME_SUPABASE_URL && RUNTIME_SUPABASE_KEY
123
123
  ? createClient(RUNTIME_SUPABASE_URL, RUNTIME_SUPABASE_KEY)
124
124
  : undefined;
125
+ /**
126
+ * Build a topic-to-action mapping from worker capabilities
127
+ */
128
+ function buildTopicActionMap(def) {
129
+ const topicMap = new Map();
130
+ for (const [actionName, actionDef] of Object.entries(def.actions)) {
131
+ if (actionDef.capabilities) {
132
+ for (const capability of actionDef.capabilities) {
133
+ if (capability.type === 'queue' && capability.topics) {
134
+ for (const topic of capability.topics) {
135
+ topicMap.set(topic, actionName);
136
+ console.log(`[nova] Mapped topic '${topic}' -> action '${actionName}'`);
137
+ }
138
+ }
139
+ // Add other capability types as needed
140
+ if (capability.type === 'webhook' && capability.eventTypes) {
141
+ for (const eventType of capability.eventTypes) {
142
+ topicMap.set(eventType, actionName);
143
+ console.log(`[nova] Mapped webhook event '${eventType}' -> action '${actionName}'`);
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
149
+ return topicMap;
150
+ }
125
151
  export async function runWorker(def) {
126
152
  if (!runtime)
127
153
  throw new Error("RUNTIME_SUPABASE_* env vars not configured");
154
+ // Build topic-to-action mapping for capability-based routing
155
+ const topicActionMap = buildTopicActionMap(def);
128
156
  console.log(`[nova] worker '${def.name}' polling ${def.queue}`);
157
+ console.log(`[nova] Topic mappings:`, Object.fromEntries(topicActionMap));
129
158
  // infinite loop – use pgmq read RPC
130
159
  while (true) {
131
160
  const { data, error } = await runtime
@@ -145,12 +174,47 @@ export async function runWorker(def) {
145
174
  continue;
146
175
  }
147
176
  for (const msg of data) {
148
- const { jobId, action: actName, payload, user_id } = msg.message;
149
- const act = def.actions[actName];
177
+ console.log(`[nova] 🔍 Raw message received:`, JSON.stringify(msg, null, 2));
178
+ const { jobId, action: actName, payload, user_id, topic, ...otherFields } = msg.message;
179
+ console.log(`[nova] 📝 Message fields:`, {
180
+ jobId,
181
+ action: actName,
182
+ topic,
183
+ user_id,
184
+ payloadType: typeof payload,
185
+ payloadKeys: payload && typeof payload === 'object' ? Object.keys(payload) : 'N/A',
186
+ otherFields: Object.keys(otherFields)
187
+ });
188
+ // Determine which action to run:
189
+ // 1. If action is explicitly specified, use it
190
+ // 2. If topic is specified, map topic to action
191
+ // 3. Otherwise, skip the message
192
+ let targetActionName = actName;
193
+ if (!targetActionName && topic) {
194
+ targetActionName = topicActionMap.get(topic);
195
+ console.log(`[nova] 🎯 Topic-based routing: '${topic}' -> '${targetActionName || 'NOT_FOUND'}'`);
196
+ console.log(`[nova] 📋 Available topic mappings:`, Object.fromEntries(topicActionMap));
197
+ }
198
+ else if (!targetActionName) {
199
+ console.log(`[nova] ⚠️ No action or topic specified in message`);
200
+ }
201
+ else {
202
+ console.log(`[nova] ✅ Direct action specified: '${targetActionName}'`);
203
+ }
204
+ const act = targetActionName ? def.actions[targetActionName] : undefined;
150
205
  if (!act) {
206
+ console.error(`[nova] ❌ No action handler found!`);
207
+ console.error(`[nova] 📋 Message analysis:`, {
208
+ action: actName,
209
+ topic,
210
+ targetAction: targetActionName,
211
+ availableActions: Object.keys(def.actions),
212
+ topicMappings: Object.fromEntries(topicActionMap)
213
+ });
151
214
  await nack(msg.msg_id, def.queue);
152
215
  continue;
153
216
  }
217
+ console.log(`[nova] 🚀 Executing action '${targetActionName}' for message ${msg.msg_id}`);
154
218
  // FGA enforcement (unchanged from original)
155
219
  const hints = act.fga ? (Array.isArray(act.fga) ? act.fga : [act.fga]) : [];
156
220
  if (hints.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newhomestar/sdk",
3
- "version": "0.4.9",
3
+ "version": "0.5.1",
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": {