akeyless-client-commons 1.1.129 → 1.1.130

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.
@@ -421,6 +421,9 @@ __export(index_exports, {
421
421
  chartsRegex: function() {
422
422
  return chartsRegex;
423
423
  },
424
+ checkConditions: function() {
425
+ return checkConditions;
426
+ },
424
427
  checkUserPermissions: function() {
425
428
  return checkUserPermissions;
426
429
  },
@@ -1119,17 +1122,202 @@ function sort_by_timestamp(a, b) {
1119
1122
  var reverse = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
1120
1123
  return reverse ? timestamp_to_millis(b) - timestamp_to_millis(a) : timestamp_to_millis(a) - timestamp_to_millis(b);
1121
1124
  }
1122
- // src/helpers/firebase.ts
1125
+ // src/helpers/global.ts
1126
+ var import_akeyless_types_commons = require("akeyless-types-commons");
1127
+ var import_axios = __toESM(require("axios"));
1128
+ var import_lodash = require("lodash");
1123
1129
  var import_meta = {};
1130
+ var calculateBearing = function(startLat, startLng, endLat, endLng) {
1131
+ if (startLat === endLat || startLng === endLng) {
1132
+ return 0;
1133
+ }
1134
+ if (startLat === void 0 || startLng === void 0 || endLat === void 0 || endLng === void 0) {
1135
+ return 0;
1136
+ }
1137
+ var startLatRad = startLat * Math.PI / 180;
1138
+ var startLngRad = startLng * Math.PI / 180;
1139
+ var endLatRad = endLat * Math.PI / 180;
1140
+ var endLngRad = endLng * Math.PI / 180;
1141
+ var dLon = endLngRad - startLngRad;
1142
+ var y = Math.sin(dLon) * Math.cos(endLatRad);
1143
+ var x = Math.cos(startLatRad) * Math.sin(endLatRad) - Math.sin(startLatRad) * Math.cos(endLatRad) * Math.cos(dLon);
1144
+ var bearing = Math.atan2(y, x) * 180 / Math.PI;
1145
+ return (bearing + 360) % 360;
1146
+ };
1147
+ var renderOnce = function() {
1148
+ return true;
1149
+ };
1150
+ var propsAreEqual = function(prevProps, nextProps) {
1151
+ return (0, import_lodash.isEqual)(prevProps, nextProps);
1152
+ };
1153
+ var getUserCountryByIp = /*#__PURE__*/ function() {
1154
+ var _ref = _async_to_generator(function() {
1155
+ var response, data, error;
1156
+ return _ts_generator(this, function(_state) {
1157
+ switch(_state.label){
1158
+ case 0:
1159
+ _state.trys.push([
1160
+ 0,
1161
+ 3,
1162
+ ,
1163
+ 4
1164
+ ]);
1165
+ return [
1166
+ 4,
1167
+ fetch("https://ipapi.co/json/")
1168
+ ];
1169
+ case 1:
1170
+ response = _state.sent();
1171
+ return [
1172
+ 4,
1173
+ response.json()
1174
+ ];
1175
+ case 2:
1176
+ data = _state.sent();
1177
+ return [
1178
+ 2,
1179
+ (data.country_code || import_akeyless_types_commons.CountryOptions.IL).toLowerCase()
1180
+ ];
1181
+ case 3:
1182
+ error = _state.sent();
1183
+ console.error("Error fetching Country:", error);
1184
+ return [
1185
+ 2,
1186
+ import_akeyless_types_commons.CountryOptions.IL
1187
+ ];
1188
+ case 4:
1189
+ return [
1190
+ 2
1191
+ ];
1192
+ }
1193
+ });
1194
+ });
1195
+ return function getUserCountryByIp() {
1196
+ return _ref.apply(this, arguments);
1197
+ };
1198
+ }();
1199
+ var userNameFormat = function(user) {
1200
+ return "".concat((user === null || user === void 0 ? void 0 : user.first_name) || "", " ").concat((user === null || user === void 0 ? void 0 : user.last_name) || "").trim();
1201
+ };
1202
+ var multiStringFormat = function(str1, str2, str3) {
1203
+ return "".concat(str1, " ").concat(str2 || "", " ").concat(str3 || "").trim();
1204
+ };
1205
+ var getLocationUrl = function(lng, lat) {
1206
+ return "https://www.google.com/maps?q=".concat(lat, ",").concat(lng);
1207
+ };
1208
+ var isNodeEnv = typeof process !== "undefined" && process.env;
1209
+ var _ref = {
1210
+ mode: isNodeEnv ? process.env.NEXT_PUBLIC_MODE : import_meta.env.VITE_MODE,
1211
+ isLocal: (isNodeEnv ? process.env.NEXT_PUBLIC_IS_LOCAL : import_meta.env.VITE_is_local) === "true"
1212
+ }, mode = _ref.mode, isLocal = _ref.isLocal;
1213
+ var getFixedNumber = function() {
1214
+ var number = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0, fix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 4;
1215
+ var sum_value = number % 1 === 0 ? number : number.toFixed(fix).replace(/\.?0+$/, "");
1216
+ return String(sum_value);
1217
+ };
1218
+ var getAddressByGeo = /*#__PURE__*/ function() {
1219
+ var _ref = _async_to_generator(function(param, currentLanguage) {
1220
+ var lat, lng, language, apiKey, url, _response_data, response, error;
1221
+ return _ts_generator(this, function(_state) {
1222
+ switch(_state.label){
1223
+ case 0:
1224
+ lat = param.lat, lng = param.lng;
1225
+ language = currentLanguage === import_akeyless_types_commons.LanguageOptions.He ? "iw" : "en";
1226
+ apiKey = isNodeEnv ? process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY : import_meta.env.VITE_api_google_key;
1227
+ url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=".concat(lat, ",").concat(lng, "&key=").concat(apiKey, "&language=").concat(language);
1228
+ _state.label = 1;
1229
+ case 1:
1230
+ _state.trys.push([
1231
+ 1,
1232
+ 3,
1233
+ ,
1234
+ 4
1235
+ ]);
1236
+ return [
1237
+ 4,
1238
+ import_axios.default.get(url)
1239
+ ];
1240
+ case 2:
1241
+ response = _state.sent();
1242
+ if (response === null || response === void 0 ? void 0 : (_response_data = response.data) === null || _response_data === void 0 ? void 0 : _response_data.results[0]) {
1243
+ return [
1244
+ 2,
1245
+ response.data.results[0].formatted_address.slice(0, 35)
1246
+ ];
1247
+ } else {
1248
+ return [
1249
+ 2,
1250
+ "address not found"
1251
+ ];
1252
+ }
1253
+ return [
1254
+ 3,
1255
+ 4
1256
+ ];
1257
+ case 3:
1258
+ error = _state.sent();
1259
+ console.error("getAddressByGeo error:", error);
1260
+ return [
1261
+ 3,
1262
+ 4
1263
+ ];
1264
+ case 4:
1265
+ return [
1266
+ 2
1267
+ ];
1268
+ }
1269
+ });
1270
+ });
1271
+ return function getAddressByGeo(_, currentLanguage) {
1272
+ return _ref.apply(this, arguments);
1273
+ };
1274
+ }();
1275
+ var validateAndCast = function(variable, condition) {
1276
+ return !!condition;
1277
+ };
1278
+ var checkConditions = function(document2, conditions) {
1279
+ if (!conditions || conditions.length === 0) return true;
1280
+ return conditions.every(function(condition) {
1281
+ var fieldValue = document2[condition.field_name];
1282
+ switch(condition.operator){
1283
+ case "==":
1284
+ return fieldValue === condition.value;
1285
+ case "!=":
1286
+ return fieldValue !== condition.value;
1287
+ case "<":
1288
+ return fieldValue < condition.value;
1289
+ case "<=":
1290
+ return fieldValue <= condition.value;
1291
+ case ">":
1292
+ return fieldValue > condition.value;
1293
+ case ">=":
1294
+ return fieldValue >= condition.value;
1295
+ case "in":
1296
+ return Array.isArray(condition.value) && condition.value.includes(fieldValue);
1297
+ case "not-in":
1298
+ return Array.isArray(condition.value) && !condition.value.includes(fieldValue);
1299
+ case "array-contains":
1300
+ return Array.isArray(fieldValue) && fieldValue.includes(condition.value);
1301
+ case "array-contains-any":
1302
+ return Array.isArray(fieldValue) && Array.isArray(condition.value) && condition.value.some(function(v) {
1303
+ return fieldValue.includes(v);
1304
+ });
1305
+ default:
1306
+ return false;
1307
+ }
1308
+ });
1309
+ };
1310
+ // src/helpers/firebase.ts
1311
+ var import_meta2 = {};
1124
1312
  var initApp = function() {
1125
1313
  var isNodeEnv2 = typeof process !== "undefined" && process.env;
1126
1314
  var firebaseConfig = {
1127
- apiKey: isNodeEnv2 ? process.env.NEXT_PUBLIC_API_KEY : import_meta.env.VITE_API_KEY,
1128
- authDomain: isNodeEnv2 ? process.env.NEXT_PUBLIC_AUTH_DOMAIN : import_meta.env.VITE_AUTH_DOMAIN,
1129
- projectId: isNodeEnv2 ? process.env.NEXT_PUBLIC_PROJECT_ID : import_meta.env.VITE_PROJECT_ID,
1130
- storageBucket: isNodeEnv2 ? process.env.NEXT_PUBLIC_STORAGE_BUCKET : import_meta.env.VITE_STORAGE_BUCKET,
1131
- messagingSenderId: isNodeEnv2 ? process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID : import_meta.env.VITE_MESSAGING_SENDER_ID,
1132
- appId: isNodeEnv2 ? process.env.NEXT_PUBLIC_APP_ID : import_meta.env.VITE_APP_ID
1315
+ apiKey: isNodeEnv2 ? process.env.NEXT_PUBLIC_API_KEY : import_meta2.env.VITE_API_KEY,
1316
+ authDomain: isNodeEnv2 ? process.env.NEXT_PUBLIC_AUTH_DOMAIN : import_meta2.env.VITE_AUTH_DOMAIN,
1317
+ projectId: isNodeEnv2 ? process.env.NEXT_PUBLIC_PROJECT_ID : import_meta2.env.VITE_PROJECT_ID,
1318
+ storageBucket: isNodeEnv2 ? process.env.NEXT_PUBLIC_STORAGE_BUCKET : import_meta2.env.VITE_STORAGE_BUCKET,
1319
+ messagingSenderId: isNodeEnv2 ? process.env.NEXT_PUBLIC_MESSAGING_SENDER_ID : import_meta2.env.VITE_MESSAGING_SENDER_ID,
1320
+ appId: isNodeEnv2 ? process.env.NEXT_PUBLIC_APP_ID : import_meta2.env.VITE_APP_ID
1133
1321
  };
1134
1322
  try {
1135
1323
  var app2 = (0, import_app.initializeApp)(firebaseConfig);
@@ -1138,7 +1326,7 @@ var initApp = function() {
1138
1326
  var db2 = (0, import_firestore2.getFirestore)(app2);
1139
1327
  var storage2 = (0, import_storage.getStorage)(app2);
1140
1328
  var googleLoginProvider2 = new import_auth.GoogleAuthProvider();
1141
- var recaptchaSiteKey = isNodeEnv2 ? process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY : import_meta.env.VITE_RECAPTCHA_SITE_KEY;
1329
+ var recaptchaSiteKey = isNodeEnv2 ? process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY : import_meta2.env.VITE_RECAPTCHA_SITE_KEY;
1142
1330
  var result = {
1143
1331
  db: db2,
1144
1332
  auth: auth2,
@@ -1870,30 +2058,6 @@ var snapshotDocument = function(config, snapshotsFirstTime) {
1870
2058
  unsubscribe: unsubscribe
1871
2059
  };
1872
2060
  };
1873
- var checkConditions = function(document2, conditions) {
1874
- if (!conditions || conditions.length === 0) return true;
1875
- return conditions.every(function(condition) {
1876
- var fieldValue = document2[condition.field_name];
1877
- switch(condition.operator){
1878
- case "==":
1879
- return fieldValue === condition.value;
1880
- case "!=":
1881
- return fieldValue !== condition.value;
1882
- case "<":
1883
- return fieldValue < condition.value;
1884
- case "<=":
1885
- return fieldValue <= condition.value;
1886
- case ">":
1887
- return fieldValue > condition.value;
1888
- case ">=":
1889
- return fieldValue >= condition.value;
1890
- case "array-contains":
1891
- return Array.isArray(fieldValue) && fieldValue.includes(condition.value);
1892
- default:
1893
- return false;
1894
- }
1895
- });
1896
- };
1897
2061
  var cleanNxSites = /*#__PURE__*/ function() {
1898
2062
  var _ref = _async_to_generator(function() {
1899
2063
  var clients, sites, allSitesToDelete;
@@ -2363,159 +2527,6 @@ var parseSnapshotAsArray = function(setState2, options) {
2363
2527
  }
2364
2528
  };
2365
2529
  };
2366
- // src/helpers/global.ts
2367
- var import_akeyless_types_commons = require("akeyless-types-commons");
2368
- var import_axios = __toESM(require("axios"));
2369
- var import_lodash = require("lodash");
2370
- var import_meta2 = {};
2371
- var calculateBearing = function(startLat, startLng, endLat, endLng) {
2372
- if (startLat === endLat || startLng === endLng) {
2373
- return 0;
2374
- }
2375
- if (startLat === void 0 || startLng === void 0 || endLat === void 0 || endLng === void 0) {
2376
- return 0;
2377
- }
2378
- var startLatRad = startLat * Math.PI / 180;
2379
- var startLngRad = startLng * Math.PI / 180;
2380
- var endLatRad = endLat * Math.PI / 180;
2381
- var endLngRad = endLng * Math.PI / 180;
2382
- var dLon = endLngRad - startLngRad;
2383
- var y = Math.sin(dLon) * Math.cos(endLatRad);
2384
- var x = Math.cos(startLatRad) * Math.sin(endLatRad) - Math.sin(startLatRad) * Math.cos(endLatRad) * Math.cos(dLon);
2385
- var bearing = Math.atan2(y, x) * 180 / Math.PI;
2386
- return (bearing + 360) % 360;
2387
- };
2388
- var renderOnce = function() {
2389
- return true;
2390
- };
2391
- var propsAreEqual = function(prevProps, nextProps) {
2392
- return (0, import_lodash.isEqual)(prevProps, nextProps);
2393
- };
2394
- var getUserCountryByIp = /*#__PURE__*/ function() {
2395
- var _ref = _async_to_generator(function() {
2396
- var response, data, error;
2397
- return _ts_generator(this, function(_state) {
2398
- switch(_state.label){
2399
- case 0:
2400
- _state.trys.push([
2401
- 0,
2402
- 3,
2403
- ,
2404
- 4
2405
- ]);
2406
- return [
2407
- 4,
2408
- fetch("https://ipapi.co/json/")
2409
- ];
2410
- case 1:
2411
- response = _state.sent();
2412
- return [
2413
- 4,
2414
- response.json()
2415
- ];
2416
- case 2:
2417
- data = _state.sent();
2418
- return [
2419
- 2,
2420
- (data.country_code || import_akeyless_types_commons.CountryOptions.IL).toLowerCase()
2421
- ];
2422
- case 3:
2423
- error = _state.sent();
2424
- console.error("Error fetching Country:", error);
2425
- return [
2426
- 2,
2427
- import_akeyless_types_commons.CountryOptions.IL
2428
- ];
2429
- case 4:
2430
- return [
2431
- 2
2432
- ];
2433
- }
2434
- });
2435
- });
2436
- return function getUserCountryByIp() {
2437
- return _ref.apply(this, arguments);
2438
- };
2439
- }();
2440
- var userNameFormat = function(user) {
2441
- return "".concat((user === null || user === void 0 ? void 0 : user.first_name) || "", " ").concat((user === null || user === void 0 ? void 0 : user.last_name) || "").trim();
2442
- };
2443
- var multiStringFormat = function(str1, str2, str3) {
2444
- return "".concat(str1, " ").concat(str2 || "", " ").concat(str3 || "").trim();
2445
- };
2446
- var getLocationUrl = function(lng, lat) {
2447
- return "https://www.google.com/maps?q=".concat(lat, ",").concat(lng);
2448
- };
2449
- var isNodeEnv = typeof process !== "undefined" && process.env;
2450
- var _ref = {
2451
- mode: isNodeEnv ? process.env.NEXT_PUBLIC_MODE : import_meta2.env.VITE_MODE,
2452
- isLocal: (isNodeEnv ? process.env.NEXT_PUBLIC_IS_LOCAL : import_meta2.env.VITE_is_local) === "true"
2453
- }, mode = _ref.mode, isLocal = _ref.isLocal;
2454
- var getFixedNumber = function() {
2455
- var number = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0, fix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 4;
2456
- var sum_value = number % 1 === 0 ? number : number.toFixed(fix).replace(/\.?0+$/, "");
2457
- return String(sum_value);
2458
- };
2459
- var getAddressByGeo = /*#__PURE__*/ function() {
2460
- var _ref = _async_to_generator(function(param, currentLanguage) {
2461
- var lat, lng, language, apiKey, url, _response_data, response, error;
2462
- return _ts_generator(this, function(_state) {
2463
- switch(_state.label){
2464
- case 0:
2465
- lat = param.lat, lng = param.lng;
2466
- language = currentLanguage === import_akeyless_types_commons.LanguageOptions.He ? "iw" : "en";
2467
- apiKey = isNodeEnv ? process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY : import_meta2.env.VITE_api_google_key;
2468
- url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=".concat(lat, ",").concat(lng, "&key=").concat(apiKey, "&language=").concat(language);
2469
- _state.label = 1;
2470
- case 1:
2471
- _state.trys.push([
2472
- 1,
2473
- 3,
2474
- ,
2475
- 4
2476
- ]);
2477
- return [
2478
- 4,
2479
- import_axios.default.get(url)
2480
- ];
2481
- case 2:
2482
- response = _state.sent();
2483
- if (response === null || response === void 0 ? void 0 : (_response_data = response.data) === null || _response_data === void 0 ? void 0 : _response_data.results[0]) {
2484
- return [
2485
- 2,
2486
- response.data.results[0].formatted_address.slice(0, 35)
2487
- ];
2488
- } else {
2489
- return [
2490
- 2,
2491
- "address not found"
2492
- ];
2493
- }
2494
- return [
2495
- 3,
2496
- 4
2497
- ];
2498
- case 3:
2499
- error = _state.sent();
2500
- console.error("getAddressByGeo error:", error);
2501
- return [
2502
- 3,
2503
- 4
2504
- ];
2505
- case 4:
2506
- return [
2507
- 2
2508
- ];
2509
- }
2510
- });
2511
- });
2512
- return function getAddressByGeo(_, currentLanguage) {
2513
- return _ref.apply(this, arguments);
2514
- };
2515
- }();
2516
- var validateAndCast = function(variable, condition) {
2517
- return !!condition;
2518
- };
2519
2530
  // src/helpers/forms.ts
2520
2531
  var import_xregexp = __toESM(require("xregexp"));
2521
2532
  var textRegex = (0, import_xregexp.default)(String.raw(_templateObject()), "gu");
@@ -2955,6 +2966,9 @@ var SocketService = /*#__PURE__*/ function() {
2955
2966
  this.disconnectCallbacks = [];
2956
2967
  this.authToken = null;
2957
2968
  this.isDisconnected = true;
2969
+ /// the data-socket keeps one subscription per collection per socket, so a second condition set
2970
+ /// for a collection never reaches it and would silently receive the first one's documents
2971
+ this.activeConditions = /* @__PURE__ */ new Map();
2958
2972
  this.handleDisconnect = function(source, reason) {
2959
2973
  var _this_socket;
2960
2974
  if (_this.isDisconnected) {
@@ -3122,6 +3136,39 @@ var SocketService = /*#__PURE__*/ function() {
3122
3136
  }
3123
3137
  }
3124
3138
  },
3139
+ {
3140
+ key: "registerConditions",
3141
+ value: function registerConditions(collectionName) {
3142
+ var conditions = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
3143
+ var signature = JSON.stringify(conditions);
3144
+ var active = this.activeConditions.get(collectionName);
3145
+ if (!active) {
3146
+ this.activeConditions.set(collectionName, {
3147
+ signature: signature,
3148
+ conditions: conditions,
3149
+ count: 1
3150
+ });
3151
+ return;
3152
+ }
3153
+ active.count++;
3154
+ if (active.signature !== signature) {
3155
+ console.error('[socket] "'.concat(collectionName, '" is already subscribed with different conditions, and a collection supports one condition set at a time. The active set stays in effect, so this subscription receives its documents instead of its own. active: ').concat(active.signature, " requested: ").concat(signature));
3156
+ }
3157
+ }
3158
+ },
3159
+ {
3160
+ key: "releaseConditions",
3161
+ value: function releaseConditions(collectionName) {
3162
+ var active = this.activeConditions.get(collectionName);
3163
+ if (!active) {
3164
+ return;
3165
+ }
3166
+ active.count--;
3167
+ if (active.count <= 0) {
3168
+ this.activeConditions.delete(collectionName);
3169
+ }
3170
+ }
3171
+ },
3125
3172
  {
3126
3173
  key: "disconnectSocket",
3127
3174
  value: function disconnectSocket() {
@@ -3133,6 +3180,8 @@ var SocketService = /*#__PURE__*/ function() {
3133
3180
  },
3134
3181
  {
3135
3182
  /// subscribe to collections
3183
+ /// conditions are derived from OnSnapshotConfig.conditions, never passed in, so a caller cannot
3184
+ /// set them in a second place and have them silently overwritten
3136
3185
  key: "subscribeToCollections",
3137
3186
  value: function subscribeToCollections(config, options) {
3138
3187
  var _this = this;
@@ -3145,26 +3194,77 @@ var SocketService = /*#__PURE__*/ function() {
3145
3194
  });
3146
3195
  var eventHandlers = [];
3147
3196
  config.forEach(function(configuration) {
3148
- var collectionName = configuration.collectionName, onAdd = configuration.onAdd, onFirstTime = configuration.onFirstTime, onModify = configuration.onModify, onRemove = configuration.onRemove, extraParsers = configuration.extraParsers;
3197
+ var collectionName = configuration.collectionName, conditions = configuration.conditions;
3198
+ var parsers = [
3199
+ configuration
3200
+ ].concat(_to_consumable_array(configuration.extraParsers || []));
3201
+ var matchedIds = /* @__PURE__ */ new Set();
3149
3202
  var attach = function(eventName, handler) {
3150
- if (!handler) return;
3151
- _this.socket.off(eventName, handler);
3152
3203
  _this.socket.on(eventName, handler);
3153
3204
  eventHandlers.push({
3154
3205
  eventName: eventName,
3155
3206
  handler: handler
3156
3207
  });
3157
3208
  };
3158
- attach("initial:".concat(collectionName), onFirstTime);
3159
- attach("add:".concat(collectionName), onAdd);
3160
- attach("update:".concat(collectionName), onModify);
3161
- attach("delete:".concat(collectionName), onRemove);
3162
- extraParsers === null || extraParsers === void 0 ? void 0 : extraParsers.forEach(function(parsers) {
3163
- var extraOnAdd = parsers.onAdd, extraOnFirstTime = parsers.onFirstTime, extraOnModify = parsers.onModify, extraOnRemove = parsers.onRemove;
3164
- attach("initial:".concat(collectionName), extraOnFirstTime);
3165
- attach("add:".concat(collectionName), extraOnAdd);
3166
- attach("update:".concat(collectionName), extraOnModify);
3167
- attach("delete:".concat(collectionName), extraOnRemove);
3209
+ var toDocs = function(payload) {
3210
+ return Array.isArray(payload) ? payload : payload ? [
3211
+ payload
3212
+ ] : [];
3213
+ };
3214
+ var run = function(op, docs) {
3215
+ return parsers.forEach(function(parser) {
3216
+ var _parser_op;
3217
+ return (_parser_op = parser[op]) === null || _parser_op === void 0 ? void 0 : _parser_op.call(parser, docs, configuration);
3218
+ });
3219
+ };
3220
+ var runIfAny = function(op, docs) {
3221
+ if (docs.length) {
3222
+ run(op, docs);
3223
+ }
3224
+ };
3225
+ attach("initial:".concat(collectionName), function(payload) {
3226
+ var docs = toDocs(payload).filter(function(doc2) {
3227
+ return checkConditions(doc2, conditions);
3228
+ });
3229
+ matchedIds.clear();
3230
+ docs.forEach(function(doc2) {
3231
+ return matchedIds.add(doc2.id);
3232
+ });
3233
+ run("onFirstTime", docs);
3234
+ });
3235
+ var handleUpsert = function(payload, defaultOp) {
3236
+ var added = [];
3237
+ var modified = [];
3238
+ var removed = [];
3239
+ toDocs(payload).forEach(function(doc2) {
3240
+ if (!(conditions === null || conditions === void 0 ? void 0 : conditions.length)) {
3241
+ (defaultOp === "onAdd" ? added : modified).push(doc2);
3242
+ return;
3243
+ }
3244
+ var wasMatching = matchedIds.has(doc2.id);
3245
+ if (checkConditions(doc2, conditions)) {
3246
+ matchedIds.add(doc2.id);
3247
+ (wasMatching ? modified : added).push(doc2);
3248
+ } else if (wasMatching) {
3249
+ matchedIds.delete(doc2.id);
3250
+ removed.push(doc2);
3251
+ }
3252
+ });
3253
+ runIfAny("onAdd", added);
3254
+ runIfAny("onModify", modified);
3255
+ runIfAny("onRemove", removed);
3256
+ };
3257
+ attach("add:".concat(collectionName), function(payload) {
3258
+ return handleUpsert(payload, "onAdd");
3259
+ });
3260
+ attach("update:".concat(collectionName), function(payload) {
3261
+ return handleUpsert(payload, "onModify");
3262
+ });
3263
+ attach("delete:".concat(collectionName), function(payload) {
3264
+ var docs = toDocs(payload).filter(function(doc2) {
3265
+ return !(conditions === null || conditions === void 0 ? void 0 : conditions.length) || matchedIds.delete(doc2.id);
3266
+ });
3267
+ runIfAny("onRemove", docs);
3168
3268
  });
3169
3269
  });
3170
3270
  var acknowledge = function(callback) {
@@ -3174,12 +3274,28 @@ var SocketService = /*#__PURE__*/ function() {
3174
3274
  console.error("Failed to subscribe to ".concat(config.join(", "), ": ").concat(callback.message));
3175
3275
  }
3176
3276
  };
3177
- if (options) {
3178
- s.emit("subscribe_options", options);
3277
+ config.forEach(function(c) {
3278
+ return _this.registerConditions(c.collectionName, c.conditions);
3279
+ });
3280
+ var conditionsByCollection = config.reduce(function(acc, c) {
3281
+ var active = _this.activeConditions.get(c.collectionName);
3282
+ if (active === null || active === void 0 ? void 0 : active.conditions.length) {
3283
+ acc[c.collectionName] = active.conditions;
3284
+ }
3285
+ return acc;
3286
+ }, {});
3287
+ var subscribeOptions = Object.keys(conditionsByCollection).length ? _object_spread_props(_object_spread({}, options), {
3288
+ conditions: conditionsByCollection
3289
+ }) : options;
3290
+ if (subscribeOptions) {
3291
+ s.emit("subscribe_options", subscribeOptions);
3179
3292
  }
3180
3293
  s.emit("subscribe_collections", collectionsNames, acknowledge);
3181
3294
  return function() {
3182
3295
  console.log("Cleaning up subscriptions for: ".concat(collectionsNames.join(", ")));
3296
+ collectionsNames.forEach(function(name) {
3297
+ return _this.releaseConditions(name);
3298
+ });
3183
3299
  s.emit("unsubscribe_collections", collectionsNames);
3184
3300
  eventHandlers.forEach(function(eh) {
3185
3301
  s.off(eh.eventName, eh.handler);
@@ -3299,6 +3415,7 @@ var subtract = function(a, b) {
3299
3415
  carsRegex: carsRegex,
3300
3416
  chargeDomain: chargeDomain,
3301
3417
  chartsRegex: chartsRegex,
3418
+ checkConditions: checkConditions,
3302
3419
  checkUserPermissions: checkUserPermissions,
3303
3420
  cleanNxSites: cleanNxSites,
3304
3421
  cn: cn,