@newhomestar/sdk 0.2.1 → 0.2.6

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
@@ -32,3 +32,9 @@ export declare function enqueue<P extends object>(actionPath: `${string}.${strin
32
32
  }>;
33
33
  export declare function runWorker(def: WorkerDef): Promise<void>;
34
34
  export type { ZodTypeAny as SchemaAny, ZodTypeAny };
35
+ /**
36
+ * Spin up an HTTP server exposing each action under POST /<worker>/<action>
37
+ */
38
+ export declare function runHttpServer(def: WorkerDef, opts?: {
39
+ port?: number;
40
+ }): void;
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ exports.action = action;
7
7
  exports.defineWorker = defineWorker;
8
8
  exports.enqueue = enqueue;
9
9
  exports.runWorker = runWorker;
10
+ exports.runHttpServer = runHttpServer;
10
11
  const dotenv_1 = __importDefault(require("dotenv"));
11
12
  const supabase_js_1 = require("@supabase/supabase-js");
12
13
  if (!process.env.RUNTIME_SUPABASE_URL) {
@@ -102,3 +103,32 @@ async function nack(id, q) {
102
103
  await runtime.schema("pgmq_public").rpc("nack", { queue_name: q, message_id: id });
103
104
  }
104
105
  function delay(ms) { return new Promise(r => setTimeout(r, ms)); }
106
+ //──────────────────── HTTP Server Harness ─────────────────────
107
+ const express_1 = __importDefault(require("express"));
108
+ const body_parser_1 = __importDefault(require("body-parser"));
109
+ /**
110
+ * Spin up an HTTP server exposing each action under POST /<worker>/<action>
111
+ */
112
+ function runHttpServer(def, opts = {}) {
113
+ const app = (0, express_1.default)();
114
+ app.use(body_parser_1.default.json());
115
+ for (const [actionName, act] of Object.entries(def.actions)) {
116
+ const route = `/${def.name}/${actionName}`;
117
+ app.post(route, async (req, res) => {
118
+ try {
119
+ const input = act.input.parse(req.body);
120
+ const ctx = { jobId: `http-${Date.now()}`, progress: () => { } };
121
+ const out = await act.handler(input, ctx);
122
+ act.output.parse(out);
123
+ res.json(out);
124
+ }
125
+ catch (err) {
126
+ res.status(400).json({ error: err.message });
127
+ }
128
+ });
129
+ }
130
+ const port = opts.port ?? (process.env.PORT ? parseInt(process.env.PORT) : 3000);
131
+ app.listen(port, () => {
132
+ console.log(`[nova] HTTP server listening on http://localhost:${port}`);
133
+ });
134
+ }
package/package.json CHANGED
@@ -1,33 +1,35 @@
1
- {
2
- "name": "@newhomestar/sdk",
3
- "version": "0.2.1",
4
- "description": "Type-safe SDK for building Nova pipelines (workers & functions)",
5
- "homepage": "https://github.com/newhomestar/nova-node-sdk#readme",
6
- "bugs": {
7
- "url": "https://github.com/newhomestar/nova-node-sdk/issues"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/newhomestar/nova-node-sdk.git"
12
- },
13
- "license": "ISC",
14
- "author": "Christian Gomez",
15
- "type": "commonjs",
16
- "main": "dist/index.js",
17
- "types": "dist/index.d.ts",
18
- "files": [
19
- "dist"
20
- ],
21
- "scripts": {
22
- "build": "tsc"
23
- },
24
- "dependencies": {
25
- "@supabase/supabase-js": "^2.39.0",
26
- "dotenv": "^16.4.3",
27
- "zod": "^3.23.8"
28
- },
29
- "devDependencies": {
30
- "typescript": "^5.4.4",
31
- "@types/node": "^20.11.17"
32
- }
33
- }
1
+ {
2
+ "name": "@newhomestar/sdk",
3
+ "version": "0.2.6",
4
+ "description": "Type-safe SDK for building Nova pipelines (workers & functions)",
5
+ "homepage": "https://github.com/newhomestar/nova-node-sdk#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/newhomestar/nova-node-sdk/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/newhomestar/nova-node-sdk.git"
12
+ },
13
+ "license": "ISC",
14
+ "author": "Christian Gomez",
15
+ "type": "commonjs",
16
+ "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc"
23
+ },
24
+ "dependencies": {
25
+ "@supabase/supabase-js": "^2.39.0",
26
+ "dotenv": "^16.4.3",
27
+ "zod": "^3.23.8",
28
+ "express": "^4.18.2",
29
+ "body-parser": "^1.20.2"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^20.11.17",
33
+ "typescript": "^5.4.4"
34
+ }
35
+ }