akeyless-client-commons 1.1.22 → 1.1.24
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/components/index.js +315 -6
- package/dist/components/index.mjs +315 -6
- package/dist/components/index.mjs.map +1 -1
- package/dist/helpers/index.d.mts +44 -4
- package/dist/helpers/index.d.ts +44 -4
- package/dist/helpers/index.js +346 -0
- package/dist/helpers/index.mjs +335 -1
- package/dist/hooks/index.d.mts +27 -8
- package/dist/hooks/index.d.ts +27 -8
- package/dist/hooks/index.js +619 -66
- package/dist/hooks/index.mjs +609 -64
- package/dist/types/index.d.mts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +5 -2
package/dist/helpers/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { FirebaseStorage } from 'firebase/storage';
|
|
|
3
3
|
import { Auth, GoogleAuthProvider, User } from 'firebase/auth';
|
|
4
4
|
import { AppCheck } from 'firebase/app-check';
|
|
5
5
|
import { WhereFilterOp, Unsubscribe, Firestore, CollectionReference, DocumentData, Timestamp, DocumentSnapshot } from 'firebase/firestore';
|
|
6
|
-
import { TObject, NxUser, CountryOptions, LanguageOptions, UserPermissionsObject, userPermissionsObjectValue, Client } from 'akeyless-types-commons';
|
|
6
|
+
import { TObject, NxUser, CountryOptions, LanguageOptions, firebase_timestamp, UserPermissionsObject, userPermissionsObjectValue, Client, RedisUpdateType, RedisUpdatePayload, SocketCallbackResponse } from 'akeyless-types-commons';
|
|
7
7
|
import React, { Dispatch, SetStateAction } from 'react';
|
|
8
8
|
import { ClassValue } from 'clsx';
|
|
9
9
|
|
|
@@ -31,6 +31,8 @@ interface OnSnapshotConfig extends OnSnapshotParsers {
|
|
|
31
31
|
fieldName: string;
|
|
32
32
|
direction: "asc" | "desc";
|
|
33
33
|
}[];
|
|
34
|
+
parseAs?: "object" | "array";
|
|
35
|
+
subscribeTo?: "cache" | "db";
|
|
34
36
|
}
|
|
35
37
|
interface OnSnapshotConfigDocument extends Omit<OnSnapshotParsers, "onAdd"> {
|
|
36
38
|
collectionName: string;
|
|
@@ -232,7 +234,7 @@ interface TimeOptions {
|
|
|
232
234
|
tz?: string;
|
|
233
235
|
defaultReturnedValue?: string;
|
|
234
236
|
}
|
|
235
|
-
declare function timestamp_to_string(firebaseTimestamp: Timestamp | Date | string, options?: TimeOptions): string;
|
|
237
|
+
declare function timestamp_to_string(firebaseTimestamp: Timestamp | Date | string | firebase_timestamp, options?: TimeOptions): string;
|
|
236
238
|
declare function timestamp_to_millis(firebaseTimestamp: Timestamp): number;
|
|
237
239
|
declare function sort_by_timestamp(a: Timestamp, b: Timestamp, reverse?: boolean): number;
|
|
238
240
|
|
|
@@ -242,9 +244,11 @@ declare const biDomain: string;
|
|
|
242
244
|
declare const notificationsDomain: string;
|
|
243
245
|
declare const callCenterGeoDomain: string;
|
|
244
246
|
declare const callCenterEventsDomain: string;
|
|
247
|
+
declare const dataSocketDomain: string;
|
|
248
|
+
declare const dataSyncDomain: string;
|
|
245
249
|
declare const akeylessOnlineDomain: string;
|
|
246
250
|
type Method = "GET" | "POST" | "PUT" | "DELETE";
|
|
247
|
-
type ServerName = "devices" | "bi" | "call-center-geo" | "call-center-events" | "notifications";
|
|
251
|
+
type ServerName = "devices" | "bi" | "call-center-geo" | "call-center-events" | "notifications" | "data-socket" | "data-sync";
|
|
248
252
|
declare const nxApiCall: (serverName: ServerName, method: Method, url: string, data?: TObject<any>) => Promise<any>;
|
|
249
253
|
|
|
250
254
|
declare const checkUserPermissions: <T extends keyof UserPermissionsObject>(userPermissions: UserPermissionsObject, entity: T, permissions?: userPermissionsObjectValue<T>[], mode?: "some" | "every") => boolean;
|
|
@@ -269,4 +273,40 @@ interface EmailAttachment {
|
|
|
269
273
|
declare const createAttachmentFromBlob: (blob: Blob, filename: string, mimeType?: string, disposition?: "attachment" | "inline") => Promise<EmailAttachment>;
|
|
270
274
|
declare const createAttachmentFromUrl: (url: string, filename?: string) => Promise<EmailAttachment>;
|
|
271
275
|
|
|
272
|
-
|
|
276
|
+
interface GetDataPayload<T = any> {
|
|
277
|
+
key: string;
|
|
278
|
+
collection_name: string;
|
|
279
|
+
callback: (value: T) => void;
|
|
280
|
+
defaultValue: T;
|
|
281
|
+
}
|
|
282
|
+
declare class SocketService {
|
|
283
|
+
private static instance;
|
|
284
|
+
private socket;
|
|
285
|
+
private connectCallbacks;
|
|
286
|
+
private disconnectCallbacks;
|
|
287
|
+
private authToken;
|
|
288
|
+
private initSocket;
|
|
289
|
+
private constructor();
|
|
290
|
+
static getInstance(): SocketService;
|
|
291
|
+
private getSocketInstance;
|
|
292
|
+
startSession(token: string): void;
|
|
293
|
+
onConnect(callback: () => void): () => void;
|
|
294
|
+
offConnect(callback: () => void): void;
|
|
295
|
+
onDisconnect(callback: () => void): () => void;
|
|
296
|
+
offDisconnect(callback: () => void): void;
|
|
297
|
+
isConnected(): boolean;
|
|
298
|
+
setAuthToken(token: string): void;
|
|
299
|
+
disconnectSocket(): void;
|
|
300
|
+
subscribeToCollections(config: OnSnapshotConfig[]): () => void;
|
|
301
|
+
setData<UpdateType extends RedisUpdateType, DataType = any>(payload: RedisUpdatePayload<UpdateType, DataType>): Promise<SocketCallbackResponse>;
|
|
302
|
+
getCollectionData<T>(payload: Omit<GetDataPayload<T>, "key">): void;
|
|
303
|
+
getDocumentData<T>(payload: GetDataPayload<T>): void;
|
|
304
|
+
deleteData(payload: {
|
|
305
|
+
key: string;
|
|
306
|
+
collection_name: string;
|
|
307
|
+
}): Promise<SocketCallbackResponse>;
|
|
308
|
+
clearAllRedisData(): Promise<SocketCallbackResponse>;
|
|
309
|
+
}
|
|
310
|
+
declare const socketServiceInstance: SocketService;
|
|
311
|
+
|
|
312
|
+
export { type EmailAttachment, type ValidationType, addAuditRecord, addLoginAudit, add_document, addressRegex, akeylessOnlineDomain, app, appCheck, auth, baseDomain, biDomain, calculateBearing, callCenterEventsDomain, callCenterGeoDomain, carsRegex, chartsRegex, checkUserPermissions, cleanNxSites, cn, collections, colorRegex, createAttachmentFromBlob, createAttachmentFromUrl, createSelectors, dataSocketDomain, dataSyncDomain, db, delete_document, devicesDomain, displayFormatPhoneNumber, durationToSeconds, emailRegex, extractAlertsData, extractBoardsData, extractCanbusData, extractCarsData, extractClientData, extractLocationData, extractSiteData, fire_base_TIME_TEMP, formatCarNumber, getAddressByGeo, getFileUrlFromStorage, 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, uploadFileToStorage, useLoginWithGoogle, useStoreValues, useValidation, userNameFormat, validateAndCast, validateUserStatusAndPermissions };
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { FirebaseStorage } from 'firebase/storage';
|
|
|
3
3
|
import { Auth, GoogleAuthProvider, User } from 'firebase/auth';
|
|
4
4
|
import { AppCheck } from 'firebase/app-check';
|
|
5
5
|
import { WhereFilterOp, Unsubscribe, Firestore, CollectionReference, DocumentData, Timestamp, DocumentSnapshot } from 'firebase/firestore';
|
|
6
|
-
import { TObject, NxUser, CountryOptions, LanguageOptions, UserPermissionsObject, userPermissionsObjectValue, Client } from 'akeyless-types-commons';
|
|
6
|
+
import { TObject, NxUser, CountryOptions, LanguageOptions, firebase_timestamp, UserPermissionsObject, userPermissionsObjectValue, Client, RedisUpdateType, RedisUpdatePayload, SocketCallbackResponse } from 'akeyless-types-commons';
|
|
7
7
|
import React, { Dispatch, SetStateAction } from 'react';
|
|
8
8
|
import { ClassValue } from 'clsx';
|
|
9
9
|
|
|
@@ -31,6 +31,8 @@ interface OnSnapshotConfig extends OnSnapshotParsers {
|
|
|
31
31
|
fieldName: string;
|
|
32
32
|
direction: "asc" | "desc";
|
|
33
33
|
}[];
|
|
34
|
+
parseAs?: "object" | "array";
|
|
35
|
+
subscribeTo?: "cache" | "db";
|
|
34
36
|
}
|
|
35
37
|
interface OnSnapshotConfigDocument extends Omit<OnSnapshotParsers, "onAdd"> {
|
|
36
38
|
collectionName: string;
|
|
@@ -232,7 +234,7 @@ interface TimeOptions {
|
|
|
232
234
|
tz?: string;
|
|
233
235
|
defaultReturnedValue?: string;
|
|
234
236
|
}
|
|
235
|
-
declare function timestamp_to_string(firebaseTimestamp: Timestamp | Date | string, options?: TimeOptions): string;
|
|
237
|
+
declare function timestamp_to_string(firebaseTimestamp: Timestamp | Date | string | firebase_timestamp, options?: TimeOptions): string;
|
|
236
238
|
declare function timestamp_to_millis(firebaseTimestamp: Timestamp): number;
|
|
237
239
|
declare function sort_by_timestamp(a: Timestamp, b: Timestamp, reverse?: boolean): number;
|
|
238
240
|
|
|
@@ -242,9 +244,11 @@ declare const biDomain: string;
|
|
|
242
244
|
declare const notificationsDomain: string;
|
|
243
245
|
declare const callCenterGeoDomain: string;
|
|
244
246
|
declare const callCenterEventsDomain: string;
|
|
247
|
+
declare const dataSocketDomain: string;
|
|
248
|
+
declare const dataSyncDomain: string;
|
|
245
249
|
declare const akeylessOnlineDomain: string;
|
|
246
250
|
type Method = "GET" | "POST" | "PUT" | "DELETE";
|
|
247
|
-
type ServerName = "devices" | "bi" | "call-center-geo" | "call-center-events" | "notifications";
|
|
251
|
+
type ServerName = "devices" | "bi" | "call-center-geo" | "call-center-events" | "notifications" | "data-socket" | "data-sync";
|
|
248
252
|
declare const nxApiCall: (serverName: ServerName, method: Method, url: string, data?: TObject<any>) => Promise<any>;
|
|
249
253
|
|
|
250
254
|
declare const checkUserPermissions: <T extends keyof UserPermissionsObject>(userPermissions: UserPermissionsObject, entity: T, permissions?: userPermissionsObjectValue<T>[], mode?: "some" | "every") => boolean;
|
|
@@ -269,4 +273,40 @@ interface EmailAttachment {
|
|
|
269
273
|
declare const createAttachmentFromBlob: (blob: Blob, filename: string, mimeType?: string, disposition?: "attachment" | "inline") => Promise<EmailAttachment>;
|
|
270
274
|
declare const createAttachmentFromUrl: (url: string, filename?: string) => Promise<EmailAttachment>;
|
|
271
275
|
|
|
272
|
-
|
|
276
|
+
interface GetDataPayload<T = any> {
|
|
277
|
+
key: string;
|
|
278
|
+
collection_name: string;
|
|
279
|
+
callback: (value: T) => void;
|
|
280
|
+
defaultValue: T;
|
|
281
|
+
}
|
|
282
|
+
declare class SocketService {
|
|
283
|
+
private static instance;
|
|
284
|
+
private socket;
|
|
285
|
+
private connectCallbacks;
|
|
286
|
+
private disconnectCallbacks;
|
|
287
|
+
private authToken;
|
|
288
|
+
private initSocket;
|
|
289
|
+
private constructor();
|
|
290
|
+
static getInstance(): SocketService;
|
|
291
|
+
private getSocketInstance;
|
|
292
|
+
startSession(token: string): void;
|
|
293
|
+
onConnect(callback: () => void): () => void;
|
|
294
|
+
offConnect(callback: () => void): void;
|
|
295
|
+
onDisconnect(callback: () => void): () => void;
|
|
296
|
+
offDisconnect(callback: () => void): void;
|
|
297
|
+
isConnected(): boolean;
|
|
298
|
+
setAuthToken(token: string): void;
|
|
299
|
+
disconnectSocket(): void;
|
|
300
|
+
subscribeToCollections(config: OnSnapshotConfig[]): () => void;
|
|
301
|
+
setData<UpdateType extends RedisUpdateType, DataType = any>(payload: RedisUpdatePayload<UpdateType, DataType>): Promise<SocketCallbackResponse>;
|
|
302
|
+
getCollectionData<T>(payload: Omit<GetDataPayload<T>, "key">): void;
|
|
303
|
+
getDocumentData<T>(payload: GetDataPayload<T>): void;
|
|
304
|
+
deleteData(payload: {
|
|
305
|
+
key: string;
|
|
306
|
+
collection_name: string;
|
|
307
|
+
}): Promise<SocketCallbackResponse>;
|
|
308
|
+
clearAllRedisData(): Promise<SocketCallbackResponse>;
|
|
309
|
+
}
|
|
310
|
+
declare const socketServiceInstance: SocketService;
|
|
311
|
+
|
|
312
|
+
export { type EmailAttachment, type ValidationType, addAuditRecord, addLoginAudit, add_document, addressRegex, akeylessOnlineDomain, app, appCheck, auth, baseDomain, biDomain, calculateBearing, callCenterEventsDomain, callCenterGeoDomain, carsRegex, chartsRegex, checkUserPermissions, cleanNxSites, cn, collections, colorRegex, createAttachmentFromBlob, createAttachmentFromUrl, createSelectors, dataSocketDomain, dataSyncDomain, db, delete_document, devicesDomain, displayFormatPhoneNumber, durationToSeconds, emailRegex, extractAlertsData, extractBoardsData, extractCanbusData, extractCarsData, extractClientData, extractLocationData, extractSiteData, fire_base_TIME_TEMP, formatCarNumber, getAddressByGeo, getFileUrlFromStorage, 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, uploadFileToStorage, useLoginWithGoogle, useStoreValues, useValidation, userNameFormat, validateAndCast, validateUserStatusAndPermissions };
|
package/dist/helpers/index.js
CHANGED
|
@@ -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, {
|
|
@@ -374,6 +393,12 @@ __export(index_exports, {
|
|
|
374
393
|
createSelectors: function() {
|
|
375
394
|
return createSelectors;
|
|
376
395
|
},
|
|
396
|
+
dataSocketDomain: function() {
|
|
397
|
+
return dataSocketDomain;
|
|
398
|
+
},
|
|
399
|
+
dataSyncDomain: function() {
|
|
400
|
+
return dataSyncDomain;
|
|
401
|
+
},
|
|
377
402
|
db: function() {
|
|
378
403
|
return db;
|
|
379
404
|
},
|
|
@@ -563,6 +588,9 @@ __export(index_exports, {
|
|
|
563
588
|
snapshotDocument: function() {
|
|
564
589
|
return snapshotDocument;
|
|
565
590
|
},
|
|
591
|
+
socketServiceInstance: function() {
|
|
592
|
+
return socketServiceInstance;
|
|
593
|
+
},
|
|
566
594
|
sort_by_timestamp: function() {
|
|
567
595
|
return sort_by_timestamp;
|
|
568
596
|
},
|
|
@@ -2248,6 +2276,8 @@ function timestamp_to_string(firebaseTimestamp, options) {
|
|
|
2248
2276
|
date = firebaseTimestamp.toDate();
|
|
2249
2277
|
} else if (_instanceof(firebaseTimestamp, Date)) {
|
|
2250
2278
|
date = firebaseTimestamp;
|
|
2279
|
+
} else if (firebaseTimestamp._seconds && firebaseTimestamp._nanoseconds) {
|
|
2280
|
+
date = new Date(firebaseTimestamp._seconds * 1e3 + firebaseTimestamp._nanoseconds / 1e6);
|
|
2251
2281
|
} else if (typeof firebaseTimestamp === "string") {
|
|
2252
2282
|
date = import_moment_timezone.default.utc(firebaseTimestamp, (options === null || options === void 0 ? void 0 : options.fromFormat) || "DD/MM/YYYY HH:mm:ss").toDate();
|
|
2253
2283
|
if (isNaN(date.getTime())) {
|
|
@@ -2283,6 +2313,8 @@ var biDomain = isLocal ? "http://localhost:9002/api/bi" : baseDomain + "/bi";
|
|
|
2283
2313
|
var notificationsDomain = isLocal ? "http://localhost:9006/api/notifications" : baseDomain + "/notifications";
|
|
2284
2314
|
var callCenterGeoDomain = isLocal ? "http://localhost:9007/api/call-center/geo" : baseDomain + "/call-center/geo";
|
|
2285
2315
|
var callCenterEventsDomain = isLocal ? "http://localhost:9008/api/call-center/events" : baseDomain + "/call-center/events";
|
|
2316
|
+
var dataSocketDomain = isLocal ? "http://localhost:9009/api/data-socket" : baseDomain + "/data-socket";
|
|
2317
|
+
var dataSyncDomain = isLocal ? "http://localhost:9010/api/data-sync" : baseDomain + "/data-sync";
|
|
2286
2318
|
var akeylessOnlineDomain = mode === "qa" ? "https://akeyless-online.xyz" : "https://akeyless-online.info";
|
|
2287
2319
|
var nxApiCall = /*#__PURE__*/ function() {
|
|
2288
2320
|
var _ref = _async_to_generator(function(serverName, method, url, data) {
|
|
@@ -2313,6 +2345,12 @@ var nxApiCall = /*#__PURE__*/ function() {
|
|
|
2313
2345
|
case "call-center-geo":
|
|
2314
2346
|
urlResult = "".concat(callCenterGeoDomain, "/").concat(url);
|
|
2315
2347
|
break;
|
|
2348
|
+
case "data-socket":
|
|
2349
|
+
urlResult = "".concat(dataSocketDomain, "/").concat(url);
|
|
2350
|
+
break;
|
|
2351
|
+
case "data-sync":
|
|
2352
|
+
urlResult = "".concat(dataSyncDomain, "/").concat(url);
|
|
2353
|
+
break;
|
|
2316
2354
|
default:
|
|
2317
2355
|
break;
|
|
2318
2356
|
}
|
|
@@ -2466,6 +2504,311 @@ var createAttachmentFromUrl = /*#__PURE__*/ function() {
|
|
|
2466
2504
|
return _ref.apply(this, arguments);
|
|
2467
2505
|
};
|
|
2468
2506
|
}();
|
|
2507
|
+
// src/helpers/socket.ts
|
|
2508
|
+
var import_socket = require("socket.io-client");
|
|
2509
|
+
var SESSION_STORAGE_KEY = "sessionId";
|
|
2510
|
+
var SocketService = /*#__PURE__*/ function() {
|
|
2511
|
+
"use strict";
|
|
2512
|
+
function _SocketService() {
|
|
2513
|
+
_class_call_check(this, _SocketService);
|
|
2514
|
+
this.socket = null;
|
|
2515
|
+
this.connectCallbacks = [];
|
|
2516
|
+
this.disconnectCallbacks = [];
|
|
2517
|
+
this.authToken = null;
|
|
2518
|
+
}
|
|
2519
|
+
_create_class(_SocketService, [
|
|
2520
|
+
{
|
|
2521
|
+
/// Initialize the socket connection
|
|
2522
|
+
key: "initSocket",
|
|
2523
|
+
value: function initSocket() {
|
|
2524
|
+
var _this = this;
|
|
2525
|
+
if (!this.socket) {
|
|
2526
|
+
var socketUrl = isLocal ? "http://localhost:9009" : mode === "qa" ? "https://nx-api.xyz" : "https://nx-api.info";
|
|
2527
|
+
this.socket = (0, import_socket.io)(socketUrl, {
|
|
2528
|
+
path: "/api/data-socket/connect",
|
|
2529
|
+
auth: function(cb) {
|
|
2530
|
+
var sessionId = localStorage.getItem(SESSION_STORAGE_KEY) || void 0;
|
|
2531
|
+
var token = _this.authToken;
|
|
2532
|
+
var authPayload = {};
|
|
2533
|
+
if (token) authPayload.token = token;
|
|
2534
|
+
if (sessionId) authPayload.sessionId = sessionId;
|
|
2535
|
+
cb(authPayload);
|
|
2536
|
+
},
|
|
2537
|
+
transports: [
|
|
2538
|
+
"websocket"
|
|
2539
|
+
],
|
|
2540
|
+
reconnection: true,
|
|
2541
|
+
reconnectionAttempts: 30,
|
|
2542
|
+
reconnectionDelay: 2 * 1e3
|
|
2543
|
+
});
|
|
2544
|
+
this.socket.on("connect", function() {
|
|
2545
|
+
var _this_socket, _this_socket1;
|
|
2546
|
+
console.log("\uD83D\uDFE2 Socket connected: ".concat((_this_socket = _this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.id, " (recovered - ").concat((_this_socket1 = _this.socket) === null || _this_socket1 === void 0 ? void 0 : _this_socket1.recovered, ")"));
|
|
2547
|
+
_this.connectCallbacks.forEach(function(cb) {
|
|
2548
|
+
return cb();
|
|
2549
|
+
});
|
|
2550
|
+
});
|
|
2551
|
+
this.socket.on("disconnect", function(reason) {
|
|
2552
|
+
console.log("Socket disconnected:", reason);
|
|
2553
|
+
_this.disconnectCallbacks.forEach(function(cb) {
|
|
2554
|
+
return cb();
|
|
2555
|
+
});
|
|
2556
|
+
});
|
|
2557
|
+
this.socket.on("session", function(param) {
|
|
2558
|
+
var session_id = param.session_id;
|
|
2559
|
+
if (session_id) {
|
|
2560
|
+
localStorage.setItem(SESSION_STORAGE_KEY, session_id);
|
|
2561
|
+
}
|
|
2562
|
+
});
|
|
2563
|
+
this.socket.on("connect_error", function(error) {
|
|
2564
|
+
console.error("Socket connection error:", error);
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
},
|
|
2569
|
+
{
|
|
2570
|
+
/// get socket instance
|
|
2571
|
+
key: "getSocketInstance",
|
|
2572
|
+
value: function getSocketInstance() {
|
|
2573
|
+
if (!this.socket) {
|
|
2574
|
+
this.initSocket();
|
|
2575
|
+
}
|
|
2576
|
+
if (!this.socket) {
|
|
2577
|
+
throw new Error("Socket not initialized");
|
|
2578
|
+
}
|
|
2579
|
+
if (!this.socket.connected) {
|
|
2580
|
+
this.socket.connect();
|
|
2581
|
+
}
|
|
2582
|
+
return this.socket;
|
|
2583
|
+
}
|
|
2584
|
+
},
|
|
2585
|
+
{
|
|
2586
|
+
/// connection management methods
|
|
2587
|
+
key: "startSession",
|
|
2588
|
+
value: function startSession(token) {
|
|
2589
|
+
this.setAuthToken(token);
|
|
2590
|
+
this.initSocket();
|
|
2591
|
+
}
|
|
2592
|
+
},
|
|
2593
|
+
{
|
|
2594
|
+
key: "onConnect",
|
|
2595
|
+
value: function onConnect(callback) {
|
|
2596
|
+
var _this = this;
|
|
2597
|
+
var _this_socket;
|
|
2598
|
+
if (!this.connectCallbacks.includes(callback)) {
|
|
2599
|
+
this.connectCallbacks.push(callback);
|
|
2600
|
+
}
|
|
2601
|
+
if ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) {
|
|
2602
|
+
callback();
|
|
2603
|
+
}
|
|
2604
|
+
return function() {
|
|
2605
|
+
return _this.offConnect(callback);
|
|
2606
|
+
};
|
|
2607
|
+
}
|
|
2608
|
+
},
|
|
2609
|
+
{
|
|
2610
|
+
key: "offConnect",
|
|
2611
|
+
value: function offConnect(callback) {
|
|
2612
|
+
this.connectCallbacks = this.connectCallbacks.filter(function(cb) {
|
|
2613
|
+
return cb !== callback;
|
|
2614
|
+
});
|
|
2615
|
+
}
|
|
2616
|
+
},
|
|
2617
|
+
{
|
|
2618
|
+
key: "onDisconnect",
|
|
2619
|
+
value: function onDisconnect(callback) {
|
|
2620
|
+
var _this = this;
|
|
2621
|
+
if (!this.disconnectCallbacks.includes(callback)) {
|
|
2622
|
+
this.disconnectCallbacks.push(callback);
|
|
2623
|
+
}
|
|
2624
|
+
if (this.socket && !this.socket.connected) {
|
|
2625
|
+
callback();
|
|
2626
|
+
}
|
|
2627
|
+
return function() {
|
|
2628
|
+
return _this.offDisconnect(callback);
|
|
2629
|
+
};
|
|
2630
|
+
}
|
|
2631
|
+
},
|
|
2632
|
+
{
|
|
2633
|
+
key: "offDisconnect",
|
|
2634
|
+
value: function offDisconnect(callback) {
|
|
2635
|
+
this.disconnectCallbacks = this.disconnectCallbacks.filter(function(cb) {
|
|
2636
|
+
return cb !== callback;
|
|
2637
|
+
});
|
|
2638
|
+
}
|
|
2639
|
+
},
|
|
2640
|
+
{
|
|
2641
|
+
key: "isConnected",
|
|
2642
|
+
value: function isConnected() {
|
|
2643
|
+
var _this_socket;
|
|
2644
|
+
return ((_this_socket = this.socket) === null || _this_socket === void 0 ? void 0 : _this_socket.connected) || false;
|
|
2645
|
+
}
|
|
2646
|
+
},
|
|
2647
|
+
{
|
|
2648
|
+
key: "setAuthToken",
|
|
2649
|
+
value: function setAuthToken(token) {
|
|
2650
|
+
this.authToken = token;
|
|
2651
|
+
if (this.socket) {
|
|
2652
|
+
this.socket.connect();
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
},
|
|
2656
|
+
{
|
|
2657
|
+
key: "disconnectSocket",
|
|
2658
|
+
value: function disconnectSocket() {
|
|
2659
|
+
if (this.socket) {
|
|
2660
|
+
this.socket.io.engine.close();
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
},
|
|
2664
|
+
{
|
|
2665
|
+
/// subscribe to collections
|
|
2666
|
+
key: "subscribeToCollections",
|
|
2667
|
+
value: function subscribeToCollections(config) {
|
|
2668
|
+
var _this = this;
|
|
2669
|
+
if (config.length === 0) {
|
|
2670
|
+
return function() {};
|
|
2671
|
+
}
|
|
2672
|
+
var s = this.getSocketInstance();
|
|
2673
|
+
var collectionsNames = config.map(function(c) {
|
|
2674
|
+
return c.collectionName;
|
|
2675
|
+
});
|
|
2676
|
+
var eventHandlers = [];
|
|
2677
|
+
config.forEach(function(configuration) {
|
|
2678
|
+
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;
|
|
2679
|
+
var attach = function(eventName, handler) {
|
|
2680
|
+
_this.socket.off(eventName, handler);
|
|
2681
|
+
_this.socket.on(eventName, handler);
|
|
2682
|
+
eventHandlers.push({
|
|
2683
|
+
eventName: eventName,
|
|
2684
|
+
handler: handler
|
|
2685
|
+
});
|
|
2686
|
+
};
|
|
2687
|
+
attach("initial:".concat(collectionName), onFirstTime);
|
|
2688
|
+
attach("add:".concat(collectionName), onAdd);
|
|
2689
|
+
attach("update:".concat(collectionName), onModify);
|
|
2690
|
+
attach("delete:".concat(collectionName), onRemove);
|
|
2691
|
+
extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
|
|
2692
|
+
var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
|
|
2693
|
+
attach("initial:".concat(collectionName), extraOnFirstTime);
|
|
2694
|
+
attach("add:".concat(collectionName), extraOnAdd);
|
|
2695
|
+
attach("update:".concat(collectionName), extraOnModify);
|
|
2696
|
+
attach("delete:".concat(collectionName), extraOnRemove);
|
|
2697
|
+
});
|
|
2698
|
+
});
|
|
2699
|
+
s.emit("subscribe_collections", collectionsNames, function(callback) {
|
|
2700
|
+
if (callback.success) {
|
|
2701
|
+
console.log("Successfully subscribed to: ".concat(collectionsNames.join(", ")));
|
|
2702
|
+
} else {
|
|
2703
|
+
console.error("Failed to subscribe to ".concat(config.join(", "), ": ").concat(callback.message));
|
|
2704
|
+
}
|
|
2705
|
+
});
|
|
2706
|
+
return function() {
|
|
2707
|
+
console.log("Cleaning up subscriptions for: ".concat(collectionsNames.join(", ")));
|
|
2708
|
+
s.emit("unsubscribe_collections", collectionsNames);
|
|
2709
|
+
eventHandlers.forEach(function(eh) {
|
|
2710
|
+
s.off(eh.eventName, eh.handler);
|
|
2711
|
+
});
|
|
2712
|
+
};
|
|
2713
|
+
}
|
|
2714
|
+
},
|
|
2715
|
+
{
|
|
2716
|
+
/// set data
|
|
2717
|
+
key: "setData",
|
|
2718
|
+
value: function setData(payload) {
|
|
2719
|
+
var s = this.getSocketInstance();
|
|
2720
|
+
return new Promise(function(resolve, reject) {
|
|
2721
|
+
s.emit("set_data", payload, function(callback) {
|
|
2722
|
+
if (callback.success) {
|
|
2723
|
+
console.log("Data saved successfully:", payload);
|
|
2724
|
+
console.log("ack", callback);
|
|
2725
|
+
resolve(callback);
|
|
2726
|
+
} else {
|
|
2727
|
+
reject(new Error(callback.message || "Save operation failed"));
|
|
2728
|
+
}
|
|
2729
|
+
});
|
|
2730
|
+
});
|
|
2731
|
+
}
|
|
2732
|
+
},
|
|
2733
|
+
{
|
|
2734
|
+
/// get data
|
|
2735
|
+
key: "getCollectionData",
|
|
2736
|
+
value: function getCollectionData(payload) {
|
|
2737
|
+
var s = this.getSocketInstance();
|
|
2738
|
+
s.emit("get_data", {
|
|
2739
|
+
collection_name: payload.collection_name
|
|
2740
|
+
}, function(socketCallback) {
|
|
2741
|
+
if (socketCallback.success && socketCallback.data) {
|
|
2742
|
+
payload.callback(socketCallback.data);
|
|
2743
|
+
} else {
|
|
2744
|
+
payload.callback(payload.defaultValue);
|
|
2745
|
+
}
|
|
2746
|
+
});
|
|
2747
|
+
}
|
|
2748
|
+
},
|
|
2749
|
+
{
|
|
2750
|
+
key: "getDocumentData",
|
|
2751
|
+
value: function getDocumentData(payload) {
|
|
2752
|
+
var s = this.getSocketInstance();
|
|
2753
|
+
s.emit("get_data", {
|
|
2754
|
+
collection_name: payload.collection_name,
|
|
2755
|
+
key: payload.key
|
|
2756
|
+
}, function(socketCallback) {
|
|
2757
|
+
if (socketCallback.success && socketCallback.data) {
|
|
2758
|
+
payload.callback(socketCallback.data);
|
|
2759
|
+
} else {
|
|
2760
|
+
payload.callback(payload.defaultValue);
|
|
2761
|
+
}
|
|
2762
|
+
});
|
|
2763
|
+
}
|
|
2764
|
+
},
|
|
2765
|
+
{
|
|
2766
|
+
/// delete data
|
|
2767
|
+
key: "deleteData",
|
|
2768
|
+
value: function deleteData(payload) {
|
|
2769
|
+
var s = this.getSocketInstance();
|
|
2770
|
+
return new Promise(function(resolve, reject) {
|
|
2771
|
+
s.emit("delete_data", payload, function(callback) {
|
|
2772
|
+
if (callback.success) {
|
|
2773
|
+
console.log("Data deleted successfully:", payload);
|
|
2774
|
+
console.log("delete ack", callback);
|
|
2775
|
+
resolve(callback);
|
|
2776
|
+
} else {
|
|
2777
|
+
reject(new Error(callback.message || "Delete operation failed"));
|
|
2778
|
+
}
|
|
2779
|
+
});
|
|
2780
|
+
});
|
|
2781
|
+
}
|
|
2782
|
+
},
|
|
2783
|
+
{
|
|
2784
|
+
key: "clearAllRedisData",
|
|
2785
|
+
value: function clearAllRedisData() {
|
|
2786
|
+
var s = this.getSocketInstance();
|
|
2787
|
+
return new Promise(function(resolve, reject) {
|
|
2788
|
+
s.emit("clear_all_redis_data", function(ack) {
|
|
2789
|
+
if (ack.success) {
|
|
2790
|
+
resolve(ack);
|
|
2791
|
+
} else {
|
|
2792
|
+
reject(new Error(ack.message || "Clear all Redis data operation failed"));
|
|
2793
|
+
}
|
|
2794
|
+
});
|
|
2795
|
+
});
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
], [
|
|
2799
|
+
{
|
|
2800
|
+
key: "getInstance",
|
|
2801
|
+
value: function getInstance() {
|
|
2802
|
+
if (!_SocketService.instance) {
|
|
2803
|
+
_SocketService.instance = new _SocketService();
|
|
2804
|
+
}
|
|
2805
|
+
return _SocketService.instance;
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
]);
|
|
2809
|
+
return _SocketService;
|
|
2810
|
+
}();
|
|
2811
|
+
var socketServiceInstance = SocketService.getInstance();
|
|
2469
2812
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2470
2813
|
0 && (module.exports = {
|
|
2471
2814
|
addAuditRecord: addAuditRecord,
|
|
@@ -2491,6 +2834,8 @@ var createAttachmentFromUrl = /*#__PURE__*/ function() {
|
|
|
2491
2834
|
createAttachmentFromBlob: createAttachmentFromBlob,
|
|
2492
2835
|
createAttachmentFromUrl: createAttachmentFromUrl,
|
|
2493
2836
|
createSelectors: createSelectors,
|
|
2837
|
+
dataSocketDomain: dataSocketDomain,
|
|
2838
|
+
dataSyncDomain: dataSyncDomain,
|
|
2494
2839
|
db: db,
|
|
2495
2840
|
delete_document: delete_document,
|
|
2496
2841
|
devicesDomain: devicesDomain,
|
|
@@ -2554,6 +2899,7 @@ var createAttachmentFromUrl = /*#__PURE__*/ function() {
|
|
|
2554
2899
|
simpleExtractData: simpleExtractData,
|
|
2555
2900
|
snapshot: snapshot,
|
|
2556
2901
|
snapshotDocument: snapshotDocument,
|
|
2902
|
+
socketServiceInstance: socketServiceInstance,
|
|
2557
2903
|
sort_by_timestamp: sort_by_timestamp,
|
|
2558
2904
|
storage: storage,
|
|
2559
2905
|
textNumbersRegex: textNumbersRegex,
|