akeyless-client-commons 1.1.47 → 1.1.49

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.
@@ -1,4 +1,4 @@
1
- import { CountryOptions } from 'akeyless-types-commons';
1
+ import { CountryOptions, RedisUpdateType, RedisUpdatePayload, SocketCallbackResponse } from 'akeyless-types-commons';
2
2
  import { Dispatch, SetStateAction, EffectCallback } from 'react';
3
3
  import { WhereFilterOp } from 'firebase/firestore';
4
4
 
@@ -49,13 +49,48 @@ interface OnSnapshotConfig extends OnSnapshotParsers {
49
49
  subscribeTo?: "cache" | "db";
50
50
  }
51
51
 
52
+ interface GetDataPayload<T = any> {
53
+ key: string;
54
+ collection_name: string;
55
+ callback: (value: T) => void;
56
+ defaultValue: T;
57
+ }
58
+ declare class SocketService {
59
+ private static instance;
60
+ private socket;
61
+ private connectCallbacks;
62
+ private disconnectCallbacks;
63
+ private authToken;
64
+ private initSocket;
65
+ private constructor();
66
+ static getInstance(): SocketService;
67
+ private getSocketInstance;
68
+ startSession(token: string): void;
69
+ onConnect(callback: () => void): () => void;
70
+ offConnect(callback: () => void): void;
71
+ onDisconnect(callback: () => void): () => void;
72
+ offDisconnect(callback: () => void): void;
73
+ isConnected(): boolean;
74
+ setAuthToken(token: string): void;
75
+ disconnectSocket(): void;
76
+ subscribeToCollections(config: OnSnapshotConfig[]): () => void;
77
+ setData<UpdateType extends RedisUpdateType, DataType = any>(payload: RedisUpdatePayload<UpdateType, DataType>): Promise<SocketCallbackResponse>;
78
+ getCollectionData<T>(payload: Omit<GetDataPayload<T>, "key">): void;
79
+ getDocumentData<T>(payload: GetDataPayload<T>): void;
80
+ deleteData(payload: {
81
+ key: string;
82
+ collection_name: string;
83
+ }): Promise<SocketCallbackResponse>;
84
+ clearAllRedisData(): Promise<SocketCallbackResponse>;
85
+ }
86
+ declare const socketServiceInstance: SocketService;
87
+
52
88
  interface UseDbSnapshotsSettings {
53
89
  cleanupForConfigChange?: boolean;
54
90
  disableLogs?: boolean;
55
91
  worker?: UseWebWorkerOptions;
56
92
  socket?: {
57
- onDisconnect?: (unsubscribe: () => void) => void;
58
- onConnect?: (unsubscribe: () => void) => void;
93
+ getSocket?: (socket: typeof socketServiceInstance) => void;
59
94
  };
60
95
  }
61
96
  declare const useDbSnapshots: (configs: OnSnapshotConfig[], label?: string, settings?: UseDbSnapshotsSettings) => void;
@@ -1,4 +1,4 @@
1
- import { CountryOptions } from 'akeyless-types-commons';
1
+ import { CountryOptions, RedisUpdateType, RedisUpdatePayload, SocketCallbackResponse } from 'akeyless-types-commons';
2
2
  import { Dispatch, SetStateAction, EffectCallback } from 'react';
3
3
  import { WhereFilterOp } from 'firebase/firestore';
4
4
 
@@ -49,13 +49,48 @@ interface OnSnapshotConfig extends OnSnapshotParsers {
49
49
  subscribeTo?: "cache" | "db";
50
50
  }
51
51
 
