monorise 1.1.0-dev.8 → 1.1.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.
Files changed (41) hide show
  1. package/dist/base/index.d.ts +54 -162
  2. package/dist/base/index.js +1 -51
  3. package/dist/base/index.js.map +1 -1
  4. package/dist/cli/cli.js +2 -8
  5. package/dist/cli/cli.js.map +1 -1
  6. package/dist/core/index.d.ts +60 -147
  7. package/dist/core/index.js +294 -1761
  8. package/dist/core/index.js.map +1 -1
  9. package/dist/react/actions/core.action.d.ts.map +1 -1
  10. package/dist/react/index.d.ts +4 -53
  11. package/dist/react/index.d.ts.map +1 -1
  12. package/dist/react/index.js +39 -586
  13. package/dist/react/index.js.map +1 -1
  14. package/dist/react/services/core.service.d.ts +1 -11
  15. package/dist/react/services/core.service.d.ts.map +1 -1
  16. package/dist/sst/components/monorise-core.d.ts +1 -12
  17. package/dist/sst/components/monorise-core.d.ts.map +1 -1
  18. package/dist/sst/components/single-table.d.ts +7 -1
  19. package/dist/sst/components/single-table.d.ts.map +1 -1
  20. package/dist/sst/index.js +16 -79
  21. package/dist/sst/index.js.map +1 -1
  22. package/package.json +6 -11
  23. package/dist/core/chunk-QV4Q5377.js +0 -76
  24. package/dist/core/chunk-QV4Q5377.js.map +0 -1
  25. package/dist/core/service.config-ZJEZ6EKA.js +0 -13
  26. package/dist/core/service.config-ZJEZ6EKA.js.map +0 -1
  27. package/dist/proxy/index.d.ts +0 -35
  28. package/dist/proxy/index.js +0 -75
  29. package/dist/proxy/index.js.map +0 -1
  30. package/dist/react/actions/websocket.action.d.ts +0 -71
  31. package/dist/react/actions/websocket.action.d.ts.map +0 -1
  32. package/dist/react/chunk-BIXAYYE4.js +0 -432
  33. package/dist/react/chunk-BIXAYYE4.js.map +0 -1
  34. package/dist/react/websocket/WebSocketManager.d.ts +0 -68
  35. package/dist/react/websocket/WebSocketManager.d.ts.map +0 -1
  36. package/dist/react/websocket/index.d.ts +0 -3
  37. package/dist/react/websocket/index.d.ts.map +0 -1
  38. package/dist/react/websocket/optimistic.d.ts +0 -51
  39. package/dist/react/websocket/optimistic.d.ts.map +0 -1
  40. package/dist/react/websocket-7MZ3ENOC.js +0 -9
  41. package/dist/react/websocket-7MZ3ENOC.js.map +0 -1
@@ -1,9 +1,34 @@
1
- import {
2
- WebSocketManager,
3
- __objRest,
4
- __spreadProps,
5
- __spreadValues
6
- } from "./chunk-BIXAYYE4.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
7
32
 
8
33
  // actions/app.action.ts
9
34
  import { produce } from "immer";
@@ -1430,16 +1455,11 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
1430
1455
  return () => queryTimeout && clearTimeout(queryTimeout);
1431
1456
  }, [entityType, query]);
