@newhomestar/sdk 0.5.0 → 0.5.2
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.d.ts +7 -0
- package/dist/index.js +48 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -126,6 +126,13 @@ export declare function generateOpenAPISpec<T extends WorkerDef>(def: T): Promis
|
|
|
126
126
|
export declare function runHttpServer<T extends WorkerDef>(def: T, opts?: {
|
|
127
127
|
port?: number;
|
|
128
128
|
}): void;
|
|
129
|
+
/**
|
|
130
|
+
* Run both HTTP server and queue consumer concurrently
|
|
131
|
+
* This gives you the best of both worlds: direct API access AND event processing
|
|
132
|
+
*/
|
|
133
|
+
export declare function runDualMode<T extends WorkerDef>(def: T, opts?: {
|
|
134
|
+
port?: number;
|
|
135
|
+
}): void;
|
|
129
136
|
export type { ZodTypeAny as SchemaAny, ZodTypeAny };
|
|
130
137
|
export { parseNovaSpec } from "./parseSpec.js";
|
|
131
138
|
export type { NovaSpec } from "./parseSpec.js";
|
package/dist/index.js
CHANGED
|
@@ -174,7 +174,17 @@ export async function runWorker(def) {
|
|
|
174
174
|
continue;
|
|
175
175
|
}
|
|
176
176
|
for (const msg of data) {
|
|
177
|
-
|
|
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
|
+
});
|
|
178
188
|
// Determine which action to run:
|
|
179
189
|
// 1. If action is explicitly specified, use it
|
|
180
190
|
// 2. If topic is specified, map topic to action
|
|
@@ -182,19 +192,29 @@ export async function runWorker(def) {
|
|
|
182
192
|
let targetActionName = actName;
|
|
183
193
|
if (!targetActionName && topic) {
|
|
184
194
|
targetActionName = topicActionMap.get(topic);
|
|
185
|
-
console.log(`[nova] Topic-based routing: '${topic}' -> '${targetActionName || 'NOT_FOUND'}'`);
|
|
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}'`);
|
|
186
203
|
}
|
|
187
204
|
const act = targetActionName ? def.actions[targetActionName] : undefined;
|
|
188
205
|
if (!act) {
|
|
189
|
-
console.
|
|
206
|
+
console.error(`[nova] ❌ No action handler found!`);
|
|
207
|
+
console.error(`[nova] 📋 Message analysis:`, {
|
|
190
208
|
action: actName,
|
|
191
209
|
topic,
|
|
192
210
|
targetAction: targetActionName,
|
|
193
|
-
availableActions: Object.keys(def.actions)
|
|
211
|
+
availableActions: Object.keys(def.actions),
|
|
212
|
+
topicMappings: Object.fromEntries(topicActionMap)
|
|
194
213
|
});
|
|
195
214
|
await nack(msg.msg_id, def.queue);
|
|
196
215
|
continue;
|
|
197
216
|
}
|
|
217
|
+
console.log(`[nova] 🚀 Executing action '${targetActionName}' for message ${msg.msg_id}`);
|
|
198
218
|
// FGA enforcement (unchanged from original)
|
|
199
219
|
const hints = act.fga ? (Array.isArray(act.fga) ? act.fga : [act.fga]) : [];
|
|
200
220
|
if (hints.length) {
|
|
@@ -346,5 +366,29 @@ export function runHttpServer(def, opts = {}) {
|
|
|
346
366
|
});
|
|
347
367
|
});
|
|
348
368
|
}
|
|
369
|
+
/*──────────────── Dual Mode: HTTP + Queue Consumer ───────────────*/
|
|
370
|
+
/**
|
|
371
|
+
* Run both HTTP server and queue consumer concurrently
|
|
372
|
+
* This gives you the best of both worlds: direct API access AND event processing
|
|
373
|
+
*/
|
|
374
|
+
export function runDualMode(def, opts = {}) {
|
|
375
|
+
console.log(`🚀 Worker "${def.name}" starting in DUAL MODE`);
|
|
376
|
+
console.log(`📡 HTTP API + 🎯 Event Queue Consumer`);
|
|
377
|
+
// Start HTTP server
|
|
378
|
+
runHttpServer(def, opts);
|
|
379
|
+
// Start queue consumer (if runtime env vars are available)
|
|
380
|
+
if (process.env.RUNTIME_SUPABASE_URL && process.env.RUNTIME_SUPABASE_KEY) {
|
|
381
|
+
console.log(`🎯 Starting queue consumer for events...`);
|
|
382
|
+
// Run queue consumer in background (don't await)
|
|
383
|
+
runWorker(def).catch((error) => {
|
|
384
|
+
console.error(`[nova] ❌ Queue consumer error:`, error);
|
|
385
|
+
console.error(`[nova] 💡 HTTP server continues running for direct API access`);
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
console.warn(`⚠️ RUNTIME_SUPABASE_* env vars not set - queue consumer disabled`);
|
|
390
|
+
console.log(`💡 Worker running in HTTP-only mode. Set RUNTIME_SUPABASE_URL and RUNTIME_SUPABASE_SERVICE_ROLE_KEY to enable event processing`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
349
393
|
// YAML spec parsing utility
|
|
350
394
|
export { parseNovaSpec } from "./parseSpec.js";
|
package/package.json
CHANGED