akeyless-client-commons 1.0.1

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.
@@ -0,0 +1,496 @@
1
+ // src/hooks/global.ts
2
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
3
+ try {
4
+ var info = gen[key](arg);
5
+ var value = info.value;
6
+ } catch (error) {
7
+ reject(error);
8
+ return;
9
+ }
10
+ if (info.done) {
11
+ resolve(value);
12
+ } else {
13
+ Promise.resolve(value).then(_next, _throw);
14
+ }
15
+ }
16
+ function _async_to_generator(fn) {
17
+ return function() {
18
+ var self = this, args = arguments;
19
+ return new Promise(function(resolve, reject) {
20
+ var gen = fn.apply(self, args);
21
+ function _next(value) {
22
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
23
+ }
24
+ function _throw(err) {
25
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
26
+ }
27
+ _next(undefined);
28
+ });
29
+ };
30
+ }
31
+ function _define_property(obj, key, value) {
32
+ if (key in obj) {
33
+ Object.defineProperty(obj, key, {
34
+ value: value,
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true
38
+ });
39
+ } else {
40
+ obj[key] = value;
41
+ }
42
+ return obj;
43
+ }
44
+ function _object_spread(target) {
45
+ for(var i = 1; i < arguments.length; i++){
46
+ var source = arguments[i] != null ? arguments[i] : {};
47
+ var ownKeys = Object.keys(source);
48
+ if (typeof Object.getOwnPropertySymbols === "function") {
49
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
50
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
51
+ }));
52
+ }
53
+ ownKeys.forEach(function(key) {
54
+ _define_property(target, key, source[key]);
55
+ });
56
+ }
57
+ return target;
58
+ }
59
+ function ownKeys(object, enumerableOnly) {
60
+ var keys = Object.keys(object);
61
+ if (Object.getOwnPropertySymbols) {
62
+ var symbols = Object.getOwnPropertySymbols(object);
63
+ if (enumerableOnly) {
64
+ symbols = symbols.filter(function(sym) {
65
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
66
+ });
67
+ }
68
+ keys.push.apply(keys, symbols);
69
+ }
70
+ return keys;
71
+ }
72
+ function _object_spread_props(target, source) {
73
+ source = source != null ? source : {};
74
+ if (Object.getOwnPropertyDescriptors) {
75
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
76
+ } else {
77
+ ownKeys(Object(source)).forEach(function(key) {
78
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
79
+ });
80
+ }
81
+ return target;
82
+ }
83
+ function _ts_generator(thisArg, body) {
84
+ var f, y, t, g, _ = {
85
+ label: 0,
86
+ sent: function() {
87
+ if (t[0] & 1) throw t[1];
88
+ return t[1];
89
+ },
90
+ trys: [],
91
+ ops: []
92
+ };
93
+ return g = {
94
+ next: verb(0),
95
+ "throw": verb(1),
96
+ "return": verb(2)
97
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
98
+ return this;
99
+ }), g;
100
+ function verb(n) {
101
+ return function(v) {
102
+ return step([
103
+ n,
104
+ v
105
+ ]);
106
+ };
107
+ }
108
+ function step(op) {
109
+ if (f) throw new TypeError("Generator is already executing.");
110
+ while(_)try {
111
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
112
+ if (y = 0, t) op = [
113
+ op[0] & 2,
114
+ t.value
115
+ ];
116
+ switch(op[0]){
117
+ case 0:
118
+ case 1:
119
+ t = op;
120
+ break;
121
+ case 4:
122
+ _.label++;
123
+ return {
124
+ value: op[1],
125
+ done: false
126
+ };
127
+ case 5:
128
+ _.label++;
129
+ y = op[1];
130
+ op = [
131
+ 0
132
+ ];
133
+ continue;
134
+ case 7:
135
+ op = _.ops.pop();
136
+ _.trys.pop();
137
+ continue;
138
+ default:
139
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
140
+ _ = 0;
141
+ continue;
142
+ }
143
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
144
+ _.label = op[1];
145
+ break;
146
+ }
147
+ if (op[0] === 6 && _.label < t[1]) {
148
+ _.label = t[1];
149
+ t = op;
150
+ break;
151
+ }
152
+ if (t && _.label < t[2]) {
153
+ _.label = t[2];
154
+ _.ops.push(op);
155
+ break;
156
+ }
157
+ if (t[2]) _.ops.pop();
158
+ _.trys.pop();
159
+ continue;
160
+ }
161
+ op = body.call(thisArg, _);
162
+ } catch (e) {
163
+ op = [
164
+ 6,
165
+ e
166
+ ];
167
+ y = 0;
168
+ } finally{
169
+ f = t = 0;
170
+ }
171
+ if (op[0] & 5) throw op[1];
172
+ return {
173
+ value: op[0] ? op[1] : void 0,
174
+ done: true
175
+ };
176
+ }
177
+ }
178
+ import { CountryOptions as CountryOptions2 } from "akeyless-types-commons";
179
+ import { useEffect as useEffect2, useLayoutEffect, useRef as useRef2 } from "react";
180
+ // src/helpers/firebase.ts
181
+ import moment from "moment";
182
+ import { initializeApp } from "firebase/app";
183
+ import { getStorage } from "firebase/storage";
184
+ import { getAuth } from "firebase/auth";
185
+ import { addDoc, collection, deleteDoc, doc, getDoc, getDocs, query, setDoc, Timestamp, where, getFirestore, onSnapshot, orderBy } from "firebase/firestore";
186
+ var initApp = function() {
187
+ var isNodeEnv2 = typeof process !== "undefined" && process.env;
188
+ var firebaseConfig = {
189
+ apiKey: isNodeEnv2 ? process.env.NEXT_PUBLIC_API_KEY : import.meta.env.VITE_API_KEY,
190
+ authDomain: isNodeEnv2 ? process.env.NEXT_PUBLIC_AUTH_DOMAIN : import.meta.env.VITE_AUTH_DOMAIN,
191
+ projectId: isNodeEnv2 ? process.env.NEXT_PUBLIC_PROJECT_ID : import.meta.env.VITE_PROJECT_ID,
192
+ storageBucket: isNodeEnv2 ? process.env.NEXT_PUBLIC_STORAGE_BUCKET : import.meta.env.VITE_STORAGE_BUCKET,
193
+ messagingSenderId: isNodeEnv2 ? process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID : import.meta.env.VITE_MESSAGING_SENDER_ID,
194
+ appId: isNodeEnv2 ? process.env.NEXT_PUBLIC_APP_ID : import.meta.env.VITE_APP_ID
195
+ };
196
+ try {
197
+ var app = initializeApp(firebaseConfig);
198
+ var auth2 = getAuth(app);
199
+ var db2 = getFirestore(app);
200
+ var storage2 = getStorage(app);
201
+ return {
202
+ db: db2,
203
+ auth: auth2,
204
+ storage: storage2
205
+ };
206
+ } catch (error) {
207
+ console.error("Failed to initialize Firebase app:", error);
208
+ return {};
209
+ }
210
+ };
211
+ var _initApp = initApp(), db = _initApp.db, auth = _initApp.auth, storage = _initApp.storage;
212
+ var collections = {
213
+ clients: collection(db, "nx-clients"),
214
+ sites: collection(db, "nx-sites"),
215
+ cars: collection(db, "units"),
216
+ users: collection(db, "nx-users"),
217
+ lastLocations: collection(db, "last_locations"),
218
+ ermEvents: collection(db, "erm_events_general"),
219
+ erm2Events: collection(db, "erm2_events_general"),
220
+ ruptelaEvents: collection(db, "ruptela_events_general"),
221
+ polygons: collection(db, "nx-polygons"),
222
+ polygonEvents: collection(db, "polygon_events"),
223
+ polygonCars: collection(db, "polygon_cars"),
224
+ canbus: collection(db, "erm_canbus_parameters"),
225
+ states: collection(db, "erm_states"),
226
+ app_pro_commands_queue: collection(db, "app_pro_commands_queue"),
227
+ trips: collection(db, "erm2_trip"),
228
+ tripsDetails: collection(db, "erm2_trip_details"),
229
+ audit: collection(db, "nx-audit"),
230
+ nx_settings: collection(db, "nx-settings"),
231
+ settings: collection(db, "settings"),
232
+ translations: collection(db, "nx-translations"),
233
+ nx_cars: collection(db, "nx-cars"),
234
+ boards: collection(db, "boards"),
235
+ protection_types: collection(db, "protectionTypes"),
236
+ board_types: collection(db, "boardTypes"),
237
+ charge_capacities: collection(db, "nx-charge-capacities")
238
+ };
239
+ var fire_base_TIME_TEMP = Timestamp.now;
240
+ var simpleExtractData = function(doc2) {
241
+ var docData = doc2.data();
242
+ return _object_spread_props(_object_spread({}, docData), {
243
+ id: doc2.id
244
+ });
245
+ };
246
+ var snapshot = function(config, snapshotsFirstTime) {
247
+ var resolvePromise;
248
+ var isResolved = false;
249
+ var promise = new Promise(function(resolve) {
250
+ console.log("==> ".concat(config.collectionName, " subscribed."));
251
+ resolvePromise = function() {
252
+ if (!isResolved) {
253
+ isResolved = true;
254
+ resolve();
255
+ }
256
+ };
257
+ });
258
+ var collectionRef = collection(db, config.collectionName);
259
+ if (config.conditions) {
260
+ config.conditions.forEach(function(condition) {
261
+ collectionRef = query(collectionRef, where(condition.field_name, condition.operator, condition.value));
262
+ });
263
+ }
264
+ if (config.orderBy) {
265
+ config.orderBy.forEach(function(order) {
266
+ collectionRef = query(collectionRef, orderBy(order.fieldName, order.direction));
267
+ });
268
+ }
269
+ var unsubscribe = onSnapshot(collectionRef, function(snapshot2) {
270
+ if (!snapshotsFirstTime.includes(config.collectionName)) {
271
+ var _config_onFirstTime, _config_extraParsers;
272
+ snapshotsFirstTime.push(config.collectionName);
273
+ var documents = snapshot2.docs.map(function(doc2) {
274
+ return simpleExtractData(doc2);
275
+ });
276
+ (_config_onFirstTime = config.onFirstTime) === null || _config_onFirstTime === void 0 ? void 0 : _config_onFirstTime.call(config, documents, config);
277
+ (_config_extraParsers = config.extraParsers) === null || _config_extraParsers === void 0 ? void 0 : _config_extraParsers.forEach(function(extraParser) {
278
+ var _extraParser_onFirstTime;
279
+ (_extraParser_onFirstTime = extraParser.onFirstTime) === null || _extraParser_onFirstTime === void 0 ? void 0 : _extraParser_onFirstTime.call(extraParser, documents, config);
280
+ });
281
+ resolvePromise();
282
+ } else {
283
+ var _config_onAdd, _config_onModify, _config_onRemove, _config_extraParsers1;
284
+ var addedDocs = [];
285
+ var modifiedDocs = [];
286
+ var removedDocs = [];
287
+ snapshot2.docChanges().forEach(function(change) {
288
+ if (change.type === "added") {
289
+ addedDocs.push(simpleExtractData(change.doc));
290
+ } else if (change.type === "modified") {
291
+ modifiedDocs.push(simpleExtractData(change.doc));
292
+ } else if (change.type === "removed") {
293
+ removedDocs.push(simpleExtractData(change.doc));
294
+ }
295
+ });
296
+ addedDocs.length && ((_config_onAdd = config.onAdd) === null || _config_onAdd === void 0 ? void 0 : _config_onAdd.call(config, addedDocs, config));
297
+ modifiedDocs.length && ((_config_onModify = config.onModify) === null || _config_onModify === void 0 ? void 0 : _config_onModify.call(config, modifiedDocs, config));
298
+ removedDocs.length && ((_config_onRemove = config.onRemove) === null || _config_onRemove === void 0 ? void 0 : _config_onRemove.call(config, removedDocs, config));
299
+ (_config_extraParsers1 = config.extraParsers) === null || _config_extraParsers1 === void 0 ? void 0 : _config_extraParsers1.forEach(function(extraParser) {
300
+ var _extraParser_onAdd, _extraParser_onModify, _extraParser_onRemove;
301
+ addedDocs.length && ((_extraParser_onAdd = extraParser.onAdd) === null || _extraParser_onAdd === void 0 ? void 0 : _extraParser_onAdd.call(extraParser, addedDocs, config));
302
+ modifiedDocs.length && ((_extraParser_onModify = extraParser.onModify) === null || _extraParser_onModify === void 0 ? void 0 : _extraParser_onModify.call(extraParser, modifiedDocs, config));
303
+ removedDocs.length && ((_extraParser_onRemove = extraParser.onRemove) === null || _extraParser_onRemove === void 0 ? void 0 : _extraParser_onRemove.call(extraParser, removedDocs, config));
304
+ });
305
+ }
306
+ }, function(error) {
307
+ console.error("Error listening to collection: ".concat(config.collectionName), error);
308
+ resolvePromise();
309
+ });
310
+ return {
311
+ promise: promise,
312
+ unsubscribe: unsubscribe
313
+ };
314
+ };
315
+ // src/helpers/global.ts
316
+ import { CountryOptions } from "akeyless-types-commons";
317
+ import axios from "axios";
318
+ // src/helpers/phoneNumber.ts
319
+ import { parsePhoneNumberFromString } from "libphonenumber-js";
320
+ // src/helpers/global.ts
321
+ import { isEqual } from "lodash";
322
+ var getUserCountryByIp = /*#__PURE__*/ function() {
323
+ var _ref = _async_to_generator(function() {
324
+ var response, error;
325
+ return _ts_generator(this, function(_state) {
326
+ switch(_state.label){
327
+ case 0:
328
+ _state.trys.push([
329
+ 0,
330
+ 2,
331
+ ,
332
+ 3
333
+ ]);
334
+ return [
335
+ 4,
336
+ axios.get("https://ipapi.co/json/")
337
+ ];
338
+ case 1:
339
+ response = _state.sent();
340
+ return [
341
+ 2,
342
+ (response.data.country_code || CountryOptions.IL).toLowerCase()
343
+ ];
344
+ case 2:
345
+ error = _state.sent();
346
+ console.error("Error fetching Country:", error);
347
+ return [
348
+ 2,
349
+ CountryOptions.IL
350
+ ];
351
+ case 3:
352
+ return [
353
+ 2
354
+ ];
355
+ }
356
+ });
357
+ });
358
+ return function getUserCountryByIp() {
359
+ return _ref.apply(this, arguments);
360
+ };
361
+ }();
362
+ var isNodeEnv = typeof process !== "undefined" && process.env;
363
+ var _ref = {
364
+ mode: isNodeEnv ? process.env.NEXT_PUBLIC_MODE : import.meta.env.VITE_MODE,
365
+ isLocal: (isNodeEnv ? process.env.NEXT_PUBLIC_IS_LOCAL : import.meta.env.VITE_is_local) === "true"
366
+ }, mode = _ref.mode, isLocal = _ref.isLocal;
367
+ // src/helpers/forms.ts
368
+ import XRegExp from "xregexp";
369
+ var textRegex = XRegExp("[^\\p{L}\\s-]", "gu");
370
+ var numbersRegex = XRegExp("[^0-9\\s-+]", "g");
371
+ var numbersOnlyRegex = XRegExp("[^0-9]", "g");
372
+ var priceRegex = XRegExp("[^0-9.]", "g");
373
+ var emailRegex = XRegExp("[^\\p{L}0-9.@\\s-]", "gu");
374
+ var colorRegex = XRegExp("[^#0-9A-Fa-f]", "g");
375
+ var carsRegex = XRegExp("[^\\p{L}0-9,_]", "gu");
376
+ var textNumbersRegex = XRegExp("[^\\p{L}0-9\\s+\\-]", "gu");
377
+ var addressRegex = XRegExp("[^\\p{L}0-9\\s.,+-\\-]", "gu");
378
+ var chartsRegex = XRegExp("[^\\p{L}0-9\\s.,_@!+-\\-]", "gu");
379
+ // src/lib/utils.ts
380
+ import { clsx } from "clsx";
381
+ import { twMerge } from "tailwind-merge";
382
+ // src/helpers/time_helpers.ts
383
+ import { Timestamp as Timestamp2 } from "firebase/firestore";
384
+ import moment2 from "moment-timezone";
385
+ // src/helpers/api.ts
386
+ import axios2 from "axios";
387
+ var baseDomain = mode === "qa" ? "https://nx-api.xyz/api" : "https://nx-api.info/api";
388
+ var devicesDomain = isLocal ? "http://localhost:9001/api/devices" : baseDomain + "/devices";
389
+ var biDomain = isLocal ? "http://localhost:9002/api/bi" : baseDomain + "/bi";
390
+ var callCenterDomain = isLocal ? "http://localhost:9003/api/call-center" : baseDomain + "/call-center";
391
+ // src/hooks/react.ts
392
+ import { isEqual as isEqual2 } from "lodash";
393
+ import { useEffect, useMemo, useRef } from "react";
394
+ function useSafeEffect(callback, dependencies, error_message) {
395
+ useEffect(function() {
396
+ try {
397
+ callback();
398
+ } catch (error) {
399
+ console.error(error_message || "Error in useEffect:", error);
400
+ }
401
+ }, dependencies);
402
+ }
403
+ var useDeepCompareMemo = function(factory, dependencies) {
404
+ var previousDepsRef = useRef([]);
405
+ if (!isEqual2(dependencies, previousDepsRef.current)) {
406
+ previousDepsRef.current = dependencies;
407
+ }
408
+ return useMemo(factory, previousDepsRef.current);
409
+ };
410
+ function useDeepCompareEffect(effect, dependencies) {
411
+ var previousDepsRef = useRef();
412
+ if (!isEqual2(previousDepsRef.current, dependencies)) {
413
+ previousDepsRef.current = dependencies;
414
+ }
415
+ useEffect(effect, [
416
+ previousDepsRef.current
417
+ ]);
418
+ }
419
+ // src/hooks/global.ts
420
+ var useDocumentTitle = function(title) {
421
+ useEffect2(function() {
422
+ document.title = title;
423
+ }, [
424
+ title
425
+ ]);
426
+ return null;
427
+ };
428
+ var useSnapshotBulk = function(configs, label) {
429
+ var snapshotsFirstTime = useRef2([]);
430
+ var unsubscribeFunctions = useRef2([]);
431
+ useDeepCompareEffect(function() {
432
+ var start = performance.now();
433
+ console.log("==> ".concat(label || "Custom snapshots", " started... "));
434
+ var snapshotResults = configs.map(function(config) {
435
+ return snapshot(config, snapshotsFirstTime.current);
436
+ });
437
+ unsubscribeFunctions.current = snapshotResults.map(function(result) {
438
+ return result.unsubscribe;
439
+ });
440
+ Promise.all(snapshotResults.map(function(result) {
441
+ return result.promise;
442
+ })).then(function() {
443
+ console.log("==> ".concat(label || "Custom snapshots", " ended. It took ").concat((performance.now() - start).toFixed(2), " ms"));
444
+ });
445
+ }, [
446
+ configs,
447
+ label
448
+ ]);
449
+ useEffect2(function() {
450
+ return function() {
451
+ unsubscribeFunctions.current.forEach(function(unsubscribe) {
452
+ if (unsubscribe) {
453
+ unsubscribe();
454
+ }
455
+ });
456
+ };
457
+ }, []);
458
+ };
459
+ var useSetUserCountry = function(setUserCountry, changLang) {
460
+ useLayoutEffect(function() {
461
+ var currentCountry = localStorage.getItem("userCountry");
462
+ if (!currentCountry) {
463
+ var updateCountry = /*#__PURE__*/ function() {
464
+ var _ref = _async_to_generator(function() {
465
+ var country;
466
+ return _ts_generator(this, function(_state) {
467
+ switch(_state.label){
468
+ case 0:
469
+ return [
470
+ 4,
471
+ getUserCountryByIp()
472
+ ];
473
+ case 1:
474
+ country = _state.sent();
475
+ changLang(country === CountryOptions2.IL ? "he" : "en");
476
+ setUserCountry(country);
477
+ localStorage.setItem("userCountry", country);
478
+ return [
479
+ 2
480
+ ];
481
+ }
482
+ });
483
+ });
484
+ return function updateCountry() {
485
+ return _ref.apply(this, arguments);
486
+ };
487
+ }();
488
+ updateCountry();
489
+ }
490
+ }, []);
491
+ return null;
492
+ };
493
+ // src/hooks/WebWorker.ts
494
+ import { useCallback, useEffect as useEffect3, useRef as useRef3 } from "react";
495
+ export { useDeepCompareEffect, useDeepCompareMemo, useDocumentTitle, useSafeEffect, useSetUserCountry, useSnapshotBulk };
496
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["c:\\work\\akeyless\\commons\\client_commons\\dist\\hooks\\index.mjs"],"names":[],"mappings":"AAAA,sBAAsB","sourcesContent":["// src/hooks/global.ts\nimport { CountryOptions as CountryOptions2 } from \"akeyless-types-commons\";\nimport { useEffect, useLayoutEffect, useRef } from \"react\";\n\n// src/helpers/firebase.ts\nimport moment from \"moment\";\nimport { initializeApp } from \"firebase/app\";\nimport { getStorage } from \"firebase/storage\";\nimport { getAuth } from \"firebase/auth\";\nimport {\n addDoc,\n collection,\n deleteDoc,\n doc,\n getDoc,\n getDocs,\n query,\n setDoc,\n Timestamp,\n where,\n getFirestore,\n onSnapshot\n} from \"firebase/firestore\";\nvar initApp = () => {\n const isNodeEnv = typeof process !== \"undefined\" && process.env;\n const firebaseConfig = {\n apiKey: isNodeEnv ? process.env.NEXT_PUBLIC_API_KEY : import.meta.env.VITE_API_KEY,\n authDomain: isNodeEnv ? process.env.NEXT_PUBLIC_AUTH_DOMAIN : import.meta.env.VITE_AUTH_DOMAIN,\n projectId: isNodeEnv ? process.env.NEXT_PUBLIC_PROJECT_ID : import.meta.env.VITE_PROJECT_ID,\n storageBucket: isNodeEnv ? process.env.NEXT_PUBLIC_STORAGE_BUCKET : import.meta.env.VITE_STORAGE_BUCKET,\n messagingSenderId: isNodeEnv ? process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID : import.meta.env.VITE_MESSAGING_SENDER_ID,\n appId: isNodeEnv ? process.env.NEXT_PUBLIC_APP_ID : import.meta.env.VITE_APP_ID\n };\n try {\n const app = initializeApp(firebaseConfig);\n const auth2 = getAuth(app);\n const db2 = getFirestore(app);\n const storage2 = getStorage(app);\n return { db: db2, auth: auth2, storage: storage2 };\n } catch (error) {\n console.error(\"Failed to initialize Firebase app:\", error);\n return { db: null, auth: null };\n }\n};\nvar { db, auth, storage } = initApp();\nvar collections = {\n clients: collection(db, \"nx-clients\"),\n sites: collection(db, \"nx-sites\"),\n cars: collection(db, \"units\"),\n users: collection(db, \"nx-users\"),\n lastLocations: collection(db, \"last_locations\"),\n ermEvents: collection(db, \"erm_events_general\"),\n erm2Events: collection(db, \"erm2_events_general\"),\n ruptelaEvents: collection(db, \"ruptela_events_general\"),\n polygons: collection(db, \"nx-polygons\"),\n polygonEvents: collection(db, \"polygon_events\"),\n polygonCars: collection(db, \"polygon_cars\"),\n canbus: collection(db, \"erm_canbus_parameters\"),\n states: collection(db, \"erm_states\"),\n app_pro_commands_queue: collection(db, \"app_pro_commands_queue\"),\n trips: collection(db, \"erm2_trip\"),\n tripsDetails: collection(db, \"erm2_trip_details\"),\n audit: collection(db, \"nx-audit\"),\n nx_settings: collection(db, \"nx-settings\"),\n settings: collection(db, \"settings\"),\n translations: collection(db, \"nx-translations\"),\n nx_cars: collection(db, \"nx-cars\"),\n boards: collection(db, \"boards\"),\n protection_types: collection(db, \"protectionTypes\"),\n board_types: collection(db, \"boardTypes\"),\n charge_capacities: collection(db, \"nx-charge-capacities\")\n};\nvar fire_base_TIME_TEMP = Timestamp.now;\nvar simpleExtractData = (doc2) => {\n const docData = doc2.data();\n return {\n ...docData,\n id: doc2.id\n };\n};\nvar snapshot = (config, snapshotsFirstTime) => {\n let resolvePromise;\n let isResolved = false;\n const promise = new Promise((resolve) => {\n console.log(`==> ${config.collectionName} subscribed.`);\n resolvePromise = () => {\n if (!isResolved) {\n isResolved = true;\n resolve();\n }\n };\n });\n let collectionRef = collection(db, config.collectionName);\n if (config.conditions) {\n config.conditions.forEach((condition) => {\n collectionRef = query(collectionRef, where(condition.field_name, condition.operator, condition.value));\n });\n }\n const unsubscribe = onSnapshot(\n collectionRef,\n (snapshot2) => {\n if (!snapshotsFirstTime.includes(config.collectionName)) {\n snapshotsFirstTime.push(config.collectionName);\n const documents = snapshot2.docs.map((doc2) => simpleExtractData(doc2));\n config.onFirstTime?.(documents, config);\n config.extraParsers?.forEach((extraParser) => {\n extraParser.onFirstTime?.(documents, config);\n });\n resolvePromise();\n } else {\n const addedDocs = [];\n const modifiedDocs = [];\n const removedDocs = [];\n snapshot2.docChanges().forEach((change) => {\n if (change.type === \"added\") {\n addedDocs.push(simpleExtractData(change.doc));\n } else if (change.type === \"modified\") {\n modifiedDocs.push(simpleExtractData(change.doc));\n } else if (change.type === \"removed\") {\n removedDocs.push(simpleExtractData(change.doc));\n }\n });\n addedDocs.length && config.onAdd?.(addedDocs, config);\n modifiedDocs.length && config.onModify?.(modifiedDocs, config);\n removedDocs.length && config.onRemove?.(removedDocs, config);\n config.extraParsers?.forEach((extraParser) => {\n addedDocs.length && extraParser.onAdd?.(addedDocs, config);\n modifiedDocs.length && extraParser.onModify?.(modifiedDocs, config);\n removedDocs.length && extraParser.onRemove?.(removedDocs, config);\n });\n }\n },\n (error) => {\n console.error(`Error listening to collection: ${config.collectionName}`, error);\n resolvePromise();\n }\n );\n return { promise, unsubscribe };\n};\n\n// src/helpers/global.ts\nimport { CountryOptions } from \"akeyless-types-commons\";\nimport axios from \"axios\";\n\n// src/helpers/phoneNumber.ts\nimport { parsePhoneNumberFromString } from \"libphonenumber-js\";\n\n// src/helpers/global.ts\nvar getUserCountryByIp = async () => {\n try {\n const response = await axios.get(\"https://ipapi.co/json/\");\n return (response.data.country_code || CountryOptions.IL).toLowerCase();\n } catch (error) {\n console.error(\"Error fetching Country:\", error);\n return CountryOptions.IL;\n }\n};\n\n// src/helpers/forms.ts\nimport XRegExp from \"xregexp\";\nvar textRegex = XRegExp(\"[^\\\\p{L}\\\\s-]\", \"gu\");\nvar numbersRegex = XRegExp(\"[^0-9\\\\s-+]\", \"g\");\nvar numbersOnlyRegex = XRegExp(\"[^0-9]\", \"g\");\nvar priceRegex = XRegExp(\"[^0-9.]\", \"g\");\nvar emailRegex = XRegExp(\"[^\\\\p{L}0-9.@\\\\s-]\", \"gu\");\nvar colorRegex = XRegExp(\"[^#0-9A-Fa-f]\", \"g\");\nvar carsRegex = XRegExp(\"[^\\\\p{L}0-9,_]\", \"gu\");\nvar textNumbersRegex = XRegExp(\"[^\\\\p{L}0-9\\\\s+\\\\-]\", \"gu\");\nvar addressRegex = XRegExp(\"[^\\\\p{L}0-9\\\\s.,\\\\-]\", \"gu\");\nvar chartsRegex = XRegExp(\"[^\\\\p{L}0-9\\\\s.,_@!\\\\-]\", \"gu\");\n\n// src/lib/utils.ts\nimport { clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\n// src/helpers/time_helpers.ts\nimport { Timestamp as Timestamp2 } from \"firebase/firestore\";\nimport moment2 from \"moment-timezone\";\n\n// src/hooks/global.ts\nfunction useSafeEffect(callback, dependencies, error_message) {\n useEffect(() => {\n try {\n callback();\n } catch (error) {\n console.error(error_message || \"Error in useEffect:\", error);\n }\n }, dependencies);\n}\nvar useDocumentTitle = (title) => {\n useEffect(() => {\n document.title = title;\n }, [title]);\n return null;\n};\nvar useSnapshotBulk = (configs, label) => {\n const snapshotsFirstTime = useRef([]);\n const unsubscribeFunctions = useRef([]);\n useEffect(() => {\n const start = performance.now();\n console.log(`==> ${label || \"Custom snapshots\"} started... `);\n const snapshotResults = configs.map((config) => snapshot(config, snapshotsFirstTime.current));\n unsubscribeFunctions.current = snapshotResults.map((result) => result.unsubscribe);\n Promise.all(snapshotResults.map((result) => result.promise)).then(() => {\n console.log(`==> ${label || \"Custom snapshots\"} ended. It took ${(performance.now() - start).toFixed(2)} ms`);\n });\n }, [JSON.stringify(configs), label]);\n useEffect(() => {\n return () => {\n unsubscribeFunctions.current.forEach((unsubscribe) => {\n if (unsubscribe) {\n unsubscribe();\n }\n });\n };\n }, []);\n};\nvar useSetUserCountry = (setUserCountry, changLang) => {\n useLayoutEffect(() => {\n const currentCountry = localStorage.getItem(\"userCountry\");\n if (!currentCountry) {\n const updateCountry = async () => {\n const country = await getUserCountryByIp();\n changLang(country === CountryOptions2.IL ? \"he\" : \"en\");\n setUserCountry(country);\n localStorage.setItem(\"userCountry\", country);\n };\n updateCountry();\n }\n }, []);\n return null;\n};\n\n// src/hooks/WebWorker.ts\nimport { useCallback, useEffect as useEffect2, useRef as useRef2 } from \"react\";\nexport {\n useDocumentTitle,\n useSafeEffect,\n useSetUserCountry,\n useSnapshotBulk\n};\n"]}