akeyless-client-commons 1.1.7 → 1.1.9

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.
@@ -39,6 +39,25 @@ function _async_to_generator(fn) {
39
39
  });
40
40
  };
41
41
  }
42
+ function _class_call_check(instance, Constructor) {
43
+ if (!(instance instanceof Constructor)) {
44
+ throw new TypeError("Cannot call a class as a function");
45
+ }
46
+ }
47
+ function _defineProperties(target, props) {
48
+ for(var i = 0; i < props.length; i++){
49
+ var descriptor = props[i];
50
+ descriptor.enumerable = descriptor.enumerable || false;
51
+ descriptor.configurable = true;
52
+ if ("value" in descriptor) descriptor.writable = true;
53
+ Object.defineProperty(target, descriptor.key, descriptor);
54
+ }
55
+ }
56
+ function _create_class(Constructor, protoProps, staticProps) {
57
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
58
+ if (staticProps) _defineProperties(Constructor, staticProps);
59
+ return Constructor;
60
+ }
42
61
  function _define_property(obj, key, value) {
43
62
  if (key in obj) {
44
63
  Object.defineProperty(obj, key, {
@@ -1906,5 +1925,276 @@ var nxApiCall = /*#__PURE__*/ function() {
1906
1925
  return _ref.apply(this, arguments);
1907
1926
  };
1908
1927
  }();
1909
- export { addAuditRecord, addLoginAudit, add_document, addressRegex, akeylessOnlineDomain, app, appCheck, auth, baseDomain, biDomain, calculateBearing, callCenterEventsDomain, callCenterGeoDomain, carsRegex, chartsRegex, checkUserPermissions, cleanNxSites, cn, collections, colorRegex, createSelectors, db, delete_document, devicesDomain, displayFormatPhoneNumber, durationToSeconds, emailRegex, extractAlertsData, extractBoardsData, extractCanbusData, extractCarsData, extractClientData, extractLocationData, extractSiteData, fire_base_TIME_TEMP, formatCarNumber, getAddressByGeo, getFixedNumber, getFormCheckboxValue, getFormElementValue, getLocationUrl, getUserByEmail, getUserByIdentifier, getUserByPhone, getUserCountryByIp, get_all_documents, get_document_by_id, get_international_phone_number, googleLoginProvider, handleChange, handleInvalid, handlePaste, initializeUserPermissions, international_israel_phone_format, isInternational, isInternationalIsraelPhone, isLocal, isNodeEnv, is_iccid, local_israel_phone_format, mode, multiStringFormat, notificationsDomain, numbersOnlyRegex, numbersRegex, nxApiCall, parseMultiSelectInput, parsePermissions, parseSnapshotAsArray, priceRegex, propsAreEqual, query_document, query_document_by_conditions, query_documents, query_documents_by_conditions, renderOnce, secondsToDuration, setFormElementValue, setState, set_document, simpleExtractData, snapshot, snapshotDocument, sort_by_timestamp, storage, textNumbersRegex, textRegex, timestamp_to_millis, timestamp_to_string, useLoginWithGoogle, useStoreValues, useValidation, userNameFormat, validateAndCast, validateUserStatusAndPermissions };
1928
+ // src/helpers/socket.ts
1929
+ import { io } from "socket.io-client";
1930
+ var SocketService = /*#__PURE__*/ function() {
1931
+ "use strict";
1932
+ function _SocketService() {
1933
+ _class_call_check(this, _SocketService);
1934
+ this.socket = null;
1935
+ this.connectCallbacks = [];
1936
+ this.disconnectCallbacks = [];
1937
+ }
1938
+ _create_class(_SocketService, [
1939
+ {
1940
+ /// Initialize the socket connection
1941
+ key: "initSocket",
1942
+ value: function initSocket() {
1943
+ var _this = this;
1944
+ if (!this.socket) {
1945
+ var SOCKET_SERVER_URL = "http://localhost:9009";
1946
+ var SOCKET_PATH = "/api/data-socket/connect";
1947
+ this.socket = io(SOCKET_SERVER_URL, {
1948
+ path: SOCKET_PATH,
1949
+ transports: [
1950
+ "websocket"
1951
+ ]
1952
+ });
1953
+ this.socket.on("connect", function() {
1954
+ var _this_socket;
1955
+ console.log("Socket connected:", (_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.id);
1956
+ _this.connectCallbacks.forEach(function(cb) {
1957
+ return cb();
1958
+ });
1959
+ });
1960
+ this.socket.on("disconnect", function(reason) {
1961
+ console.log("Socket disconnected:", reason);
1962
+ _this.disconnectCallbacks.forEach(function(cb) {
1963
+ return cb();
1964
+ });
1965
+ });
1966
+ this.socket.on("connect_error", function(error) {
1967
+ console.error("Socket connection error:", error);
1968
+ });
1969
+ }
1970
+ }
1971
+ },
1972
+ {
1973
+ /// get socket instance
1974
+ key: "getSocketInstance",
1975
+ value: function getSocketInstance() {
1976
+ if (!this.socket) {
1977
+ this.initSocket();
1978
+ }
1979
+ if (!this.socket) {
1980
+ throw new Error("Socket not initialized");
1981
+ }
1982
+ if (!this.socket.connected) {
1983
+ this.socket.connect();
1984
+ }
1985
+ return this.socket;
1986
+ }
1987
+ },
1988
+ {
1989
+ /// subscribe to collections
1990
+ key: "subscribeToCollections",
1991
+ value: function subscribeToCollections(config) {
1992
+ var s = this.getSocketInstance();
1993
+ var collectionsNames = config.map(function(c) {
1994
+ return c.collectionName;
1995
+ });
1996
+ var eventHandlers = [];
1997
+ config.forEach(function(configuration) {
1998
+ var collectionName = configuration.collectionName, onAdd = configuration.onAdd, onFirstTime = configuration.onFirstTime, onModify = configuration.onModify, onRemove = configuration.onRemove, extraParsers = configuration.extraParsers, conditions = configuration.conditions, orderBy2 = configuration.orderBy;
1999
+ s.on("initial:".concat(collectionName), onFirstTime);
2000
+ eventHandlers.push({
2001
+ eventName: "initial:".concat(collectionName),
2002
+ handler: onFirstTime
2003
+ });
2004
+ s.on("add:".concat(collectionName), onAdd);
2005
+ eventHandlers.push({
2006
+ eventName: "add:".concat(collectionName),
2007
+ handler: onAdd
2008
+ });
2009
+ s.on("update:".concat(collectionName), onModify);
2010
+ eventHandlers.push({
2011
+ eventName: "update:".concat(collectionName),
2012
+ handler: onModify
2013
+ });
2014
+ s.on("delete:".concat(collectionName), onRemove);
2015
+ eventHandlers.push({
2016
+ eventName: "delete:".concat(collectionName),
2017
+ handler: onRemove
2018
+ });
2019
+ extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
2020
+ var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
2021
+ s.on("initial:".concat(collectionName), extraOnFirstTime);
2022
+ eventHandlers.push({
2023
+ eventName: "initial:".concat(collectionName),
2024
+ handler: extraOnFirstTime
2025
+ });
2026
+ s.on("add:".concat(collectionName), extraOnAdd);
2027
+ eventHandlers.push({
2028
+ eventName: "add:".concat(collectionName),
2029
+ handler: extraOnAdd
2030
+ });
2031
+ s.on("update:".concat(collectionName), extraOnModify);
2032
+ eventHandlers.push({
2033
+ eventName: "update:".concat(collectionName),
2034
+ handler: extraOnModify
2035
+ });
2036
+ s.on("delete:".concat(collectionName), extraOnRemove);
2037
+ eventHandlers.push({
2038
+ eventName: "delete:".concat(collectionName),
2039
+ handler: extraOnRemove
2040
+ });
2041
+ });
2042
+ });
2043
+ s.emit("subscribe_collections", collectionsNames, function(callback) {
2044
+ if (callback.success) {
2045
+ console.log("Successfully subscribed to: ".concat(collectionsNames.join(", ")));
2046
+ } else {
2047
+ console.error("Failed to subscribe to ".concat(config.join(", "), ": ").concat(callback.message));
2048
+ }
2049
+ });
2050
+ return function() {
2051
+ console.log("Cleaning up subscriptions for: ".concat(collectionsNames.join(", ")));
2052
+ s.emit("unsubscribe_collections", collectionsNames);
2053
+ eventHandlers.forEach(function(eh) {
2054
+ s.off(eh.eventName, eh.handler);
2055
+ });
2056
+ };
2057
+ }
2058
+ },
2059
+ {
2060
+ /// set data
2061
+ key: "setData",
2062
+ value: function setData(payload) {
2063
+ var s = this.getSocketInstance();
2064
+ return new Promise(function(resolve, reject) {
2065
+ s.emit("set_data", payload, function(callback) {
2066
+ if (callback.success) {
2067
+ console.log("Data saved successfully:", payload);
2068
+ console.log("ack", callback);
2069
+ resolve(callback);
2070
+ } else {
2071
+ reject(new Error(callback.message || "Save operation failed"));
2072
+ }
2073
+ });
2074
+ });
2075
+ }
2076
+ },
2077
+ {
2078
+ /// get data
2079
+ key: "getCollectionData",
2080
+ value: function getCollectionData(payload) {
2081
+ var s = this.getSocketInstance();
2082
+ s.emit("get_data", {
2083
+ collection_name: payload.collection_name
2084
+ }, function(socketCallback) {
2085
+ if (socketCallback.success && socketCallback.data) {
2086
+ payload.callback(socketCallback.data);
2087
+ } else {
2088
+ payload.callback(payload.defaultValue);
2089
+ }
2090
+ });
2091
+ }
2092
+ },
2093
+ {
2094
+ key: "getDocumentData",
2095
+ value: function getDocumentData(payload) {
2096
+ var s = this.getSocketInstance();
2097
+ s.emit("get_data", {
2098
+ collection_name: payload.collection_name,
2099
+ key: payload.key
2100
+ }, function(socketCallback) {
2101
+ if (socketCallback.success && socketCallback.data) {
2102
+ payload.callback(socketCallback.data);
2103
+ } else {
2104
+ payload.callback(payload.defaultValue);
2105
+ }
2106
+ });
2107
+ }
2108
+ },
2109
+ {
2110
+ /// delete data
2111
+ key: "deleteData",
2112
+ value: function deleteData(payload) {
2113
+ var s = this.getSocketInstance();
2114
+ return new Promise(function(resolve, reject) {
2115
+ s.emit("delete_data", payload, function(callback) {
2116
+ if (callback.success) {
2117
+ console.log("Data deleted successfully:", payload);
2118
+ console.log("delete ack", callback);
2119
+ resolve(callback);
2120
+ } else {
2121
+ reject(new Error(callback.message || "Delete operation failed"));
2122
+ }
2123
+ });
2124
+ });
2125
+ }
2126
+ },
2127
+ {
2128
+ key: "clearAllRedisData",
2129
+ value: function clearAllRedisData() {
2130
+ var s = this.getSocketInstance();
2131
+ return new Promise(function(resolve, reject) {
2132
+ s.emit("clear_all_redis_data", function(ack) {
2133
+ if (ack.success) {
2134
+ resolve(ack);
2135
+ } else {
2136
+ reject(new Error(ack.message || "Clear all Redis data operation failed"));
2137
+ }
2138
+ });
2139
+ });
2140
+ }
2141
+ },
2142
+ {
2143
+ /// connection management methods
2144
+ key: "onConnect",
2145
+ value: function onConnect(callback) {
2146
+ var _this_socket;
2147
+ this.connectCallbacks.push(callback);
2148
+ if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
2149
+ callback();
2150
+ }
2151
+ }
2152
+ },
2153
+ {
2154
+ key: "offConnect",
2155
+ value: function offConnect(callback) {
2156
+ this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
2157
+ return cb !== callback;
2158
+ });
2159
+ }
2160
+ },
2161
+ {
2162
+ key: "onDisconnect",
2163
+ value: function onDisconnect(callback) {
2164
+ this.disconnectCallbacks.push(callback);
2165
+ if (this.socket && !this.socket.connected) {
2166
+ callback();
2167
+ }
2168
+ }
2169
+ },
2170
+ {
2171
+ key: "offDisconnect",
2172
+ value: function offDisconnect(callback) {
2173
+ this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
2174
+ return cb !== callback;
2175
+ });
2176
+ }
2177
+ },
2178
+ {
2179
+ key: "isConnected",
2180
+ value: function isConnected() {
2181
+ var _this_socket;
2182
+ return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
2183
+ }
2184
+ }
2185
+ ], [
2186
+ {
2187
+ key: "getInstance",
2188
+ value: function getInstance() {
2189
+ if (!_SocketService.instance) {
2190
+ _SocketService.instance = new _SocketService();
2191
+ }
2192
+ return _SocketService.instance;
2193
+ }
2194
+ }
2195
+ ]);
2196
+ return _SocketService;
2197
+ }();
2198
+ var socketServiceInstance = SocketService.getInstance();
2199
+ export { addAuditRecord, addLoginAudit, add_document, addressRegex, akeylessOnlineDomain, app, appCheck, auth, baseDomain, biDomain, calculateBearing, callCenterEventsDomain, callCenterGeoDomain, carsRegex, chartsRegex, checkUserPermissions, cleanNxSites, cn, collections, colorRegex, createSelectors, db, delete_document, devicesDomain, displayFormatPhoneNumber, durationToSeconds, emailRegex, extractAlertsData, extractBoardsData, extractCanbusData, extractCarsData, extractClientData, extractLocationData, extractSiteData, fire_base_TIME_TEMP, formatCarNumber, getAddressByGeo, getFixedNumber, getFormCheckboxValue, getFormElementValue, getLocationUrl, getUserByEmail, getUserByIdentifier, getUserByPhone, getUserCountryByIp, get_all_documents, get_document_by_id, get_international_phone_number, googleLoginProvider, handleChange, handleInvalid, handlePaste, initializeUserPermissions, international_israel_phone_format, isInternational, isInternationalIsraelPhone, isLocal, isNodeEnv, is_iccid, local_israel_phone_format, mode, multiStringFormat, notificationsDomain, numbersOnlyRegex, numbersRegex, nxApiCall, parseMultiSelectInput, parsePermissions, parseSnapshotAsArray, priceRegex, propsAreEqual, query_document, query_document_by_conditions, query_documents, query_documents_by_conditions, renderOnce, secondsToDuration, setFormElementValue, setState, set_document, simpleExtractData, snapshot, snapshotDocument, socketServiceInstance, sort_by_timestamp, storage, textNumbersRegex, textRegex, timestamp_to_millis, timestamp_to_string, useLoginWithGoogle, useStoreValues, useValidation, userNameFormat, validateAndCast, validateUserStatusAndPermissions };
1910
2200
  //# sourceMappingURL=index.mjs.map