52
+ interface GetDataPayload<T = any> {
53
+ key: string;
54
+ collection_name: string;
55
+ callback: (value: T) => void;
56
+ defaultValue: T;
57
+ }
58
+ declare class SocketService {
59
+ private static instance;
60
+ private socket;
61
+ private connectCallbacks;
62
+ private disconnectCallbacks;
63
+ private authToken;
64
+ private initSocket;
65
+ private constructor();
66
+ static getInstance(): SocketService;
67
+ private getSocketInstance;
68
+ startSession(token: string): void;
69
+ onConnect(callback: () => void): () => void;
70
+ offConnect(callback: () => void): void;
71
+ onDisconnect(callback: () => void): () => void;
72
+ offDisconnect(callback: () => void): void;
73
+ isConnected(): boolean;
74
+ setAuthToken(token: string): void;
75
+ disconnectSocket(): void;
76
+ subscribeToCollections(config: OnSnapshotConfig[]): () => void;
77
+ setData<UpdateType extends RedisUpdateType, DataType = any>(payload: RedisUpdatePayload<UpdateType, DataType>): Promise<SocketCallbackResponse>;
78
+ getCollectionData<T>(payload: Omit<GetDataPayload<T>, "key">): void;
79
+ getDocumentData<T>(payload: GetDataPayload<T>): void;
80
+ deleteData(payload: {
81
+ key: string;
82
+ collection_name: string;
83
+ }): Promise<SocketCallbackResponse>;
84
+ clearAllRedisData(): Promise<SocketCallbackResponse>;
85
+ }
86
+ declare const socketServiceInstance: SocketService;
87
+
52
88
  interface UseDbSnapshotsSettings {
53
89
  cleanupForConfigChange?: boolean;
54
90
  disableLogs?: boolean;
55
91
  worker?: UseWebWorkerOptions;
56
92
  socket?: {
57
- onDisconnect?: (unsubscribe: () => void) => void;
58
- onConnect?: (unsubscribe: () => void) => void;
93
+ getSocket?: (socket: typeof socketServiceInstance) => void;
59
94
  };
60
95
  }
61
96
  declare const useDbSnapshots: (configs: OnSnapshotConfig[], label?: string, settings?: UseDbSnapshotsSettings) => void;