1432
1457
  useEffect2(() => {
1433
- if (!query) {
1434
- const dataMapArray = Array.from(dataMap.values()).sort(
1435
- byEntityId
1458
+ if (!query && dataMap.size !== (entities == null ? void 0 : entities.length)) {
1459
+ setIsSearching(false);
1460
+ setEntities(
1461
+ Array.from(dataMap.values()).sort(byEntityId)
1436
1462
  );
1437
- if (dataMap.size !== (entities == null ? void 0 : entities.length) || dataMapArray.some(
1438
- (item, index) => JSON.stringify(item) !== JSON.stringify(entities == null ? void 0 : entities[index])
1439
- )) {
1440
- setIsSearching(false);
1441
- setEntities(dataMapArray);
1442
- }
1443
1463
  }
1444
1464
  if (query) {
1445
1465
  setEntities(searchResults);
@@ -1447,7 +1467,6 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
1447
1467
  }, [
1448
1468
  dataMap,
1449
1469
  dataMap.size,
1450
- entities,
1451
1470
  entities == null ? void 0 : entities.length,
1452
1471
  query,
1453
1472
  searchResults,
@@ -1727,539 +1746,6 @@ var initCoreActions = (monoriseStore, appActions, coreService2) => {
1727
1746
  };
1728
1747
  };
1729
1748
 
1730
- // actions/websocket.action.ts
1731
- import { useCallback, useEffect as useEffect3, useRef, useState as useState3 } from "react";
1732
- import { produce as produce5 } from "immer";
1733
- var globalWsManager = null;
1734
- var wsEndpoint;
1735
- var initializeWebSocketManager = (WebSocketManagerClass, endpoint, token) => {
1736
- if (globalWsManager) return globalWsManager;
1737
- wsEndpoint = endpoint;
1738
- globalWsManager = new WebSocketManagerClass(endpoint, token || "");
1739
- globalWsManager.connect();
1740
- return globalWsManager;
1741
- };
1742
- var getWebSocketManager = () => globalWsManager;
1743
- var initWebSocketActions = (monoriseStore, httpActions) => {
1744
- const useEntitySocket2 = (entityType, opts = {}) => {
1745
- const { limit = 20, skipInitialFetch = false } = opts;
1746
- const [isLoading, setIsLoading] = useState3(!skipInitialFetch);
1747
- const [isFetchingMore, setIsFetchingMore] = useState3(false);
1748
- const [isRefreshing, setIsRefreshing] = useState3(false);
1749
- const [isSubscribed, setIsSubscribed] = useState3(false);
1750
- const [error, setError2] = useState3(null);
1751
- const [hasMore, setHasMore] = useState3(true);
1752
- const lastKeyRef = useRef(void 0);
1753
- const isFirstFetchRef = useRef(true);
1754
- const entities = monoriseStore((state) => {
1755
- var _a;
1756
- const entityState = state.entity[entityType];
1757
- return Array.from(((_a = entityState == null ? void 0 : entityState.dataMap) == null ? void 0 : _a.values()) || []);
1758
- });
1759
- const fetchData = async (type) => {
1760
- if (!httpActions) return;
1761
- if (type === "more") {
1762
- setIsFetchingMore(true);
1763
- } else if (type === "refresh") {
1764
- setIsRefreshing(true);
1765
- } else {
1766
- setIsLoading(true);
1767
- }
1768
- setError2(null);
1769
- try {
1770
- const fetchLastKey = type === "refresh" ? void 0 : lastKeyRef.current;
1771
- const result = await httpActions.listEntities(entityType, {
1772
- limit,
1773
- lastKey: fetchLastKey
1774
- });
1775
- monoriseStore.setState(
1776
- produce5((state) => {
1777
- if (type === "refresh") {
1778
- state.entity[entityType].dataMap.clear();
1779
- }
1780
- for (const entity of result.data) {
1781
- state.entity[entityType].dataMap.set(entity.entityId, entity);
1782
- }
1783
- state.entity[entityType].isFirstFetched = true;
1784
- state.entity[entityType].lastKey = result.lastKey;
1785
- })
1786
- );
1787
- lastKeyRef.current = result.lastKey;
1788
- setHasMore(!!result.lastKey);
1789
- } catch (err) {
1790
- setError2(err instanceof Error ? err : new Error("Failed to fetch"));
1791
- } finally {
1792
- setIsLoading(false);
1793
- setIsFetchingMore(false);
1794
- setIsRefreshing(false);
1795
- }
1796
- };
1797
- useEffect3(() => {
1798
- if (skipInitialFetch) return;
1799
- fetchData("initial");
1800
- }, [entityType, limit, skipInitialFetch]);
1801
- useEffect3(() => {
1802
- if (!globalWsManager) {
1803
- setIsSubscribed(false);
1804
- return;
1805
- }
1806
- const subKey = globalWsManager.subscribeEntityType(entityType);
1807
- setIsSubscribed(true);
1808
- let wasConnected = false;
1809
- const unsubscribeState = globalWsManager.onStateChange((state) => {
1810
- if (state === "connected" && wasConnected === false && !isFirstFetchRef.current) {
1811
- fetchData("refresh");
1812
- }
1813
- wasConnected = state === "connected";
1814
- isFirstFetchRef.current = false;
1815
- });
1816
- const unsubscribeMessage = globalWsManager.onMessage(
1817
- (msg) => {
1818
- if (msg.type === "entity.created" || msg.type === "entity.updated" || msg.type === "entity.deleted") {
1819
- const payload = msg.payload;
1820
- if (payload.entityType !== entityType) return;
1821
- if (msg.type === "entity.created" || msg.type === "entity.updated") {
1822
- if (payload.data) {
1823
- monoriseStore.setState(
1824
- produce5((state) => {
1825
- const key = entityType;
1826
- if (!state.entity[key]) {
1827
- state.entity[key] = { dataMap: /* @__PURE__ */ new Map(), isFirstFetched: false, lastKey: void 0 };
1828
- }
1829
- state.entity[key].dataMap.set(
1830
- payload.entityId,
1831
- payload.data
1832
- );
1833
- })
1834
- );
1835
- }
1836
- } else if (msg.type === "entity.deleted") {
1837
- monoriseStore.setState(
1838
- produce5((state) => {
1839
- var _a;
1840
- const key = entityType;
1841
- if ((_a = state.entity[key]) == null ? void 0 : _a.dataMap) {
1842
- state.entity[key].dataMap.delete(payload.entityId);
1843
- }
1844
- })
1845
- );
1846
- }
1847
- }
1848
- }
1849
- );
1850
- return () => {
1851
- globalWsManager == null ? void 0 : globalWsManager.unsubscribeEntityType(subKey);
1852
- unsubscribeState();
1853
- unsubscribeMessage();
1854
- setIsSubscribed(false);
1855
- };
1856
- }, [entityType]);
1857
- const fetchMore = async () => {
1858
- if (!hasMore || isFetchingMore) return;
1859
- await fetchData("more");
1860
- };
1861
- return {
1862
- entities,
1863
- isLoading,
1864
- isFetchingMore,
1865
- isSubscribed,
1866
- error,
1867
- isRefreshing,
1868
- fetchMore,
1869
- hasMore
1870
- };
1871
- };
1872
- const useMutualSocket2 = (byEntityType, byEntityId2, mutualEntityType, opts = {}) => {
1873
- const { limit = 20, skipInitialFetch = false } = opts;
1874
- const [isLoading, setIsLoading] = useState3(
1875
- !skipInitialFetch && !!byEntityId2
1876
- );
1877
- const [isFetchingMore, setIsFetchingMore] = useState3(false);
1878
- const [isRefreshing, setIsRefreshing] = useState3(false);
1879
- const [isSubscribed, setIsSubscribed] = useState3(false);
1880
- const [error, setError2] = useState3(null);
1881
- const [hasMore, setHasMore] = useState3(true);
1882
- const lastKeyRef = useRef(void 0);
1883
- const isFirstFetchRef = useRef(true);
1884
- const mutualKey = byEntityId2 ? `${byEntityType}/${byEntityId2}/${mutualEntityType}` : "";
1885
- const mutuals = monoriseStore((state) => {
1886
- var _a, _b;
1887
- return Array.from(((_b = (_a = state.mutual[mutualKey]) == null ? void 0 : _a.dataMap) == null ? void 0 : _b.values()) || []);
1888
- });
1889
- const fetchData = async (type) => {
1890
- if (!byEntityId2 || !httpActions) return;
1891
- if (type === "more") {
1892
- setIsFetchingMore(true);
1893
- } else if (type === "refresh") {
1894
- setIsRefreshing(true);
1895
- } else {
1896
- setIsLoading(true);
1897
- }
1898
- setError2(null);
1899
- try {
1900
- const fetchLastKey = type === "refresh" ? void 0 : lastKeyRef.current;
1901
- const result = await httpActions.listEntitiesByEntity(
1902
- byEntityType,
1903
- byEntityId2,
1904
- mutualEntityType,
1905
- { limit, lastKey: fetchLastKey }
1906
- );
1907
- monoriseStore.setState(
1908
- produce5((state) => {
1909
- if (!state.mutual[mutualKey]) {
1910
- state.mutual[mutualKey] = {
1911
- dataMap: /* @__PURE__ */ new Map(),
1912
- isFirstFetched: true,
1913
- lastKey: void 0
1914
- };
1915
- }
1916
- if (type === "refresh") {
1917
- state.mutual[mutualKey].dataMap.clear();
1918
- }
1919
- for (const entity of result.entities) {
1920
- const e = entity;
1921
- state.mutual[mutualKey].dataMap.set(e.entityId, entity);
1922
- }
1923
- state.mutual[mutualKey].lastKey = result.lastKey;
1924
- })
1925
- );
1926
- lastKeyRef.current = result.lastKey;
1927
- setHasMore(!!result.lastKey);
1928
- } catch (err) {
1929
- setError2(err instanceof Error ? err : new Error("Failed to fetch"));
1930
- } finally {
1931
- setIsLoading(false);
1932
- setIsFetchingMore(false);
1933
- setIsRefreshing(false);
1934
- }
1935
- };
1936
- useEffect3(() => {
1937
- if (skipInitialFetch || !byEntityId2) {
1938
- setIsLoading(false);
1939
- return;
1940
- }
1941
- lastKeyRef.current = void 0;
1942
- setHasMore(true);
1943
- isFirstFetchRef.current = true;
1944
- fetchData("initial");
1945
- }, [byEntityType, byEntityId2, mutualEntityType, limit, skipInitialFetch]);
1946
- useEffect3(() => {
1947
- if (!globalWsManager || !byEntityId2) {
1948
- setIsSubscribed(false);
1949
- return;
1950
- }
1951
- const subKey = globalWsManager.subscribeMutualType(
1952
- byEntityType,
1953
- byEntityId2,
1954
- mutualEntityType
1955
- );
1956
- setIsSubscribed(true);
1957
- let wasConnected = false;
1958
- const unsubscribeState = globalWsManager.onStateChange((state) => {
1959
- if (state === "connected" && wasConnected === false && !isFirstFetchRef.current) {
1960
- fetchData("refresh");
1961
- }
1962
- wasConnected = state === "connected";
1963
- isFirstFetchRef.current = false;
1964
- });
1965
- const unsubscribeMessage = globalWsManager.onMessage(
1966
- (msg) => {
1967
- if (msg.type === "mutual.created" || msg.type === "mutual.updated" || msg.type === "mutual.deleted") {
1968
- const payload = msg.payload;
1969
- if (payload.byEntityType !== byEntityType || payload.byEntityId !== byEntityId2 || payload.mutualEntityType !== mutualEntityType) {
1970
- return;
1971
- }
1972
- if (msg.type === "mutual.created" || msg.type === "mutual.updated") {
1973
- if (payload.data) {
1974
- monoriseStore.setState(
1975
- produce5((state) => {
1976
- if (!state.mutual[mutualKey]) {
1977
- state.mutual[mutualKey] = {
1978
- dataMap: /* @__PURE__ */ new Map(),
1979
- isFirstFetched: true,
1980
- lastKey: void 0
1981
- };
1982
- }
1983
- state.mutual[mutualKey].dataMap.set(
1984
- payload.entityId,
1985
- payload.data
1986
- );
1987
- })
1988
- );
1989
- }
1990
- } else if (msg.type === "mutual.deleted") {
1991
- monoriseStore.setState(
1992
- produce5((state) => {
1993
- var _a;
1994
- (_a = state.mutual[mutualKey]) == null ? void 0 : _a.dataMap.delete(payload.entityId);
1995
- })
1996
- );
1997
- }
1998
- }
1999
- }
2000
- );
2001
- return () => {
2002
- globalWsManager == null ? void 0 : globalWsManager.unsubscribeMutualType(subKey);
2003
- unsubscribeState();
2004
- unsubscribeMessage();
2005
- setIsSubscribed(false);
2006
- };
2007
- }, [byEntityType, byEntityId2, mutualEntityType, mutualKey]);
2008
- const fetchMore = async () => {
2009
- if (!hasMore || isFetchingMore) return;
2010
- await fetchData("more");
2011
- };
2012
- return {
2013
- mutuals,
2014
- isLoading,
2015
- isFetchingMore,
2016
- isSubscribed,
2017
- error,
2018
- isRefreshing,
2019
- fetchMore,
2020
- hasMore
2021
- };
2022
- };
2023
- const useEphemeralSocket2 = (channel, opts) => {
2024
- const [isSubscribed, setIsSubscribed] = useState3(false);
2025
- useEffect3(() => {
2026
- if (!globalWsManager || !channel) {
2027
- setIsSubscribed(false);
2028
- return;
2029
- }
2030
- const subKey = globalWsManager.subscribeEphemeral(channel);
2031
- setIsSubscribed(true);
2032
- const unsubscribeMessage = globalWsManager.onMessage(
2033
- (msg) => {
2034
- var _a;
2035
- if (msg.type === "ephemeral") {
2036
- const payload = msg.payload;
2037
- if (payload.channel !== channel) return;
2038
- (_a = opts == null ? void 0 : opts.onMessage) == null ? void 0 : _a.call(opts, payload.data, payload.senderId);
2039
- }
2040
- }
2041
- );
2042
- return () => {
2043
- globalWsManager == null ? void 0 : globalWsManager.unsubscribeEphemeral(subKey);
2044
- unsubscribeMessage();
2045
- setIsSubscribed(false);
2046
- };
2047
- }, [channel]);
2048
- const send = useCallback(
2049
- (data) => {
2050
- if (!globalWsManager || !channel) return;
2051
- globalWsManager.sendEphemeral(channel, data);
2052
- },
2053
- [channel]
2054
- );
2055
- return { isSubscribed, send };
2056
- };
2057
- const useEntityFeed2 = (opts) => {
2058
- const { entityType, entityId, ticketEndpoint } = opts;
2059
- const [isConnected, setIsConnected] = useState3(false);
2060
- const [error, setError2] = useState3(null);
2061
- const refreshTimerRef = useRef(null);
2062
- const wsManagerRef = useRef(null);
2063
- const isMountedRef = useRef(true);
2064
- const connectingRef = useRef(false);
2065
- const reconnectCountRef = useRef(0);
2066
- const connectRef = useRef(() => {
2067
- });
2068
- const lastConnectedAtRef = useRef(0);
2069
- const fetchTicket = useCallback(async () => {
2070
- try {
2071
- const url = ticketEndpoint || `/api/core/ws/ticket/${entityType}/${entityId}`;
2072
- const fetchOpts = {
2073
- method: "POST",
2074
- headers: { "Content-Type": "application/json" }
2075
- };
2076
- if (ticketEndpoint) {
2077
- fetchOpts.body = JSON.stringify({ entityType, entityId });
2078
- }
2079
- const response = await fetch(url, fetchOpts);
2080
- if (response.status === 401 || response.status === 403) {
2081
- return { error: { code: "TICKET_UNAUTHORIZED", message: "Unauthorized" } };
2082
- }
2083
- if (!response.ok) {
2084
- return { error: { code: "TICKET_FAILED", message: `HTTP ${response.status}` } };
2085
- }
2086
- const data = await response.json();
2087
- return { data };
2088
- } catch (err) {
2089
- return { error: { code: "TICKET_FAILED", message: err.message } };
2090
- }
2091
- }, [entityType, entityId, ticketEndpoint]);
2092
- const connectWithTicket = useCallback(async () => {
2093
- if (connectingRef.current) return;
2094
- connectingRef.current = true;
2095
- let result = null;
2096
- const maxRetries = 3;
2097
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
2098
- result = await fetchTicket();
2099
- if (!isMountedRef.current) {
2100
- connectingRef.current = false;
2101
- return;
2102
- }
2103
- if (!result.error) break;
2104
- if (result.error.code === "TICKET_UNAUTHORIZED") break;
2105
- if (attempt < maxRetries) {
2106
- await new Promise((r) => setTimeout(r, 1e3 * Math.pow(2, attempt)));
2107
- if (!isMountedRef.current) {
2108
- connectingRef.current = false;
2109
- return;
2110
- }
2111
- }
2112
- }
2113
- if (result.error) {
2114
- setError2(result.error);
2115
- setIsConnected(false);
2116
- connectingRef.current = false;
2117
- return;
2118
- }
2119
- setError2(null);
2120
- const { ticket, wsUrl, expiresIn } = result.data;
2121
- if (wsManagerRef.current) {
2122
- wsManagerRef.current.disconnect();
2123
- }
2124
- const { WebSocketManager: WsManagerClass } = await import("./websocket-7MZ3ENOC.js");
2125
- const wsUrlWithTicket = `${wsUrl}?ticket=${encodeURIComponent(ticket)}`;
2126
- const manager = new WsManagerClass(wsUrlWithTicket, "");
2127
- manager.disableAutoReconnect = true;
2128
- wsManagerRef.current = manager;
2129
- globalWsManager = manager;
2130
- manager.onStateChange((state) => {
2131
- if (!isMountedRef.current) return;
2132
- if (wsManagerRef.current !== manager) return;
2133
- if (state === "connected") {
2134
- connectingRef.current = false;
2135
- reconnectCountRef.current = 0;
2136
- lastConnectedAtRef.current = Date.now();
2137
- setIsConnected(true);
2138
- setError2(null);
2139
- } else if (state === "disconnected") {
2140
- connectingRef.current = false;
2141
- setIsConnected(false);
2142
- const wasStable = Date.now() - lastConnectedAtRef.current > 5e3;
2143
- if (wasStable && reconnectCountRef.current < 5) {
2144
- reconnectCountRef.current++;
2145
- const delay = 2e3 * Math.pow(2, reconnectCountRef.current - 1);
2146
- setTimeout(() => {
2147
- if (isMountedRef.current && !connectingRef.current) {
2148
- connectRef.current();
2149
- }
2150
- }, delay);
2151
- }
2152
- }
2153
- });
2154
- manager.onMessage((msg) => {
2155
- if (!isMountedRef.current) return;
2156
- if (msg.type === "entity.created" || msg.type === "entity.updated") {
2157
- const payload = msg.payload;
2158
- if (payload.data) {
2159
- monoriseStore.setState(
2160
- produce5((state) => {
2161
- const key = payload.entityType;
2162
- if (!state.entity[key]) {
2163
- state.entity[key] = { dataMap: /* @__PURE__ */ new Map(), isFirstFetched: false, lastKey: void 0 };
2164
- }
2165
- state.entity[key].dataMap.set(payload.entityId, payload.data);
2166
- })
2167
- );
2168
- }
2169
- } else if (msg.type === "entity.deleted") {
2170
- const payload = msg.payload;
2171
- monoriseStore.setState(
2172
- produce5((state) => {
2173
- var _a, _b;
2174
- (_b = (_a = state.entity[payload.entityType]) == null ? void 0 : _a.dataMap) == null ? void 0 : _b.delete(payload.entityId);
2175
- })
2176
- );
2177
- } else if (msg.type === "mutual.created" || msg.type === "mutual.updated") {
2178
- const payload = msg.payload;
2179
- if (payload.data) {
2180
- const mutualKey = `${payload.byEntityType}/${payload.byEntityId}/${payload.mutualEntityType}`;
2181
- monoriseStore.setState(
2182
- produce5((state) => {
2183
- if (!state.mutual[mutualKey]) {
2184
- state.mutual[mutualKey] = { dataMap: /* @__PURE__ */ new Map(), isFirstFetched: false, lastKey: void 0 };
2185
- }
2186
- state.mutual[mutualKey].dataMap.set(payload.entityId, payload.data);
2187
- })
2188
- );
2189
- }
2190
- } else if (msg.type === "mutual.deleted") {
2191
- const payload = msg.payload;
2192
- const mutualKey = `${payload.byEntityType}/${payload.byEntityId}/${payload.mutualEntityType}`;
2193
- monoriseStore.setState(
2194
- produce5((state) => {
2195
- var _a, _b;
2196
- (_b = (_a = state.mutual[mutualKey]) == null ? void 0 : _a.dataMap) == null ? void 0 : _b.delete(payload.entityId);
2197
- })
2198
- );
2199
- }
2200
- });
2201
- manager.connect();
2202
- if (refreshTimerRef.current) {
2203
- clearTimeout(refreshTimerRef.current);
2204
- }
2205
- const refreshMs = Math.max((expiresIn - 120) * 1e3, 6e4);
2206
- refreshTimerRef.current = setTimeout(() => {
2207
- if (isMountedRef.current) {
2208
- connectRef.current();
2209
- }
2210
- }, refreshMs);
2211
- }, [fetchTicket]);
2212
- connectRef.current = connectWithTicket;
2213
- useEffect3(() => {
2214
- isMountedRef.current = true;
2215
- if (entityId) {
2216
- connectRef.current();
2217
- }
2218
- let lastCheckTime = Date.now();
2219
- const sleepCheckInterval = setInterval(() => {
2220
- const now = Date.now();
2221
- const elapsed = now - lastCheckTime;
2222
- lastCheckTime = now;
2223
- if (elapsed > 3e4 && wsManagerRef.current) {
2224
- wsManagerRef.current.disconnect();
2225
- wsManagerRef.current = null;
2226
- connectingRef.current = false;
2227
- reconnectCountRef.current = 0;
2228
- connectRef.current();
2229
- }
2230
- }, 5e3);
2231
- const handleOnline = () => {
2232
- var _a;
2233
- if (!isMountedRef.current) return;
2234
- if (((_a = wsManagerRef.current) == null ? void 0 : _a.getState()) === "connected") return;
2235
- if (connectingRef.current) return;
2236
- reconnectCountRef.current = 0;
2237
- connectRef.current();
2238
- };
2239
- window.addEventListener("online", handleOnline);
2240
- return () => {
2241
- isMountedRef.current = false;
2242
- clearInterval(sleepCheckInterval);
2243
- window.removeEventListener("online", handleOnline);
2244
- if (refreshTimerRef.current) {
2245
- clearTimeout(refreshTimerRef.current);
2246
- }
2247
- if (wsManagerRef.current) {
2248
- wsManagerRef.current.disconnect();
2249
- wsManagerRef.current = null;
2250
- }
2251
- };
2252
- }, [entityType, entityId]);
2253
- return { isConnected, error };
2254
- };
2255
- return {
2256
- useEntitySocket: useEntitySocket2,
2257
- useMutualSocket: useMutualSocket2,
2258
- useEphemeralSocket: useEphemeralSocket2,
2259
- useEntityFeed: useEntityFeed2
2260
- };
2261
- };
2262
-
2263
1749
  // lib/api.ts
2264
1750
  import request from "axios";
2265
1751
  var initAxiosInterceptor = (store2, appActions) => {
@@ -2378,7 +1864,6 @@ var auth_service_default = initAuthService;
2378
1864
  var ENTITY_API_BASE_URL = "/api/core/entity";
2379
1865
  var MUTUAL_API_BASE_URL = "/api/core/mutual";
2380
1866
  var TAG_API_BASE_URL = "/api/core/tag";
2381
- var TRANSACTION_API_BASE_URL = "/api/core/transaction";
2382
1867
  var initCoreService = (monoriseStore, axios2, opts) => {
2383
1868
  let options = opts || {};
2384
1869
  const listEntities = (entityType, payload, opts2 = {}) => {
@@ -2495,10 +1980,9 @@ var initCoreService = (monoriseStore, axios2, opts) => {
2495
1980
  var _a;
2496
1981
  const { entityApiBaseUrl = ENTITY_API_BASE_URL } = options;
2497
1982
  const entityConfig = monoriseStore.getState().config;
2498
- const body = opts2.condition ? __spreadProps(__spreadValues({}, adjustments), { $condition: opts2.condition }) : adjustments;
2499
1983
  return axios2.post(
2500
1984
  opts2.customUrl || `${entityApiBaseUrl}/${entityType}/${id}/adjust`,
2501
- body,
1985
+ adjustments,
2502
1986
  {
2503
1987
  requestKey: getEntityRequestKey("adjust", entityType, id),
2504
1988
  isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
@@ -2525,22 +2009,6 @@ var initCoreService = (monoriseStore, axios2, opts) => {
2525
2009
  }
2526
2010
  );
2527
2011
  };
2528
- const transaction = (operations, opts2 = {}) => {
2529
- var _a;
2530
- const { transactionApiBaseUrl = TRANSACTION_API_BASE_URL } = options;
2531
- return axios2.post(
2532
- opts2.customUrl || transactionApiBaseUrl,
2533
- { operations },
2534
- {
2535
- requestKey: "transaction",
2536
- isInterruptive: (_a = opts2.isInterruptive) != null ? _a : true,
2537
- feedback: __spreadValues({
2538
- loading: "Processing transaction",
2539
- success: "Transaction completed"
2540
- }, opts2.feedback || {})
2541
- }
2542
- );
2543
- };
2544
2012
  const listEntitiesByEntity = (byEntityType, entityType, byEntityId2, opts2 = {}, chainEntityQuery) => {
2545
2013
  const { mutualApiBaseUrl = MUTUAL_API_BASE_URL } = options;
2546
2014
  return axios2.get(
@@ -2684,7 +2152,6 @@ var initCoreService = (monoriseStore, axios2, opts) => {
2684
2152
  return {
2685
2153
  makeEntityService,
2686
2154
  makeMutualService,
2687
- transaction,
2688
2155
  setOptions
2689
2156
  };
2690
2157
  };
@@ -2915,7 +2382,6 @@ var initMonoriseStore = () => {
2915
2382
  };
2916
2383
 
2917
2384
  // index.ts
2918
- import { transactional } from "../base/index.js";
2919
2385
  var initMonorise = () => {
2920
2386
  const { monoriseStore: store2, setOptions: setMonoriseOptions } = initMonoriseStore();
2921
2387
  const appActions = initAppActions(store2);
@@ -2926,7 +2392,6 @@ var initMonorise = () => {
2926
2392
  const coreService2 = core_service_default(store2, axios2);
2927
2393
  const authActions = initAuthActions(store2, authService2);
2928
2394
  const coreActions = initCoreActions(store2, appActions, coreService2);
2929
- const websocketActions = initWebSocketActions(store2);
2930
2395
  const axiosInterceptor = injectAxiosInterceptor(
2931
2396
  appActions,
2932
2397
  authActions,
@@ -2952,14 +2417,14 @@ var initMonorise = () => {
2952
2417
  onApiSuccess: opts.onApiSuccess
2953
2418
  });
2954
2419
  };
2955
- return __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
2420
+ return __spreadValues(__spreadValues(__spreadValues(__spreadValues({
2956
2421
  config,
2957
2422
  store: store2,
2958
2423
  axios: axios2,
2959
2424
  authService: authService2,
2960
2425
  filestoreService: filestoreService2,
2961
2426
  coreService: coreService2
2962
- }, configActions), appActions), authActions), coreActions), websocketActions);
2427
+ }, configActions), appActions), authActions), coreActions);
2963
2428
  };
2964
2429
  var Monorise = initMonorise();
2965
2430
  var {
@@ -3011,15 +2476,10 @@ var {
3011
2476
  useEntityState,
3012
2477
  getEntity,
3013
2478
  updateLocalTaggedEntity,
3014
- deleteLocalTaggedEntity,
3015
- useEntitySocket,
3016
- useMutualSocket,
3017
- useEphemeralSocket,
3018
- useEntityFeed
2479
+ deleteLocalTaggedEntity
3019
2480
  } = Monorise;
3020
2481
  var index_default = Monorise;
3021
2482
  export {
3022
- WebSocketManager,
3023
2483
  adjustEntity,
3024
2484
  authService,
3025
2485
  axios,
@@ -3047,8 +2507,6 @@ export {
3047
2507
  getProfile,
3048
2508
  getTagRequestKey,
3049
2509
  getUniqueFieldRequestKey,
3050
- getWebSocketManager,
3051
- initializeWebSocketManager,
3052
2510
  listMoreEntities,
3053
2511
  logout,
3054
2512
  openModal,
@@ -3058,7 +2516,6 @@ export {
3058
2516
  setIsUnauthorized,
3059
2517
  startLoading,
3060
2518
  store,
3061
- transactional,
3062
2519
  updateLocalEntity,
3063
2520
  updateLocalTaggedEntity,
3064
2521
  upsertEntity,
@@ -3067,17 +2524,13 @@ export {
3067
2524
  useEntities,
3068
2525
  useEntity,
3069
2526
  useEntityByUniqueField,
3070
- useEntityFeed,
3071
- useEntitySocket,
3072
2527
  useEntityState,
3073
- useEphemeralSocket,
3074
2528
  useErrorStore,
3075
2529
  useInterruptiveLoadStore,
3076
2530
  useIsUnauthorized,
3077
2531
  useLoadStore,
3078
2532
  useModalStore,
3079
2533
  useMutual,
3080
- useMutualSocket,
3081
2534
  useMutuals,
3082
2535
  useProfile,
3083
2536
  useTaggedEntities