@@ -22,6 +22,8 @@ interface OnSnapshotConfig extends OnSnapshotParsers {
22
22
  fieldName: string;
23
23
  direction: "asc" | "desc";
24
24
  }[];
25
+ parseAs?: "object" | "array";
26
+ subscribeTo?: "cache" | "db";
25
27
  }
26
28
 
27
29
  declare const useDocumentTitle: (title: string) => any;
@@ -35,4 +37,22 @@ declare function useSafeEffect(callback: () => void, dependencies: any[], error_
35
37
  declare const useDeepCompareMemo: <T>(factory: () => T, dependencies: any[]) => T;
36
38
  declare function useDeepCompareEffect(effect: EffectCallback, dependencies: any[]): void;
37
39
 
38
- export { useDeepCompareEffect, useDeepCompareMemo, useDocumentTitle, useSafeEffect, useSetUserCountry, useSnapshotBulk };
40
+ declare const useSocketSubscription: (config: OnSnapshotConfig[]) => {
41
+ socketConnected: boolean;
42
+ };
43
+ type UseSmartSubscriptionSettings = {
44
+ label?: string;
45
+ settings?: {
46
+ cleanupForConfigChange?: boolean;
47
+ disableLogs?: boolean;
48
+ };
49
+ };
50
+ declare const useSmartSnapshot: (configs: OnSnapshotConfig[], options?: UseSmartSubscriptionSettings) => {
51
+ groupedConfig: {
52
+ configForDb: any[];
53
+ configForCache: any[];
54
+ };
55
+ socketConnected: boolean;
56
+ };
57
+
58
+ export { useDeepCompareEffect, useDeepCompareMemo, useDocumentTitle, useSafeEffect, useSetUserCountry, useSmartSnapshot, useSnapshotBulk, useSocketSubscription };
@@ -22,6 +22,8 @@ interface OnSnapshotConfig extends OnSnapshotParsers {
22
22
  fieldName: string;
23
23
  direction: "asc" | "desc";
24
24
  }[];
25
+ parseAs?: "object" | "array";
26
+ subscribeTo?: "cache" | "db";
25
27
  }
