@newhomestar/sdk 0.4.3 → 0.4.5
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 +3 -3
- package/dist/index.js +31 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z, type ZodTypeAny } from "zod";
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
3
|
export interface ActionDef<I extends ZodTypeAny, O extends ZodTypeAny> {
|
|
3
4
|
name: string;
|
|
4
5
|
input: I;
|
|
@@ -54,10 +55,9 @@ export interface ORPCServerOptions {
|
|
|
54
55
|
plugins?: any[];
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
57
|
-
* Run an oRPC server
|
|
58
|
-
* Note: Simplified version for ESM compatibility
|
|
58
|
+
* Run an official oRPC server - fully compliant with oRPC standards!
|
|
59
59
|
*/
|
|
60
|
-
export declare function runORPCServer<T extends WorkerDef>(def: T, options?: ORPCServerOptions):
|
|
60
|
+
export declare function runORPCServer<T extends WorkerDef>(def: T, options?: ORPCServerOptions): import("http").Server<typeof IncomingMessage, typeof ServerResponse>;
|
|
61
61
|
export declare function runWorker(def: WorkerDef): Promise<void>;
|
|
62
62
|
export declare function generateOpenAPISpec<T extends WorkerDef>(def: T): Promise<{
|
|
63
63
|
openapi: string;
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,8 @@ import { OpenFgaClient } from "@openfga/sdk";
|
|
|
13
13
|
import { createServer } from "node:http";
|
|
14
14
|
// Full oRPC imports now working with ESM
|
|
15
15
|
import { os } from "@orpc/server";
|
|
16
|
+
import { RPCHandler } from "@orpc/server/node";
|
|
17
|
+
import { CORSPlugin } from "@orpc/server/plugins";
|
|
16
18
|
import { OpenAPIHandler } from "@orpc/openapi/fetch";
|
|
17
19
|
if (!process.env.RUNTIME_SUPABASE_URL) {
|
|
18
20
|
// local dev – read .env.local
|
|
@@ -76,21 +78,43 @@ export function createORPCRouter(def) {
|
|
|
76
78
|
}
|
|
77
79
|
};
|
|
78
80
|
return await actionDef.handler(input, ctx);
|
|
79
|
-
})
|
|
81
|
+
})
|
|
82
|
+
.callable(); // Make the procedure callable like a regular function
|
|
80
83
|
procedures[actionName] = procedure;
|
|
81
84
|
}
|
|
82
85
|
return procedures;
|
|
83
86
|
}
|
|
84
87
|
/**
|
|
85
|
-
* Run an oRPC server
|
|
86
|
-
* Note: Simplified version for ESM compatibility
|
|
88
|
+
* Run an official oRPC server - fully compliant with oRPC standards!
|
|
87
89
|
*/
|
|
88
90
|
export function runORPCServer(def, options = {}) {
|
|
89
91
|
const router = createORPCRouter(def);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
console.log(`[nova] Starting official oRPC server "${def.name}"`);
|
|
93
|
+
// Use official oRPC serving pattern
|
|
94
|
+
const handler = new RPCHandler(router, {
|
|
95
|
+
plugins: [new CORSPlugin(), ...(options.plugins || [])]
|
|
96
|
+
});
|
|
97
|
+
const server = createServer(async (req, res) => {
|
|
98
|
+
const result = await handler.handle(req, res, {
|
|
99
|
+
context: {
|
|
100
|
+
headers: req.headers,
|
|
101
|
+
jobId: `orpc-${Date.now()}`,
|
|
102
|
+
// Add any other Nova-specific context
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
if (!result.matched) {
|
|
106
|
+
res.statusCode = 404;
|
|
107
|
+
res.end('No procedure matched');
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT) : 8000);
|
|
111
|
+
server.listen(port, () => {
|
|
112
|
+
console.log(`[nova] Official oRPC server listening on http://localhost:${port}`);
|
|
113
|
+
console.log(`[nova] Available procedures: ${Object.keys(def.actions).join(', ')}`);
|
|
114
|
+
console.log(`[nova] 🔥 RPC protocol: ACTIVE (not HTTP fallback)`);
|
|
115
|
+
console.log(`[nova] 🌐 CORS: Enabled via CORSPlugin`);
|
|
116
|
+
});
|
|
117
|
+
return server;
|
|
94
118
|
}
|
|
95
119
|
/*──────────────── Runtime harness (Supabase RPC) - UNCHANGED ───────────────*/
|
|
96
120
|
const RUNTIME_SUPABASE_URL = process.env.RUNTIME_SUPABASE_URL;
|
package/package.json
CHANGED