@newhomestar/sdk 0.4.1 → 0.4.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 CHANGED
@@ -1,5 +1,4 @@
1
1
  import { z, ZodTypeAny } from "zod";
2
- import type { IncomingMessage, ServerResponse } from "node:http";
3
2
  export interface ActionDef<I extends ZodTypeAny, O extends ZodTypeAny> {
4
3
  name: string;
5
4
  input: I;
@@ -46,18 +45,10 @@ export declare function defineWorker<T extends WorkerDef>(def: T): T;
46
45
  export declare function enqueue<P extends object>(actionPath: `${string}.${string}`, payload: P): Promise<{
47
46
  job_id: string;
48
47
  }>;
49
- /**
50
- * Create an oRPC router from a WorkerDef, mapping each action to an oRPC procedure
51
- */
52
- export declare function createORPCRouter<T extends WorkerDef>(def: T): Record<string, any>;
53
48
  export interface ORPCServerOptions {
54
49
  port?: number;
55
50
  plugins?: any[];
56
51
  }
57
- /**
58
- * Run an oRPC server with OpenAPI support - replaces runTRPCServer
59
- */
60
- export declare function runORPCServer<T extends WorkerDef>(def: T, options?: ORPCServerOptions): import("http").Server<typeof IncomingMessage, typeof ServerResponse>;
61
52
  export declare function runWorker(def: WorkerDef): Promise<void>;
62
53
  export declare function generateOpenAPISpec<T extends WorkerDef>(def: T): Promise<{
63
54
  openapi: string;
package/dist/index.js CHANGED
@@ -7,34 +7,12 @@ exports.parseNovaSpec = void 0;
7
7
  exports.action = action;
8
8
  exports.defineWorker = defineWorker;
9
9
  exports.enqueue = enqueue;
10
- exports.createORPCRouter = createORPCRouter;
11
- exports.runORPCServer = runORPCServer;
12
10
  exports.runWorker = runWorker;
13
11
  exports.generateOpenAPISpec = generateOpenAPISpec;
14
12
  exports.runHttpServer = runHttpServer;
15
13
  const dotenv_1 = __importDefault(require("dotenv"));
16
14
  const supabase_js_1 = require("@supabase/supabase-js");
17
15
  const sdk_1 = require("@openfga/sdk");
18
- // TODO: Install oRPC dependencies
19
- // import { os } from "@orpc/server";
20
- // import { OpenAPIHandler } from "@orpc/openapi/node";
21
- // Temporary stubs for oRPC until dependencies are installed
22
- const os = {
23
- route: (config) => ({
24
- input: (schema) => ({
25
- output: (schema) => ({
26
- handler: (handler) => ({ _route: config, _input: schema, _output: schema, _handler: handler })
27
- })
28
- })
29
- })
30
- };
31
- const OpenAPIHandler = class {
32
- constructor(router, options) { }
33
- async handle(req, res, context) {
34
- return { matched: false };
35
- }
36
- };
37
- const node_http_1 = require("node:http");
38
16
  if (!process.env.RUNTIME_SUPABASE_URL) {
39
17
  // local dev – read .env.local
40
18
  dotenv_1.default.config({ path: ".env.local", override: true });
@@ -78,76 +56,6 @@ async function enqueue(actionPath, payload) {
78
56
  throw error;
79
57
  return data;
80
58
  }
81
- /*──────────────── NEW: oRPC Router Creation ───────────────*/
82
- /**
83
- * Create an oRPC router from a WorkerDef, mapping each action to an oRPC procedure
84
- */
85
- function createORPCRouter(def) {
86
- const procedures = {};
87
- for (const [actionName, actionDef] of Object.entries(def.actions)) {
88
- const method = actionDef.method || 'POST';
89
- const path = actionDef.path || `/${actionName}`;
90
- // Create oRPC procedure with route information
91
- const procedure = os
92
- .route({ method, path })
93
- .input(actionDef.input)
94
- .output(actionDef.output)
95
- .handler(async ({ input, context }) => {
96
- const ctx = {
97
- jobId: context?.jobId || `orpc-${Date.now()}`,
98
- progress: (percent, meta) => {
99
- console.log(`[${actionName}] Progress: ${percent}%`, meta);
100
- }
101
- };
102
- return await actionDef.handler(input, ctx);
103
- });
104
- procedures[actionName] = procedure;
105
- }
106
- return procedures;
107
- }
108
- /**
109
- * Run an oRPC server with OpenAPI support - replaces runTRPCServer
110
- */
111
- function runORPCServer(def, options = {}) {
112
- const router = createORPCRouter(def);
113
- const handler = new OpenAPIHandler(router, {
114
- plugins: options.plugins || []
115
- });
116
- const server = (0, node_http_1.createServer)(async (req, res) => {
117
- try {
118
- const result = await handler.handle(req, res, {
119
- context: {
120
- worker: def,
121
- queue: def.queue,
122
- jobId: `http-${Date.now()}`
123
- }
124
- });
125
- if (!result.matched) {
126
- res.statusCode = 404;
127
- res.setHeader('Content-Type', 'application/json');
128
- res.end(JSON.stringify({ error: 'No procedure matched' }));
129
- }
130
- }
131
- catch (error) {
132
- console.error('[oRPC Server Error]:', error);
133
- res.statusCode = 500;
134
- res.setHeader('Content-Type', 'application/json');
135
- res.end(JSON.stringify({ error: 'Internal server error' }));
136
- }
137
- });
138
- const port = options.port ?? (process.env.PORT ? parseInt(process.env.PORT) : 3000);
139
- server.listen(port, () => {
140
- console.log(`[nova] oRPC server "${def.name}" listening on http://localhost:${port}`);
141
- console.log(`[nova] OpenAPI spec available at http://localhost:${port}/openapi.json`);
142
- // Log available endpoints
143
- Object.entries(def.actions).forEach(([actionName, actionDef]) => {
144
- const method = actionDef.method || 'POST';
145
- const path = actionDef.path || `/${actionName}`;
146
- console.log(`[nova] ${method} ${path} -> ${actionName}`);
147
- });
148
- });
149
- return server;
150
- }
151
59
  /*──────────────── Runtime harness (Supabase RPC) - UNCHANGED ───────────────*/
152
60
  const RUNTIME_SUPABASE_URL = process.env.RUNTIME_SUPABASE_URL;
153
61
  const RUNTIME_SUPABASE_KEY = process.env.RUNTIME_SUPABASE_SERVICE_ROLE_KEY;
@@ -324,7 +232,7 @@ function runHttpServer(def, opts = {}) {
324
232
  app.get('/health', handler);
325
233
  }
326
234
  }
327
- const port = opts.port ?? (process.env.PORT ? parseInt(process.env.PORT) : 3000);
235
+ const port = opts.port ?? (process.env.PORT ? parseInt(process.env.PORT) : 8000);
328
236
  app.listen(port, () => {
329
237
  console.log(`[nova] HTTP server listening on http://localhost:${port}`);
330
238
  Object.entries(def.actions).forEach(([actionName, actionDef]) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newhomestar/sdk",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
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": {
@@ -23,6 +23,8 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@openfga/sdk": "^0.9.0",
26
+ "@orpc/openapi": "1.7.4",
27
+ "@orpc/server": "1.7.4",
26
28
  "@supabase/supabase-js": "^2.39.0",
27
29
  "body-parser": "^1.20.2",
28
30
  "dotenv": "^16.4.3",