@@ -1623,14 +1623,11 @@ var useSocketSnapshots = function(configs, label, settings) {
1623
1623
  (_offConnectRef_current = offConnectRef.current) === null || _offConnectRef_current === void 0 ? void 0 : _offConnectRef_current.call(offConnectRef);
1624
1624
  (_offDisconnectRef_current = offDisconnectRef.current) === null || _offDisconnectRef_current === void 0 ? void 0 : _offDisconnectRef_current.call(offDisconnectRef);
1625
1625
  offConnectRef.current = socketServiceInstance.onConnect(function() {
1626
- var _settings_socket_onConnect, _settings_socket;
1627
1626
  setSocketConnected(true);
1628
1627
  socketStarted.current = false;
1629
1628
  subscribe();
1630
- settings === null || settings === void 0 ? void 0 : (_settings_socket = settings.socket) === null || _settings_socket === void 0 ? void 0 : (_settings_socket_onConnect = _settings_socket.onConnect) === null || _settings_socket_onConnect === void 0 ? void 0 : _settings_socket_onConnect.call(_settings_socket, offConnectRef.current);
1631
1629
  });
1632
1630
  offDisconnectRef.current = socketServiceInstance.onDisconnect(function() {
1633
- var _settings_socket_onDisconnect, _settings_socket;
1634
1631
  setSocketConnected(false);
1635
1632
  cleanupSubscriptionsRef.current.forEach(function(cleanup) {
1636
1633
  return cleanup();
@@ -1638,7 +1635,6 @@ var useSocketSnapshots = function(configs, label, settings) {
1638
1635
  cleanupSubscriptionsRef.current = [];
1639
1636
  activeSubscriptionKeyRef.current = null;
1640
1637
  activeCollectionsRef.current = /* @__PURE__ */ new Set();
1641
- settings === null || settings === void 0 ? void 0 : (_settings_socket = settings.socket) === null || _settings_socket === void 0 ? void 0 : (_settings_socket_onDisconnect = _settings_socket.onDisconnect) === null || _settings_socket_onDisconnect === void 0 ? void 0 : _settings_socket_onDisconnect.call(_settings_socket, offDisconnectRef.current);
1642
1638
  });
1643
1639
  if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
1644
1640
  return function() {
@@ -1663,6 +1659,8 @@ var useSocketSnapshots = function(configs, label, settings) {
1663
1659
  (_auth_currentUser = auth.currentUser) === null || _auth_currentUser === void 0 ? void 0 : _auth_currentUser.uid
1664
1660
  ]);
1665
1661
  (0, import_react5.useEffect)(function() {
1662
+ var _settings_socket_getSocket, _settings_socket;
1663
+ settings === null || settings === void 0 ? void 0 : (_settings_socket = settings.socket) === null || _settings_socket === void 0 ? void 0 : (_settings_socket_getSocket = _settings_socket.getSocket) === null || _settings_socket_getSocket === void 0 ? void 0 : _settings_socket_getSocket.call(_settings_socket, socketServiceInstance);
1666
1664
  return function() {
1667
1665
  var _offConnectRef_current, _offDisconnectRef_current;
1668
1666
  cleanupSubscriptionsRef.current.forEach(function(cleanup) {
@@ -1526,14 +1526,11 @@ var useSocketSnapshots = function(configs, label, settings) {
1526
1526
  (_offConnectRef_current = offConnectRef.current) === null || _offConnectRef_current === void 0 ? void 0 : _offConnectRef_current.call(offConnectRef);
1527
1527
  (_offDisconnectRef_current = offDisconnectRef.current) === null || _offDisconnectRef_current === void 0 ? void 0 : _offDisconnectRef_current.call(offDisconnectRef);
1528
1528
  offConnectRef.current = socketServiceInstance.onConnect(function() {
1529
- var _settings_socket_onConnect, _settings_socket;
1530
1529
  setSocketConnected(true);
1531
1530
  socketStarted.current = false;
1532
1531
  subscribe();
1533
- settings === null || settings === void 0 ? void 0 : (_settings_socket = settings.socket) === null || _settings_socket === void 0 ? void 0 : (_settings_socket_onConnect = _settings_socket.onConnect) === null || _settings_socket_onConnect === void 0 ? void 0 : _settings_socket_onConnect.call(_settings_socket, offConnectRef.current);
1534
1532
  });
1535
1533
  offDisconnectRef.current = socketServiceInstance.onDisconnect(function() {
1536
- var _settings_socket_onDisconnect, _settings_socket;
1537
1534
  setSocketConnected(false);
1538
1535
  cleanupSubscriptionsRef.current.forEach(function(cleanup) {
1539
1536
  return cleanup();
@@ -1541,7 +1538,6 @@ var useSocketSnapshots = function(configs, label, settings) {
1541
1538
  cleanupSubscriptionsRef.current = [];
1542
1539
  activeSubscriptionKeyRef.current = null;
1543
1540
  activeCollectionsRef.current = /* @__PURE__ */ new Set();
1544
- settings === null || settings === void 0 ? void 0 : (_settings_socket = settings.socket) === null || _settings_socket === void 0 ? void 0 : (_settings_socket_onDisconnect = _settings_socket.onDisconnect) === null || _settings_socket_onDisconnect === void 0 ? void 0 : _settings_socket_onDisconnect.call(_settings_socket, offDisconnectRef.current);
1545
1541
  });
1546
1542
  if (settings === null || settings === void 0 ? void 0 : settings.cleanupForConfigChange) {
1547
1543
  return function() {
@@ -1566,6 +1562,8 @@ var useSocketSnapshots = function(configs, label, settings) {
1566
1562
  (_auth_currentUser = auth.currentUser) === null || _auth_currentUser === void 0 ? void 0 : _auth_currentUser.uid
1567
1563
  ]);
1568
1564
  useEffect4(function() {
1565
+ var _settings_socket_getSocket, _settings_socket;
1566
+ settings === null || settings === void 0 ? void 0 : (_settings_socket = settings.socket) === null || _settings_socket === void 0 ? void 0 : (_settings_socket_getSocket = _settings_socket.getSocket) === null || _settings_socket_getSocket === void 0 ? void 0 : _settings_socket_getSocket.call(_settings_socket, socketServiceInstance);
1569
1567
  return function() {
1570
1568
  var _offConnectRef_current, _offDisconnectRef_current;
1571
1569
  cleanupSubscriptionsRef.current.forEach(function(cleanup) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akeyless-client-commons",
3
- "version": "1.1.47",
3
+ "version": "1.1.49",
4
4
  "scripts": {
5
5
  "build": "tsup",
6
6
  "deploy": "npm run build && npm version patch --no-git-tag-version && npm publish",