codehooks-js 1.3.12 → 1.3.13

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/README.md CHANGED
@@ -317,6 +317,5 @@ await conn.set('key', 'value', { ttl: 3600000 }); // 1 hour TTL
317
317
  5. **Real-time communication** via Server-Sent Events
318
318
  6. **Workflow engine** for complex step-based applications
319
319
  7. **Auto-generated CRUD APIs** with schema validation
320
- 8. **Template rendering** system
321
- 9. **Singleton pattern** for global application state
322
- 10. **Datastore** with MongoDB-like query syntax, key-value operations, and queue management
320
+ 8. **Datastore** with MongoDB-like query syntax, key-value operations, and queue management
321
+ 9. **Security & Authentication** with JWKS support and custom auth middleware for secure API endpoints
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {agg} from './aggregation/index.mjs';
2
2
  import {crudlify as crud} from './crudlify/index.mjs';
3
- import {serveStatic as ws, render as renderView} from './webserver.mjs';
3
+ import {serveStatic as ws, render as renderView, internalFetch} from './webserver.mjs';
4
4
  import Workflow from './workflow/engine.mjs';
5
5
 
6
6
  function createRoute(str) {
@@ -116,6 +116,10 @@ class Codehooks {
116
116
  res.status(200).json({...data});
117
117
  })
118
118
  }
119
+
120
+ internalFetch = (url, options = {}) => {
121
+ return internalFetch(url, options);
122
+ }
119
123
 
120
124
  createWorkflow = (name, description, steps, options={}) => {
121
125
  const wf = new Workflow(name, description, steps, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codehooks-js",
3
- "version": "1.3.12",
3
+ "version": "1.3.13",
4
4
  "type": "module",
5
5
  "description": "Codehooks.io official library - provides express.JS like syntax",
6
6
  "main": "index.js",
package/types/index.d.ts CHANGED
@@ -1048,6 +1048,13 @@ export class Codehooks {
1048
1048
  * @returns Promise with the registered workflow name
1049
1049
  */
1050
1050
  registerWorkflow: (name: string, description: string, steps: WorkflowDefinition) => Promise<string>;
1051
+ /**
1052
+ * Fetch data from another Codehooks API
1053
+ * @param url - URL to fetch from, e.g. http://myapi-ffee.codehooks.io/dev/api/myroute
1054
+ * @param options - Fetch options
1055
+ * @returns Promise with the fetched data
1056
+ */
1057
+ internalFetch: (url: string, options?: any) => Promise<any>;
1051
1058
  }
1052
1059
  declare const _coho: Codehooks;
1053
1060
 
package/webserver.mjs CHANGED
@@ -1,4 +1,6 @@
1
1
  import mime from 'mime';
2
+ import fetch from 'node-fetch';
3
+ import { URL } from 'url';
2
4
 
3
5
  // old and new style support
4
6
  function promisify(cb, fn) {
@@ -222,4 +224,30 @@ async function handlebars(viewFile, data, settings, cb) {
222
224
  console.error('Handle bars engine error:', err)
223
225
  cb(err);
224
226
  }
225
- }
227
+ }
228
+
229
+ // Generic fetch wrapper that routes through apigateway-service
230
+ export const internalFetch = (url, options = {}) => {
231
+ // Parse the original URL to extract domain and path
232
+
233
+ const urlObj = new URL(url);
234
+ const originalHost = urlObj.host;
235
+ const pathAndQuery = urlObj.pathname + urlObj.search;
236
+
237
+ // Replace domain with apigateway-service
238
+ const proxyUrl = `http://apigateway-service:8888${pathAndQuery}`;
239
+
240
+ // Merge headers with original host
241
+ const headers = {
242
+ ...options.headers,
243
+ 'host': originalHost
244
+ };
245
+
246
+ // Create new options with updated headers
247
+ const newOptions = {
248
+ ...options,
249
+ headers
250
+ };
251
+
252
+ return fetch(proxyUrl, newOptions);
253
+ };