@newhomestar/sdk 0.4.8 → 0.5.0

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/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,9 +174,24 @@ 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
+ const { jobId, action: actName, payload, user_id, topic } = msg.message;
178
+ // Determine which action to run:
179
+ // 1. If action is explicitly specified, use it
180
+ // 2. If topic is specified, map topic to action
181
+ // 3. Otherwise, skip the message
182
+ let targetActionName = actName;
183
+ if (!targetActionName && topic) {
184
+ targetActionName = topicActionMap.get(topic);
185
+ console.log(`[nova] Topic-based routing: '${topic}' -> '${targetActionName || 'NOT_FOUND'}'`);
186
+ }
187
+ const act = targetActionName ? def.actions[targetActionName] : undefined;
150
188
  if (!act) {
189
+ console.warn(`[nova] No action found for message:`, {
190
+ action: actName,
191
+ topic,
192
+ targetAction: targetActionName,
193
+ availableActions: Object.keys(def.actions)
194
+ });
151
195
  await nack(msg.msg_id, def.queue);
152
196
  continue;
153
197
  }
@@ -58,7 +58,7 @@ export declare const WorkerDefSchema: z.ZodObject<{
58
58
  }, z.core.$strip>, z.ZodObject<{
59
59
  type: z.ZodLiteral<"scheduled">;
60
60
  cron: z.ZodString;
61
- timezone: z.ZodDefault<z.ZodString>;
61
+ timezone: z.ZodOptional<z.ZodString>;
62
62
  description: z.ZodOptional<z.ZodString>;
63
63
  }, z.core.$strip>, z.ZodObject<{
64
64
  type: z.ZodLiteral<"queue">;
@@ -49,7 +49,7 @@ export const WorkerDefSchema = z.object({
49
49
  z.object({
50
50
  type: z.literal('scheduled'),
51
51
  cron: z.string(),
52
- timezone: z.string().default('UTC'),
52
+ timezone: z.string().optional(),
53
53
  description: z.string().optional()
54
54
  }),
55
55
  z.object({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newhomestar/sdk",
3
- "version": "0.4.8",
3
+ "version": "0.5.0",
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": {