@cloudnux/local-cloud-provider 0.7.0 → 0.10.0

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.js CHANGED
@@ -1755,6 +1755,37 @@ function createLocalFunctionsService() {
1755
1755
  throw new Error(JSON.stringify(context.response.body));
1756
1756
  }
1757
1757
  return context.response.body;
1758
+ },
1759
+ createWebSocketRequest: (connectionId, event, data) => {
1760
+ const wsRequest = {
1761
+ connectionId,
1762
+ event,
1763
+ path: "",
1764
+ body: data
1765
+ };
1766
+ return [wsRequest];
1767
+ },
1768
+ buildWebSocketResponse: (context) => {
1769
+ if (context.response.status === "error") {
1770
+ throw new Error(JSON.stringify(context.response.body));
1771
+ }
1772
+ return context.response.body;
1773
+ }
1774
+ };
1775
+ }
1776
+
1777
+ // src/services/websocket.ts
1778
+ var _manager = null;
1779
+ function setWebSocketManager(manager) {
1780
+ _manager = manager;
1781
+ }
1782
+ function createLocalWebSocketService() {
1783
+ return {
1784
+ async sendToClient(connectionId, data) {
1785
+ if (!_manager) {
1786
+ throw new Error("WebSocket plugin not initialized");
1787
+ }
1788
+ return _manager.sendToClient(connectionId, data);
1758
1789
  }
1759
1790
  };
1760
1791
  }
@@ -1763,6 +1794,7 @@ function createLocalFunctionsService() {
1763
1794
  import Fastify from "fastify";
1764
1795
  import fastifyRawBody from "fastify-raw-body";
1765
1796
  import cors from "@fastify/cors";
1797
+ import fastifyPrintRoutes from "fastify-print-routes";
1766
1798
  function createRouter(options = {}) {
1767
1799
  const fastify = Fastify({
1768
1800
  maxParamLength: 1e3,
@@ -1773,6 +1805,10 @@ function createRouter(options = {}) {
1773
1805
  encoding: "utf8"
1774
1806
  });
1775
1807
  fastify.register(cors, {});
1808
+ fastify.register(fastifyPrintRoutes);
1809
+ fastify.addHook("onReady", () => {
1810
+ setWebSocketManager(fastify.websockets);
1811
+ });
1776
1812
  return fastify;
1777
1813
  }
1778
1814
 
@@ -1782,7 +1818,8 @@ var localCloudProvider = {
1782
1818
  createStorageService: createLocalStorageService,
1783
1819
  createLocationService: createLocalLocationService,
1784
1820
  createEventBrokerService: createLocalEventBrokerService,
1785
- createFunctionsService: createLocalFunctionsService
1821
+ createFunctionsService: createLocalFunctionsService,
1822
+ createWebSocketService: createLocalWebSocketService
1786
1823
  };
1787
1824
  export {
1788
1825
  createRouter,