26
28
 
27
29
  declare const useDocumentTitle: (title: string) => any;
@@ -35,4 +37,22 @@ declare function useSafeEffect(callback: () => void, dependencies: any[], error_
35
37
  declare const useDeepCompareMemo: <T>(factory: () => T, dependencies: any[]) => T;
36
38
  declare function useDeepCompareEffect(effect: EffectCallback, dependencies: any[]): void;
37
39
 
38
- export { useDeepCompareEffect, useDeepCompareMemo, useDocumentTitle, useSafeEffect, useSetUserCountry, useSnapshotBulk };
40
+ declare const useSocketSubscription: (config: OnSnapshotConfig[]) => {
41
+ socketConnected: boolean;
42
+ };
43
+ type UseSmartSubscriptionSettings = {
44
+ label?: string;
45
+ settings?: {
46
+ cleanupForConfigChange?: boolean;
47
+ disableLogs?: boolean;
48
+ };
49
+ };
50
+ declare const useSmartSnapshot: (configs: OnSnapshotConfig[], options?: UseSmartSubscriptionSettings) => {
51
+ groupedConfig: {
52
+ configForDb: any[];
53
+ configForCache: any[];
54
+ };
55
+ socketConnected: boolean;
56
+ };
57
+
58
+ export { useDeepCompareEffect, useDeepCompareMemo, useDocumentTitle, useSafeEffect, useSetUserCountry, useSmartSnapshot, useSnapshotBulk, useSocketSubscription };